How to get all orders data from flipkart seller api

566 views Asked by At

Can someone help me to get all order data from Flipkart seller API?

Currently, I am using this but it fetches the Orderitems list of different orders. Is there any API to fetch directly all orders?

$url  = "https://api.flipkart.net/sellers/v2/orders/search";
    $curl = curl_init(); 
    $json = '{
              "sort": {
    "field": "dispatchByDate",
    "order": "desc"
  }
            }';
    curl_setopt($curl, CURLOPT_URL,$url);

    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'Content-Type:application/json',
    'Authorization:Bearer '.$tokan['access_token'],
    ''
    ));
    $result = curl_exec($curl);
    $ee = curl_getinfo($curl);
    echo "<pre>";
    //print_r($ee);
    curl_close($curl);
  
    $result = json_decode($result,true);
     print_r($result);

Please revert if anybody has any solution.

2

There are 2 answers

0
YESHWANTH LN On

you can try easyecom service to fetch the orders data from the flipkart

0
shobhnath On
> You can try this code to get flipkart All Orders details using seller APIs


  public function getFlipkartSO($nextPageUrl = null) {
                $token=$this->getrefreshtoken();
                $access_token=json_decode($token)->access_token;  
                $currentdate = date("Y-m-d\TH:i:s");
                $yesterday = date("Y-m-d\TH:i:s", strtotime('-1 day', strtotime($currentdate)));
                
                $dataArray = array("filter" => array("orderDate" => array("fromDate" => $yesterday, "toDate" => $currentdate)),"pagination" => array("pageSize" => 20));
            
             
                $nextPageUrl = $nextPageUrl;
                $url = 'https://api.flipkart.net/sellers/v2/orders/search';
                if(isset($nextPageUrl)){
                    $curl = curl_init();
                    curl_setopt_array($curl, array(
                    CURLOPT_URL => $nextPageUrl,
                    CURLOPT_RETURNTRANSFER => true,
                    CURLOPT_ENCODING => '',
                    CURLOPT_MAXREDIRS => 10,
                    CURLOPT_TIMEOUT => 0,
                    CURLOPT_FOLLOWLOCATION => true,
                    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                    CURLOPT_CUSTOMREQUEST => 'GET',
                    CURLOPT_HTTPHEADER => array(
                    'Authorization: Bearer xxxxx-xxxxxx-xxxxxx-xxxxx611'
                    ),
                ));
                $response = curl_exec($curl);
                }else{    
                    $curl = curl_init();
                
                    curl_setopt_array($curl, array(
                        CURLOPT_URL => $url,
                        CURLOPT_RETURNTRANSFER => true,
                        CURLOPT_ENCODING => '',
                        CURLOPT_MAXREDIRS => 10,
                        CURLOPT_TIMEOUT => 0,
                        CURLOPT_FOLLOWLOCATION => true,
                        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                        CURLOPT_CUSTOMREQUEST => 'POST',
                        CURLOPT_POSTFIELDS => json_encode($dataArray),
                        CURLOPT_HTTPHEADER => array(
                            'Content-Type: application/json',
                            'Authorization: Bearer xxxxx-xxxxxx-xxxxxx-xxxxx611'
                        ),
                    ));
                    $response = curl_exec($curl);
                }
            
                $salseoder = json_decode($response);
                if (isset($salseoder->hasMore)) {      
                    if(isset($salseoder->nextPageUrl)){
                        $nextPageUrl = 'https://api.flipkart.net/sellers/v2'.$salseoder->nextPageUrl;
                    }else{
                        $nextPageUrl= null;
                    }         
                   
                    $address_details=array();
                    $finalarray=array();
                    $Price_Components=[];
                    foreach ($salseoder->orderItems as $item) {
                        if(isset($item->orderId)){
                            $OrderId =  $item->orderId;
                        }
                                     
                            if(isset($item->orderItemId)){
                                $OrderItemId =  $item->orderItemId;
                            }
                            if(isset($item->hsn)){
                                $hsn =  $item->hsn;
                            }
                            if(isset($item->status)){
                                $Status =  $item->status;
                            }
                            if(isset($item->hold)){
                                $Hold =  $item->hold;
                            }
                            if(isset($item->orderDate)){
                                $OrderDate=date('d-M-Y H:i:s', strtotime($item->orderDate));
                            }
                            if(isset($item->dispatchAfterDate)){
                                $DispatchAfterDate=date('d-M-Y H:i:s', strtotime($item->dispatchAfterDate));
                            }
                            if(isset($item->dispatchByDate)){
                                $DispatchByDate=date('d-M-Y H:i:s', strtotime($item->dispatchByDate));
                            }
                            if(isset($item->deliverByDate)){
                                $DeliverByDate=date('d-M-Y H:i:s', strtotime($item->deliverByDate));
                            }
                            if(isset($item->updatedAt)){
                                $UpdatedAt=date('d-M-Y H:i:s', strtotime($item->updatedAt));
                            }
                            if(isset($item->sla)){
                                $sla=$item->sla;
                            }
                            if(isset($item->quantity)){
                                $Quantity=$item->quantity;
                            }
                            if(isset($item->title)){
                                $Title=$item->title;
                            }
                            if(isset($item->listingId)){
                                $ListingId=$item->listingId;
                            }
                            if(isset($item->fsn)){
                                $FSN=$item->fsn;
                            }
                            if(isset($item->sku)){
                                $SKU=$item->sku;
                            }
                            if(isset($item->shippingPincode)){
                                $ShippingPincode=$item->shippingPincode;
                            }
                            if(isset($item->dispatchServiceTier)){
                                $Dispatch_Service_Tier=$item->dispatchServiceTier;
                            }
                            if(isset($item->priceComponents->sellingPrice)){
                                $Selling_Price=$item->priceComponents->sellingPrice;
                            }
                            if(isset($item->priceComponents->customerPrice)){
                                $Customer_Price=$item->priceComponents->customerPrice;
                            }
                            if(isset($item->priceComponents->shippingCharge)){
                                $Shipping_Charge=$item->priceComponents->shippingCharge;
                            }
                            if(isset($item->priceComponents->totalPrice)){
                                $Total_Price=$item->priceComponents->totalPrice;
                            }
                            if(isset($item->priceComponents->flipkartDiscount)){
                                $Flipkart_Discount=$item->priceComponents->flipkartDiscount;
                            }
                            if(isset($item->priceComponents->subsidy)){
                                $Subsidy=$item->priceComponents->subsidy;
                            }
                            if(isset($item->paymentType)){
                                $Payment_Type=$item->paymentType;
                            }
                            if(isset($item->shipmentId)){
                                $ShipmentId=$item->shipmentId;
                            }
                            if(isset($item->shipmentType)){
                                $Shipment_Type=$item->shipmentType;
                            }
                            if(isset($item->serviceProfile)){
                                $Service_Profile=$item->serviceProfile;
                            }
                            $Price_Components =array(array("Selling_Price"=>$Selling_Price,"Customer_Price"=>$Customer_Price,"Shipping_Charge"=>$Shipping_Charge,"Total_Price"=>$Total_Price,"Flipkart_Discount"=>$Flipkart_Discount,"Subsidy"=>$Subsidy));
                            $orders_details = array("OrderItemId"=>$OrderItemId,"OrderId"=>$OrderId,"hsn"=>$hsn,"Status"=>$Status,"Hold"=>$Hold,"OrderDate"=>$OrderDate,"DispatchAfterDate"=>$DispatchAfterDate,"DispatchByDate"=>$DispatchByDate,"DeliverByDate"=>$DeliverByDate,"UpdatedAt"=>$UpdatedAt,"Quantity"=>$Quantity,"Title"=>$Title,"ListingId"=>$ListingId,"FSN"=>$FSN,"SKU"=>$SKU,"ShippingPincode"=>$ShippingPincode,"Dispatch_Service_Tier"=>$Dispatch_Service_Tier,"Payment_Type"=>$Payment_Type,"ShipmentId"=>$ShipmentId,"Shipment_Type"=>$Shipment_Type,"Service_Profile"=>$Service_Profile,"Price_Components"=>$Price_Components);
                        
                       <!-- insert item in data base orders_details -->
    
                       <!-- insert qyery -->
                   
                    }
                    $this->getFlipkartSO($nextPageUrl);
                } else {
                    echo 'No more data available.';
                }    
                curl_close($curl);
           
        }