-1

I have been using the following code in Shopify to handle order fulfillment. It was functioning correctly until last week, but suddenly it stopped working. Despite attempting various solutions, the issue remains unresolved as the response I receive is always blank.

Here's the modified code:

$data = array(
    "fulfillment" => array(
        "tracking_number" => $tracking_id,
        "location_id" => "56530665662",
        "tracking_url" => "https://yalidine.com/suivre-un-colis/?tracking=".$tracking_id,
        "tracking_company" => "Yalidine"
    )
);

$data_string = json_encode($data);

$ch_shopify = curl_init('https://'.$shopify_api_key.':'.$shopify_api_password.'@'.$shop_name.'.myshopify.com/admin/orders/'.$order_id.'/fulfillments.json');
curl_setopt($ch_shopify, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($data_string))
);

curl_setopt($ch_shopify, CURLOPT_POST, 1);
curl_setopt($ch_shopify, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch_shopify, CURLOPT_RETURNTRANSFER, true);
$response_shopify = curl_exec($ch_shopify);

$resp_array = json_decode(trim($response_shopify), TRUE);
echo("*************************");
print_r($response_shopify);
$fulfillment = strval($resp_array['fulfillment']['status']);

if ($resp_array['errors']['base'][0] == "Line items are already fulfilled" || $fulfillment == "success") {
    $_SESSION['response'] = $order_number;
    header("Location: index.php");
    exit();
} else {
    $_SESSION['error'] = $resp_array;
    echo "resp_array: ".$resp_array;
}

Please note that the value of resp_array is consistently blank.

I have attempted various adjustments, such as adding the API version, but the issue persists.

When testing the code on Postman, I received the following error: "{ "errors": { "fulfillment": "Required parameter missing or invalid" } }".

Aniskonig
  • 31
  • 8
  • You asked this already, not even a full 24 hours ago: https://stackoverflow.com/q/76704726/1427878 – CBroe Jul 18 '23 at 12:16
  • Because of people like you rating down, I dindn't got any answer – Aniskonig Jul 18 '23 at 12:18
  • I doubt that has anything much to do with the mere two downvotes your question got. And if you did not even get it to work properly via Postman - then you should go and check the API documentation for whether anything significant has changed recently. – CBroe Jul 18 '23 at 12:24
  • 1
    Please use a single Stack Overflow account. – KIKO Software Jul 18 '23 at 12:34
  • I think you need to check and explore the API for better code options, here is the API documentation on how to add tracking information to a [fullfilment in REST API](https://shopify.dev/docs/api/admin-rest/2023-07/resources/fulfillment#post-fulfillments-fulfillment-id-update-tracking) – Onkar Jul 18 '23 at 12:58
  • If `resp_array` is "blank" then I'd inspect `response_shopify` next – Chris Haas Jul 18 '23 at 13:22
  • I know nothing about Shopify, but if I'm reading things correctly, there's a fairly recent thread out there stating that the `/admin/orders` API is being deprecated: https://community.shopify.com/c/customers-discounts-and-orders/need-help-regarding-deprected-orders-api-to-fulfillment-orders/m-p/2099867 – Chris Haas Jul 18 '23 at 13:31
  • even with that I updated it max but I still face the same problem – Aniskonig Jul 20 '23 at 11:28

1 Answers1

0

API Version

First of all, you should specify the API version that you are using in the URL, otherwise you could have undefined behaviour. You are probably using a deprecated version, so you should probably decide on updating your code and using the current latest version (as of 08/2023): 2023-07.

For example:

$ch_shopify = curl_init('https://'.$shopify_api_key.':'.$shopify_api_password.'@'.$shop_name.'.myshopify.com/admin/api/2023-07/.........');

How to set Tracking Info

Secondly, the way Fulfillments work in the API has changed, you first need to get the FullfilmentOrder from the Order and then using that you can set a new Fullfilment containing the tracking number.

Get FulfillmentOrder from Order

So lets get the FulfillmentOrder for a specific Order

GET /admin/api/2023-07/orders/{{ order_id }}/fulfillment_orders.json

see: https://shopify.dev/docs/api/admin-rest/2023-07/resources/fulfillmentorder#get-orders-order-id-fulfillment-orders

Set Fulfillment for FulfillmentOrder

Then using the ID of the FulfillmentOrder, we can POST a new Fulfillment, containing the tracking information.

POST /admin/api/2023-07/fulfillments.json

Your $data should look like this.

$data = array(
    "fulfillment" => array(
        "line_items_by_fulfillment_order" => array (
            0 => array(
                "fulfillment_order_id" => {{ fulfillment_order_id }}
            )
        ),
        "tracking_info" => array (
            "company" => "UPS",
            "number" => "789679679",
            "url" => "http://ups.com/XXXX"
        )
    )
);

see: https://shopify.dev/docs/api/admin-rest/2023-07/resources/fulfillment#post-fulfillments