FROM CACHE - en_header

Fulfillment API returning 404

Solved
tsornin
Tourist
6 0 5

I'm trying to post to the Fulfillment (REST) API to fulfill line items on an order. I'm following the instructions from https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillment#create-2020-0..., and POSTing this:

"fulfillment" : {
      "tracking_number" : "",
      "line_items" : [
         {
            "id" : 5073200218215
         }
      ],
      "location_id" : 319520779
   }

to the url https://username:password@shopid.myshopify.com/admin/api/2020-04/orders/2259886243943/fulfillments.json

(with my shop's specific details)

However I'm getting a 404 back from the API, which is really unhelpful.

I've tried it with tracking_number: null, and also with no tracking number at all, but it's always the same: 404.

What now?

I have confirmed that it's the correct location id, order id and line_item id's. The line item is a product whose "requires_shipping" is false. Does that affect this?

 

Accepted Solution (1)

Accepted Solutions
vix
Shopify Staff
Shopify Staff
539 103 116

This is an accepted solution.

Hey @tsornin 

Thanks for the information. With any 404 you would be seeing a "not found" error - which to me means one of your IDs is incorrect. Can you confirm that the Order ID, Line Item ID and the Location ID (that corresponds to this line item specifically) are infact the correct ones? 

Let me know

View solution in original post

Replies 22 (22)
tsornin
Tourist
6 0 5

More info: 'x-request-id': [ 'eb28f5fb-fb97-407a-9bfa-b0c7e004d1f2' ]

 

Greg_Kujawa
Shopify Partner
1023 84 268

If that's the entirety of your JSON request body, aren't you missing the enclosing braces around the entire thing? Like this...

 

{
"fulfillment": {
  "location_id": 203128,
  "tracking_number": "123456789",
  "tracking_numbers": ["123456789"],
  "service": "manual",
  "tracking_url": "https://shipping.xyz/track.php?num=123456789",
  "tracking_urls": ["https://shipping.xyz/track.php?num=123456789"],
  "tracking_company": "Jack Black's Pack, Stack and Track",  
  "receipt": {},
  "line_items": [{"id": 4204529844276, "quantity": 1, "variant_id": null, "fulfillment_service":"manual" }],
  "notify_customer": false
  }
}
vix
Shopify Staff
Shopify Staff
539 103 116

This is an accepted solution.

Hey @tsornin 

Thanks for the information. With any 404 you would be seeing a "not found" error - which to me means one of your IDs is incorrect. Can you confirm that the Order ID, Line Item ID and the Location ID (that corresponds to this line item specifically) are infact the correct ones? 

Let me know

tsornin
Tourist
6 0 5

Solved it - it was in fact using the wrong order ID. I had set a variable earlier in the code for the order ID and was not updating it correctly. (sigh!) 

Thanks!

 

Ahsan3
New Member
22 0 0

Hi, I am trying to send the fulfillment acceptance for a fulfillment order using the fulfillment acceptance API https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillmentrequest#create...  

POST /admin/api/2020-04/fulfillment_orders/1046000825/fulfillment_request/accept.json

But it gives me 404 

{"errors":"Not Found"}

I have made sure 100 times that I am using the correct fulfillment order id and also made sure that this product is assigned to my fulfillment service app. 

Below is my POST request code, can someone please help me to figure out what am I missing here or what is wrong here:

$fulfillment_request = [
"fulfillment_request" => [
"message" => "We will start processing your fulfillment on the next business day.",
]
];

$SHOP_URL = 'ss-activewear-new.myshopify.com';
$SHOPIFY_API = "https://$API_KEY =>$PASSWORD@$SHOP_URL//admin/api/2021-01/fulfillment_orders/3639838146743/fulfillment_request/accept.json";

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $SHOPIFY_API);
$headers = array(
"Authorization: Basic ".base64_encode("$API_KEY:$PASSWORD"),
"Content-Type: application/json",
"charset: utf-8"
);

curl_setopt($curl, CURLOPT_HTTPHEADER,$headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($fulfillment_request));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

echo "\n\n";
$response = curl_exec ($curl);
curl_close ($curl);

For Shopify Staff: 
My x-request-id

x-request-id: d7760696-25f6-4b3a-a176-28e0628e5fea

My Shop URL: ss-activewear-new.myshopify.com

 

Greg_Kujawa
Shopify Partner
1023 84 268

@Ahsan3 wrote:

$SHOP_URL = 'ss-activewear-new.myshopify.com';
$SHOPIFY_API = "https://$API_KEY =>$PASSWORD@$SHOP_URL//admin/api/2021-01/fulfillment_orders/3639838146743/fulfillment_request/accept.json";

 


Check the $SHOPIFY_API variable declaration. As there appears to be two forward slashes after $SHOP_URL. Should just be one forward slash, right?

Ahsan3
New Member
22 0 0

That double slash worked perfectly fine for all other APIs like POST product API and Inventory level API. So this is not the issue I guess.  

Can you confirm the payload of the acceptance that I am using? Does it require any other parameter like specifying location Id? or anything else

Please Help!

Greg_Kujawa
Shopify Partner
1023 84 268

Don't you have to create a fulfillment order first, and then reference that fulfillment order ID in what you are trying to request?

 

https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillment#create-2021-0...

 

Ahsan3
New Member
22 0 0

When I sent the fulfillment request manually from the store to my app, didn't it create a fulfillment order already? because my app receives it as a fulfillment request notification on my callback URL. So technically an order has already been created and now I have to either accept it or reject it. Or am I missing anything here? Do I still need to create another fulfillment order? 

As per my understanding here is the life cycle of a fulfillment order.

1- The custom app receives the fulfillment request from Shopify.

2- The custom app reads the request and either accepts it or rejects it.

3- If accepted, then we will later send the tracking information as 3rd step.

4- Once the tracking number is posted we will send the fulfillment complete request.

Please let me know if I am missing any process here or is there something wrong with my acceptance request code?

Greg_Kujawa
Shopify Partner
1023 84 268
Makes sense in terms of the workflow. So when you are hitting the fulfillment accept endpoint, you are referencing the fulfillment order ID not the order ID, correct? These are two different values and you need to include the fulfillment order ID in the URL. This value should’ve been sent out in the original request you receive.
Ahsan3
New Member
22 0 0

You got it correct, I am using the fulfillment order Id that I received in the original request. This is the exact fulfillment order id that shows in the store URL as well. So once again here is my latest acceptance request. What parameter or process am I missing. I have been struggling with it for the last 3 days. Can't send acceptance, can't send rejection:

x-request-id: c8c0efab-dc49-4143-8e4d-24b6a06466c4

$fulfillment_request = [
"fulfillment_request" => [
"message" => "We will start processing your fulfillment on the next business day.",
]
];

$SHOPIFY_API = "https://$API_KEY =>$PASSWORD@$SHOP_URL//admin/api/2021-01/fulfillment_orders/3639838146743/fulfillment_request/accept.json";

 

Greg_Kujawa
Shopify Partner
1023 84 268

What happens when you hit this endpoint with a GET request?

/admin/api/2021-01/orders/{order_id}/fulfillments/{fulfillment_id}.json

If you substitute the order ID with a known existing order that is associated with fulfillment, and substitute the fulfillment ID with what you have seen come across that's valid. Do you get the fulfillment in the response?  

Ahsan3
New Member
22 0 0

Just followed your steps for the GET request and it's giving me 

{"fulfillment":null}

 What should be the next step?
I really appreciate your help.

Greg_Kujawa
Shopify Partner
1023 84 268

Hence your 404 error you've been getting. The fulfillment order ID doesn't exist.

Here is an overview that walks you through the steps --> https://shopify.dev/tutorials/manage-fulfillments-with-fulfillment-and-fulfillmentorder-resources. That's a good place to start. There are a lot of steps, and one thing I know is that if you plan on using the API for requesting, accepting, and rejecting fulfillments then the fulfillment service that's registered needs to be registered through the API.

For example, I have a test shop and had an order that was already flagged for manual custom fulfillment. When I tried to hit that in the fulfillment request endpoint the call was rejected with a HTTP 422 status "The fulfillment order's assigned fulfillment service must be of api type."  

Ahsan3
New Member
22 0 0

I had created a fulfillment service through the API and received a successful response. Below was my request code:

$fulfillment = array (
'fulfillment_service' => array (
'name' => 'SS Active Wear',
'handle' => 'ssactivewear',
'callback_url' => 'https://f22a5f120d58.ngrok.io/shopify_test/inventory_check.php',
'inventory_management' => true,
'tracking_support' => true,
'requires_shipping_method' => true,
'format' => 'json',
),
);

 

This was my response:

{
"fulfillment_service": {
"id": 57105186999,
"name": "SS Active Wear",
"email": null,
"service_name": "SS Active Wear",
"handle": "ss-active-wear",
"fulfillment_orders_opt_in": false,
"include_pending_stock": false,
"provider_id": null,
"location_id": 60534456503,
"callback_url": "https://f22a5f120d58.ngrok.io/shopify_test/inventory_check.php",
"tracking_support": true,
"inventory_management": true
}
}

I just notice that "fulfillment_orders_opt_in": false.  Do you think that this is the root cause of the acceptance failures? If so how can I fix it?

Greg_Kujawa
Shopify Partner
1023 84 268
You would presumably need to remove the existing fulfillment service you registered and register it again with the opt in flag set to true. Details here

https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillmentservice

Please throughly read the other reference guide I linked to earlier. It goes over every single step that needs to be followed. All the answers are there if you follow it!
Ahsan3
New Member
22 0 0

Thanks Greg for your help, as instructed here's what I have done now:

  1. I registered a new fulfillment service this time with "fulfillment_orders_opt_in": true and received the confirmation in the response as well.
  2. Assigned a product to my new fulfillment service.
  3. Placed the order and sent the fulfillment request to my app.
  4. Tried sending the acceptance this time but it resulted in 
    422 
    {"errors":{"name":["has already been taken"]}}

  5. I further went down to check the GET fulfillment as guided above by you and that also resulted in the same error 422 {"errors":{"name":["has already been taken"]}}

Greg_Kujawa
Shopify Partner
1023 84 268

I'm wondering if the new fulfillment service you registered has the exact same name as the previous one. Perhaps try deleting the previous one if you haven't already (https://shopify.dev/docs/admin-api/rest/reference/shipping-and-fulfillment/fulfillmentservice#destro...). Also, perhaps try registering a fulfillment service with a unique name. See https://community.shopify.com/c/Shopify-APIs-SDKs/POST-admin-fulfillment-services-json-fails-with-42... for a similar scenario...

Ahsan3
New Member
22 0 0

Hi Greg, This is what I have done:

1. Removed my old Fulfillment
2. Registered a new fulfilment with "fulfillment_orders_opt_in": true,
3. Created a new product with a new service location id
4. Verified the variation inventory managed by in shopify Admin
it shows the name of my new service
5. Created the order and shopify admin shows my fulfillment name on that order
6. I then sent the fulfillment from shopify admin however didn't receive the request notification on my call back URL. Whereas test notification through test webhook fulfillment/create is always received on the same callback URL
7. I then tried this for my order GET /admin/api/2021-01/orders/{order_id}/fulfillments/{fulfillment_id}.json
and that says {"fulfillment":null}


Any help? why the actual order notification is not being received; whereas the test notification is always received.