Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Issue with Fulfillment RESTful API

Solved

Issue with Fulfillment RESTful API

DanTrayton93
Tourist
6 0 1

Hi,

I'm trying to fulfil an order in Shopify using a RESTful API.

The one I have been using is 

POST: https://{StoreName}.myshopify.com/admin/api/2022-07/orders/{fulfillmentID}/fulfillments.json

BODY:

{
    "fulfillment": {
    "line_items_by_fulfillment_order": [
                {
                    "fulfillment_order_id": {ID}
                }
            ],
      "notify_customer" : false, 
      "location_id": {locationID}
    }
}

The response I'm getting is a 404 - with no content.

I've seen some examples online where they use the tracking Info which I can't find.

I've also assigned read and write abilities for the following (including some for other tasks)

 

read_products, write_inventory, read_inventory, read_orders, write_orders, write_third_party_fulfillment_orders, read_third_party_fulfillment_orders, write_fulfillments, read_fulfillments, write_merchant_managed_fulfillment_orders, read_merchant_managed_fulfillment_orders, write_assigned_fulfillment_orders, read_assigned_fulfillment_orders, write_custom_fulfillment_services, read_custom_fulfillment_services, write_fulfillment_constraint_rules, read_fulfillment_constraint_rules 

 

If I remove the location ID from the payload the response suggests that the location ID is mandatory so the call must be working.

Is there something missing from my payload or should I be using a different call?

 

Many Thanks,

 

Dan

Accepted Solution (1)

Milkbottlelough
Shopify Partner
27 5 38

This is an accepted solution.

I think you are missing a step.  You need to GET request the following:

 

https://{StoreName}.myshopify.com/admin/api/2022-10/orders/{order_id}/fulfillment_orders.json

 

This will return a list of fulfillment_order_ids for the shopify order {order_id}.

 

You can then iterate over these IDs and POST the body you described above to: 

 

https://{StoreName}.myshopify.com/admin/api/2022-07/orders/{fulfillmentID}/fulfillments.json

 

In the body the fulfillment_order_id is the fulfillment order ID you retrieved in the first GET request above.

 

The 404 you are getting is because the fulfillment_order_id is not being found by Shopify.

 

Here's what my payload that is sent to the Fulfillments endpoint looks like:

 

[

        "line_items_by_fulfillment_order" => [
            [
                "fulfillment_order_id" => $fulfillmentOrderId
            ],
        ],
        "tracking_info" => [
            "number" => $tracking_number,
            "url" => $tracking_url,
            "company" => $tracking_company,
        ],
        "notify_customer" => true,
        "origin_address" => null,
        "message" => "Items are shipped."
    
]

 

View solution in original post

Replies 9 (9)

Milkbottlelough
Shopify Partner
27 5 38

This is an accepted solution.

I think you are missing a step.  You need to GET request the following:

 

https://{StoreName}.myshopify.com/admin/api/2022-10/orders/{order_id}/fulfillment_orders.json

 

This will return a list of fulfillment_order_ids for the shopify order {order_id}.

 

You can then iterate over these IDs and POST the body you described above to: 

 

https://{StoreName}.myshopify.com/admin/api/2022-07/orders/{fulfillmentID}/fulfillments.json

 

In the body the fulfillment_order_id is the fulfillment order ID you retrieved in the first GET request above.

 

The 404 you are getting is because the fulfillment_order_id is not being found by Shopify.

 

Here's what my payload that is sent to the Fulfillments endpoint looks like:

 

[

        "line_items_by_fulfillment_order" => [
            [
                "fulfillment_order_id" => $fulfillmentOrderId
            ],
        ],
        "tracking_info" => [
            "number" => $tracking_number,
            "url" => $tracking_url,
            "company" => $tracking_company,
        ],
        "notify_customer" => true,
        "origin_address" => null,
        "message" => "Items are shipped."
    
]

 

RobertM
Excursionist
20 0 4

I'm having the same issue of not being able to send the fulfillments, and I tried this solution, and it didn't work.  The documentation says you should use endpoint

 /admin/api/2023-07/orders/fulfillments.json.  i.e don't put the fulfillment id in the url.  When I do that it returns no errors but doesn't do it.  So I added the fulfillment id per your suggestion and it now says. "Not Found".  I then changed the 2023 to be 2022 and it still returns "Not Found".  I verified the Fulfillment ID again and it is correct.  Any ideas?

DanTrayton93
Tourist
6 0 1

Hi @RobertM ,

 

I've managed to get the call working. A couple of things to check are: 

  • ensure you have the necessary read and write capabilities on the shop.
  • and that the fulfilment order id being used is the correct one (this is something I got wrong)

I use postman client to test the API calls - the first call was as @Milkbottlelough  suggested https://{ShopName}.myshopify.com/admin/api/2023-07/orders/{OrderId}/fulfillment_orders.json

 

from the response you will want to use the id 

 

DanTrayton93_0-1691567609892.png

 

from this if you do a POST call to https://{shopname}.myshopify.com/admin/api/2023-07/fulfillments.json 

with your shopify access token and content-type set to application/json and a body similar to this:

 

{
    "fulfillment": {
            "location_id""{locationId}",
            "notify_customer" : false,       
            "line_items_by_fulfillment_order": [
                    {
                        "fulfillment_order_id""{FullmentOrderID}"
                        
                    }
              ]
        }
}
It should hopefully work.
I didn't need to put in tracking information - I think this is an optional parameter.
Let me know if you get any luck with this approach.
 
Kind Regards,
 
Dan

 

 

 

RobertM
Excursionist
20 0 4

Thank you Dan, Your reply was the answer, and I got it to work.  The URL in the accepted solution does not work.  It was

https://{StoreName}.myshopify.com/admin/api/2022-07/orders/{fulfillmentID}/fulfillments.json.

In your solution, the URL was 

https://{StoreName}.myshopify.com/admin/api/2022-07/fulfillments.json

i.e. the /orders/{fulfillmentid} was removed and that does work.  I had the correct GET part, but not the POST.  Thank you for clarifying how to do it.   I'm going to try to add tracking information now.

  Robert.

Milkbottlelough
Shopify Partner
27 5 38

You are absolutely correct, typo on my part in the second URL - apologies.

 

I tried to edit my answer but I can't as it's the accepted solution.  For anyone in the future who wanders on here the corrected urls in my solution are:

 

GET

https://{StoreName}.myshopify.com/admin/api/2022-10/orders/{order_id}/fulfillment_orders.json

 

POST

https://{StoreName}.myshopify.com/admin/api/2022-07/fulfillments.json

RobertM
Excursionist
20 0 4

Thanks for correcting the accepted solution.  I used the 2023-07 api, and it worked too.

DanTrayton93
Tourist
6 0 1

Hi @Milkbottlelough ,

 

Thank you for getting back to me. I've now managed to get this working. You were right I think I was using the wrong fulfilment order id in the call. 

Everything looks to be working OK now.

Thank you for your help.

 

Kind Regards,

 

Dan

Milkbottlelough
Shopify Partner
27 5 38

Delighted to hear that!

 

Things have certainly become that bit more complicated on the API side of things when it comes to fulfillments but I guess that was inevitable as partial fulfilment functionality must have been a real head-scratcher for the Shopify devs to roll out without breaking lots of things already in the wild!

 

Best of luck with the rest of your project!

 

 

IGIT
Shopify Partner
44 0 10

How did you mange this? As soon as we send in the initial fulfilment Shopify closes the fulfilment and rebuffs any further event or fulfilment messages with a "fulfilment closed" message and doesn't alter the state nor update the customer. This means that once the fulfilment has been sent with tracking info and carrier, we cannot inform the customer of out for delivery or delivered