shopifyshopify-appfulfillment

How to create or update shopify fulfillments


I need to update/create shopify order fulfillment but getting some errors like { "errors": "Not Found" } I have checked creds everything is right key token store URL everything but getting this error again and again. is there someone who can help with this?

Code is copied and implemented from this guide Fulfillments orders

header("Access-Control-Allow-Origin: *");
set_time_limit(0);
error_reporting(E_ALL);
ini_set("display_errors", 1);
define("API_KEY", '8f6ba81c2bXXXXXXXXXXXXXXXXX');
define("ACCESS_TOKEN", 'XXXXXXXee88e7dXX3604d8XXXXXXXXXXXXXX');
define("SHOP", 'myshopistore-XXXXX');
define("API_VERSION", '2022-10');

$ch = curl_init();
echo $url = 'https://'.API_KEY.':'.ACCESS_TOKEN.'@'.SHOP.'.myshopify.com/admin/api/2022-10/fulfillments.json';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
"{"fulfillment":{"message":"The package was shipped this morning.",
"notify_customer":false,"tracking_info":{"number":1562678,"url":"https://www.my-shipping-company.com","company":"my-shipping-company"},
"line_items_by_fulfillment_order":[{"fulfillment_order_id":125846255999999}]}}");

$headers = array();
$headers[] = 'X-Shopify-Access-Token: XXXXXX27eeXX8e7d9e3604dXXXXXXXXXXXXXX';
$headers[] = 'Content-Type: application/json';
print_r($headers);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

echo $result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

Solution

  • Here is the answer of the question this can help someone in the same case, actually I was using wrong fulfillment_order_id and location_number Before creating a fulfillment from above code we need to get the fulfillment_order_id from this API request https://'.API_KEY.':'.ACCESS_TOKEN.'@'.SHOP.'.myshopify.com'/admin/api/2022-10/orders/XXXXXXXXXXXXXX/fulfillment_orders.json this request will return the fulfillment_order_id inside the line_items node then use this id to create your fulfillment.

    below API will return locations in case you need them https://'.API_KEY.':'.ACCESS_TOKEN.'@'.SHOP.'.myshopify.com'/admin/api/2022-10/locations.json