Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Shopify Order Fulfilment using API

Solved

Shopify Order Fulfilment using API

ZMahmood
Shopify Partner
2 1 0
$url = 'https://' . $STORE_URL . '/admin/api//2023-07/fulfillments.json'; 
$ch = curl_init();

$abc = '{
"fulfillment": {

"line_items_by_fulfillment_order": [
{
"fulfillment_order_id": 5404222980327

}
],
"notify_customer" => false,
"tracking_info": {
"number": "MS1562678",
"url": "https://www.my-shipping-company.com?tracking_number=MS1562678"
},
"location_id": 71680327911
}
}';



curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_POSTFIELDS, $abc);

$headers = array();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "X-Shopify-Access-Token: {$accessToken}"));

$results = curl_exec($ch);
//$results=json_encode($results);
$results=json_decode($results,true);

$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //can check status code, requst successfully processed if return 200
var_dump($http_code);
var_dump($results);

if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}

curl_close($ch);

this is my code I'm getting int(400) NULL error or sometimes 404 not found error while trying to fulfill the order. 

Accepted Solution (1)
ZMahmood
Shopify Partner
2 1 0

This is an accepted solution.

the main issue was with my JSON data which I was trying to pass

here below is the right format which works for me.

 

$data = [
'fulfillment' => [
'line_items_by_fulfillment_order' => [
[
'fulfillment_order_id' => 6488664834279
]
],
'notify_customer' => false,
'location_id' => 69471600871
]
];

View solution in original post

Replies 2 (2)

Liam
Community Manager
3108 344 902

Hi ZMahmood,

 

In the code above I noticed you have two slashes in the endpoint path (it should be `/admin/api/2023-07/fulfillments.json`) also there could be an issue with how you're using the PHP array syntax (`=>`) inside a JSON string. It should be `:` instead of `=>` for `notify_customer`. Can you retry with these changes?

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

ZMahmood
Shopify Partner
2 1 0

This is an accepted solution.

the main issue was with my JSON data which I was trying to pass

here below is the right format which works for me.

 

$data = [
'fulfillment' => [
'line_items_by_fulfillment_order' => [
[
'fulfillment_order_id' => 6488664834279
]
],
'notify_customer' => false,
'location_id' => 69471600871
]
];