Fulfillment API problems--400

Fulfillment API problems--400

tzvishmuel1
New Member
4 0 0

I have waded through dozens (or hundreds) of similar cases here.  Some are 'solved' and some are not, but none of the solutions work for me.

 

We have a very simple setup, with just one in-house warehouse.  We receive the orders, ship them out, then we want to update tracking data and close the order.

 

Once I have the shipping/tracking data, first we retrieve the fulfillment ids using the endpoint https://{store name}.myshopify.com/admin/api/2023-04/orders/{order id}/fulfillment_orders.json

This works fine. Since we're going to fulfill the entire order at once I take the first ID supplied, before the line_items.

 

I then build the outgoing data with the following php code:

$post = array(
   'fulfillment' => array(
      'line_items_by_fulfillment_order' => array(
         "fulfillment_order_id" => {fill_id}
       ),
      "tracking_info" => array(
         "company" => $carrier,
         "number" => $tracking
      ),
      'notify_customer' => false,
      'location_id' => {location id from the fulfillment orders array}
   )
);

 

$post=json_encode($post);

 

This is sent out to the endpoint https://{store name}.myshopify.com/admin/api/2023-04/fulfillments.json and I get a 400 error.  (Note that if I try to do it the old way, with orders/{order id}, as suggested in some of the posts, I get a 404 instead of 400.

 

My app has all the permissions it needs, and when I fetch the fulfillmlent IDs it always gives create_fulfillment as a support action, so I'm at a loss.  Any help is appreciated.

Replies 4 (4)

SomeUsernameHe
Shopify Partner
495 54 99

I would try adding some debugging and see what the logs show: 

$post = array(
    'fulfillment' => array(
        'line_items_by_fulfillment_order' => array(
            "fulfillment_order_id" => {fill_id}
        ),
        "tracking_info" => array(
            "company" => $carrier,
            "number" => $tracking
        ),
        'notify_customer' => false,
        'location_id' => {location id from the fulfillment orders array}
    )
);

$post = json_encode($post);

// Initialize cURL
$ch = curl_init();

// Set cURL options
curl_setopt($ch, CURLOPT_URL, "https://{store name}.myshopify.com/admin/api/2023-04/fulfillments.json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    // Include your access token here
));

// Execute cURL request
$response = curl_exec($ch);

// Check for errors and log them
if(curl_errno($ch)) {
    error_log('cURL error: ' . curl_error($ch));
}

// Log response
error_log('API response: ' . $response);

// Close cURL session
curl_close($ch);
Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
tzvishmuel1
New Member
4 0 0

I have done debugging but removed those statements for this script.  It shows everything proceeding normally up until the 400 error, which has no details.

SomeUsernameHe
Shopify Partner
495 54 99
'location_id' => {location id from the fulfillment orders array}

 seems to be a placeholder rather than actual code. In your PHP script, you should replace {location id from the fulfillment orders array} with the actual location ID obtained from your fulfillment orders. This should be a specific numeric or string identifier, like $locationId, which you would have defined earlier in your script based on the data retrieved from Shopify's API.

Ensure that you're assigning the correct location ID as retrieved from the fulfillment orders to the location_id field in your $postData array.

Have I helped? Consider putting coffee in my mouth!
Buy Me a Coffee
tzvishmuel1
New Member
4 0 0

Sorry, I put it in this way here as a placeholder to clarify..in the actual script it's $loc_id, which is the location I retrieved in the fulfillment ids call.