Jump to content

 

thanasisloi7

Member Since 09 Nov 2011
Offline Last Active Dec 07 2021 09:00 PM
-----

Posts I've Made

In Topic: Php Api Shipments

14 April 2021 - 08:56 PM

Not familiar with whatever wrapper you're using so I don't know what it's actually returning in $get_order.  But if you get a specific order via the api by using  "orders/123" and then json_decode() the result, you should have a 'products' array that contains the products from the order.  You can then look a that to see how to reference the product_id.

 

Note that casting an array to a StdClass kind of defeats the purpose of doing a json_decode($get_order,true).  (and make sure you use true as the 2nd argument to json_decode.)  Instead you should assume that $obj is an array().  But if you want to use it as an object, you will most likely have to cast your $obj->status to a string.

i just do it like this..

$get_order = callAPI('GET', 'https://www.test.com/api/orders/'.$WO, json_encode($result, true));
$obj = json_decode($get_order);

foreach ($obj->products as $products) {
    $item_id = $products->{'item_id'};
    $amount = $products->{'amount'};
}


//and then i request a POST



$data_shipment =  array(
   "carrier" => "",
   "order_id" => $WO,
   "products" => array(
        $item_id =>  $amount,
    ),
   "shipping" => $M,
   "shipping_id" => $CSCOURIER,
   "user_id" => "0",
   "tracking_number" => $V
);

$update_shipment = callAPI('POST', 'https://www.test.com/api/shipments', json_encode($data_shipment));

Thank you for your help.


In Topic: Php Api Shipments

14 April 2021 - 07:06 PM

You might have to use a multi call approach.  I.e. GET's to retrieve the products in an order and the PUTS/POST to create the shipments.

I already make this to read the status of order

$get_order = callAPI('GET', 'https://www.test.com/api/orders/'.$WO, json_encode($result, true));

$obj = json_decode($get_order);
$details = $obj->details;
$currentstatus = $obj->status;

i don't know how to read the products id's and quantity and then how to POST