Create Tracking

Hi everyone,

I’m trying to add tracking information to a paid fulfillment order using the Shopify API. I send a POST request to the fulfillment orders endpoint with the following payload and code. However, I don’t get any useful error message or response indicating success or failure.

Here is the code I use:

php

KopierenBearbeiten

$data = [
    'fulfillment' => [
        'message' => 'The package was shipped this morning.',
        'notify_customer' => false,
        'tracking_info' => [
            'number' => '00340434467160030320',
            'company' => 'DHL'
        ],
        'line_items_by_fulfillment_order' => [[
            'fulfillment_order_id' => 11708472918365,
            'fulfillment_order_line_items' => [[
                'id' => 34823647822173,
                'quantity' => 1
            ]]
        ]]
    ]
];

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . '/fulfillments.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'X-Shopify-Access-Token: ' . $access_token,
    'Content-Type: application/json',
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$response = curl_exec($ch);

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

curl_close($ch);

$shopify_response = json_decode($response, true);
echo "<pre>";
print_r($shopify_response);
echo "</pre>";

I expect either a confirmation or an error message, but the response is either empty or unclear. Has anyone encountered this before or knows what might be missing?

Thanks in advance!


Would you like me to help you tweak the code or check for common pitfalls in this request?

I’d probably look at moving over to GraphQL first as REST is now deprecated.

1 Like

I have already tried it with GraphQL unfortunately without success

I’m starting to wonder if I’m using the right call I’ve already tried everything I could think of

// GraphQL-Mutation
$query = <<<GQL
mutation fulfillmentCreate($fulfillment: FulfillmentInput!, $message: String) {
fulfillmentCreate(fulfillment: $fulfillment, message: $message) {
fulfillment {
id
status
trackingInfo {
number
url
company
}
}
userErrors {
field
message
}
}
}
GQL;

// Variablen für die Mutation
$variables = [
‘fulfillment’ => [
‘trackingInfo’ => [
‘number’ => ‘00340434467160030320’,
‘url’ => ‘DHL Sendungsverfolgung - den Status Ihrer Pakete verfolgen | DHL’,
‘company’ => ‘DHL’,
],
‘notifyCustomer’ => true,
‘lineItemsByFulfillmentOrder’ => [
[
‘fulfillmentOrderId’ => ‘gid://shopify/Order/11708472918365’,
‘fulfillmentOrderLineItems’ => [
// Mindestens ein LineItem notwendig, sonst schlägt es fehl
[
‘id’ => ‘gid://shopify/LineItem/34823647822173’, // ← Anpassen
‘quantity’ => 1
]
]
]
]
],
‘message’ => ‘Deine Bestellung wurde versendet!’
];

// API-Anfrage vorbereiten
$payload = json_encode([
‘query’ => $query,
‘variables’ => $variables
]);

$ch = curl_init(“https://$shop/admin/api/2023-10/graphql.json”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
“Content-Type: application/json”,
“X-Shopify-Access-Token: $accessToken”
]);

// Anfrage ausführen
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

// Antwort anzeigen
$shopify_orders = json_decode($response, TRUE);
echo “

”;print_r($shopify_orders);echo “
”;

//Response
Array
(
[errors] => Array
(
[0] => Array
(
[message] => invalid id
[locations] => Array
(
[0] => Array
(
[line] => 3
[column] => 3
)

                    )

                [path] => Array
                    (
                        [0] => fulfillmentCreate
                    )

                [extensions] => Array
                    (
                        [code] => RESOURCE_NOT_FOUND
                    )

            )

    )

[data] => Array
    (
        [fulfillmentCreate] => 
    )

[extensions] => Array
    (
        [cost] => Array
            (
                [requestedQueryCost] => 11
                [actualQueryCost] => 1
                [throttleStatus] => Array
                    (
                        [maximumAvailable] => 2000
                        [currentlyAvailable] => 1999
                        [restoreRate] => 100
                    )

            )

    )

)

You’re not passing the right IDs.

fulfillmentOrderId should be like gid://shopify/FulfillmentOrder/7808748126545

And id for the line items should be like gid://shopify/FulfillmentOrderLineItem/17009801462097

when i change it to that i get the following error message i already tried that too i double and triple checked the ids it’s the orderids and the line ids am i missing a step in between?

Array
(
[data] => Array
(
[fulfillmentCreate] => Array
(
[fulfillment] =>
[userErrors] => Array
(
[0] => Array
(
[field] => Array
(
[0] => fulfillment
)

                                [message] => Fulfillment order does not exist.
                            )

                    )

            )

    )

[extensions] => Array
    (
        [cost] => Array
            (
                [requestedQueryCost] => 11
                [actualQueryCost] => 10
                [throttleStatus] => Array
                    (
                        [maximumAvailable] => 2000
                        [currentlyAvailable] => 1990
                        [restoreRate] => 100
                    )

            )

    )

)

Have you actually used the correct ID though? Not just changed it from Order to FulfillmentOrder? They will be completley different IDs.

I suggest looking into how fulfillments work.

thanks it worked now but it is very cumbersome because every order and every article has two different ids and you have to query them in two different ways makes no sense

thank you very much for your help