Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

Re: REST Fulfillment Creation HELP Please

Solved

REST Fulfillment Creation HELP Please

colleenc
Shopify Partner
91 9 21

Issue: Post tracking info to Shopify via API. Previously used admin/api/2020-04/orders/{Order: Id}/fulfillments.json which has been deprecated. Trying to post via admin/api/2021-10/fulfillments.json or /admin/api/2022-07/fulfillments.json without success.

 

I have been pulling my hair out for a few days now. Reading everything here as well as Shopify Documentation and appear to be no closer to getting this solved. I seem to have this at a point where it is being recognized in some way, but I am now getting this fun error. I have checked my data and ensured that there are no "quantity" : 0 in the data. I am at a loss. Open to suggestions!

 

@Shopify  it would have been really cool if you let us know what method to use to pull in tracking data after you deprecated admin/api/2020-04/orders/{Order: Id}/fulfillments.json because based on my reading there are a lot of us struggling to find a workable replacement.

 

@Ralph-HA did you manage to find a fix?

 

UPDATE: I just realized that my issue is I tried to use the "order id" as the fulfillment id. Need to look at the code again. This is the code I used to create the json code. When you look at the sample, the "order id" line is missing.

 

{
	"fulfillment": {
        "notify_customer": true,
		"location_id": 18014371875,
		"tracking_number": {Fulfillments: Tracking Number},
		"tracking_url": "{Tracking URL}",
		"tracking_company": "{Carrier}",
        "line_items_by_fulfillment_order" : [
              {
               "order_id": {Order: Id},
               "fulfillment_order_line_items": [{Line Items Fulfillment Array}]
              }
            ]
	}
}

 

Current error message: 

   "Fulfillment payloads fulfillment order must be greater than 0"

 

API Endpoint: admin/api/2021-10/fulfillments.json

 

Method: POST

 

    "fulfillment": {
      "line_items_by_fulfillment_order": [
        {
          "fulfillment_order_line_items": [
            {
              "id": 1239874,
              "quantity": 1
            },
            {
              "id": 0983498723,
              "quantity": 1
            },
          "order_id": 123456789
        }
      ],
      "location_id": 98765432,
      "notify_customer": true,
      "tracking_company": "Canada Post",
      "tracking_number": 0123456789,
      "tracking_url": "https://www.canadapost-postescanada.ca/track-reperage/"
    }
  }

For reference, I have read through the following & tried many, many incremental fixes.

https://community.shopify.com/c/fulfillment-api-deprecation/frequently-asked-questions/td-p/1564746

https://community.shopify.com/c/shopify-apis-and-sdks/quot-create-a-fulfillment-quot-rest-api-endpoi...

https://shopify.dev/api/admin-rest/2021-10/resources/fulfillment#post-fulfillments

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

 

Accepted Solution (1)
colleenc
Shopify Partner
91 9 21

This is an accepted solution.

After several attempts, this finally works. The previously posted solutions work if you only need to fulfill the entire order. This process takes into account back-ordered items as well. So this code will only fulfill line items that shipped and not automatically fulfill the entire order.

 

Sorry for any confusion, I thought it was working when the orders were fulfilled and then I realized the code was fulfilling the entire order including out-of-stock items. All fixed now.

 

Again, thank you everyone for your input and patience!

 

Step One:

 

GET

https://xxx.myshopify.com/admin/api/2022-10/orders/{Order : Id}/fulfillment_orders.json

 

Step Two: Parse the return for the following details

 

In the return, look for the column with the array in it and parse out the array. There are several columns of data needed from this array. Some of them are also outside of the array, but some are not. The array is called "api.fulfillment_orders line_items". The columns you need, depending on your requirements, are:

 

api.fulfillment_orders id = fulfillment_orders_id

api.fulfillment_orders assigned_location_id = location_id

api.fulfillment_orders order_id = order_id

api.fulfillment_orders line_items variant_id = variant_id

api.fulfillment_orders line_items id = line item identifier needed for your ship quantity array

 

Admittedly, there may have been something with the way I pulled in this data that caused the array to occur. So you may not have to parse out the data, but in case you do, those are the details. After that, put together an array with your shipping info (only if you need it).

 

 

{"id": {api.fulfillment_orders line_items id}, "quantity": {Quantity Shipped}}

 

 

Step Three: POST to API (or use your method of choice)

 

API: https://xxx.myshopify.com/admin/api/2022-10/fulfillments.json

 

JSON:

 

{
	"fulfillment": {
		"line_items_by_fulfillment_order": [{
    		"fulfillment_order_id": {api.fulfillment_orders id},
            "fulfillment_order_line_items": [{Line Items Fulfillment Array}]
  }],
      "tracking_info": {
          "company": "{Fulfillments: Tracking Company}", 
          "number": {Fulfillments: Tracking Number}, 
          "url": "{Tracking URL}"
      },
		"notify_customer": false,
		"location_id": {api.fulfillment_orders assigned_location_id}
	}
}

 

 

 

View solution in original post

Replies 15 (15)

Ralph-HA
Shopify Partner
108 7 46

Hi @colleenc ,

   Not sure if you've solved this, as I see you mentioned using the fulfillment order id.  I'll give some guidance if you haven't solved this or if someone else runs into this.

  1. The Fulfillment Order now drives fulfillment.  You have to first retrieve the Fulfillment Orders for your Order and then provided the fulfillment order id and the line item id and quantity you want to fulfill. 
  2. Your JSON object structure is not correct.  Looking at the samples in the Fulfillment Order documentation, you can see what the structure should look like.  I've restructured your JSON doc below to try and help.
  3. I noticed you are providing the tracking details at the top level of the JSON doc.  If you look at the Shopify documentation you'll see you need to provide the tracking info in the tracking_info object.  Also, note you can only provide a single tracking number per fulfillment.
  4. You can't provide the location of the fulfillment. Shopify will fulfill the orders based on the location of the Fulfillment Order.  If you want to change the location, you'll have to use the move action on the Fulfillment Order API.

To help give some guidance, here is a restructuring of the request body.

 

"fulfillment": {
      "line_items_by_fulfillment_order": [
        {
            "fulfillment_order_id": 123456789,
"fulfillment_order_line_items": [
{
"id": 1239874,
"quantity": 1
},
{
"id": 0983498723,
"quantity": 1
}
] } ],
"tracking_info": {
"company": "Canada Post",
"number": 0123456789,
"url": "https://www.canadapost-postescanada.ca/track-reperage/"
}, "notify_customer": true }

I hope this moves you in the right direction!

Co-Founder / Developer at Highview Apps
Our Shopify Apps: EZ Exporter | EZ Inventory | EZ Importer | EZ Notify | EZ Fulfill
colleenc
Shopify Partner
91 9 21

Thank you @Ralph-HA! This has been a great help. It looks like I have sorted out how to grab the fulfillment order id, which had been the biggest stopper for me. Thanks for the JSON help. I am going to test everything this morning. Things are finally looking up! I will let you know where I am at and what my final solution is.

colleenc
Shopify Partner
91 9 21

Hi @Ralph-HA I have managed to get the API to give me the fulfillment order id. 

 

I think I have my JSON cleaned up properly, and it is going through, it is not failing. However, it is not adding the tracking info to the orders and it is not showing the items as shipped. It's pretty frustrating especially when the old API was so simple - and it was working.

 

Here is what I am doing:

 

GET

https://xxx.myshopify.com/admin/api/2022-10/orders/{Order: Id}/fulfillment_orders.json

 

Which is sending me:

api.id, api.shop_id, api.order_id, etc.

api.id appears to be the fulfillment_order_id as api.order_id is the order_id.

 

API: https://xxx.myshopify.com/admin/api/2022-10/fulfillments.json

JSON:

{
	"fulfillment": {
		"line_items_by_fulfillment_order": [{
			"fulfillment_order_id": {api.id},
			"fulfillment_order_line_items": [{Line Items Fulfillment Array}]
        }],
          "tracking_info": {
			"company": "{Fulfillments: Tracking Company}",
			"number": {Fulfillments: Tracking Number},
			"url": "{Tracking URL}"
		},
		"notify_customer": false,
		"location_id": {api.assigned_location_id}
	}
}

 

I have check and refreshed the app permissions, so that does not seem to be the issue. I am quite frustrated by this.

colleenc
Shopify Partner
91 9 21

Hello my https://fragrance-lodge.myshopify.com/admin/api/2020-04/orders/{Order: Id}/fulfillments.json is not working/has been deprecated armageddon peeps!

 

With a lot of help from @Ralph-HA @IGIT @SCHLUE1  and others, it is solved.

 

THIS PROCESS IS WORKING!

 

Pay attention to the details, as a tiny detail can mess you up for days...ask me how I know...

 

Step One: GET Fulfillment_Orders API

 

This step creates the fulfillment and returns the fulfillment_order_id that you need.

 

GET

https://xxx.myshopify.com/admin/api/2022-10/orders/{Order : Id}/fulfillment_orders.json

 

Note: Make sure you use fulfillment_orders and not fulfillments.

 

This will send you: api.id, api.shop_id, api.order_id, etc., which you need for the next step. Use the api.id for the next step as it is the fulfillment_order_id, do not use api.order_id  as it is the order_id.

 

Step two: POST to API (or use your method of choice)

 

API: https://xxx.myshopify.com/admin/api/2022-10/fulfillments.json

 

JSON:

{
	"fulfillment": {
		"line_items_by_fulfillment_order": [{
    		"fulfillment_order_id": {api.id},
            "line_items": [{Line Items Fulfillment Array}]
  }],
      "tracking_info": {
          "company": "{Fulfillments: Tracking Company}", 
          "number": {Fulfillments: Tracking Number}, 
          "url": "{Tracking URL}"
      },
		"notify_customer": false,
		"location_id": {api.assigned_location_id}
	}

 

And that's it! You are done.

SCHLUE1
Tourist
6 1 3

Great to see that this working now. Thank you for sharing your findings ColleenC!!

 

colleenc
Shopify Partner
91 9 21

I made an error in the code above, the correct code should include fulfillment_order_line_items and not line_items. I am going to repost my corrected solution. The correct code is:

 

{
	"fulfillment": {
		"line_items_by_fulfillment_order": [{
    		"fulfillment_order_id": {api.id},
            "fulfillment_order_line_items": [{Line Items Fulfillment Array}]
  }],
      "tracking_info": {
          "company": "{Fulfillments: Tracking Company}", 
          "number": {Fulfillments: Tracking Number}, 
          "url": "{Tracking URL}"
      },
		"notify_customer": false,
		"location_id": {api.assigned_location_id}
	}
colleenc
Shopify Partner
91 9 21

CORRECTION: My earlier post had an error in the code. It showed line_items instead of fulfillment_order_line_items. The code in this post is correct.

 

Hello my https://XXX.myshopify.com/admin/api/2020-04/orders/{Order : Id}/fulfillments.json is not working/has been deprecated armageddon peeps!

 

With a lot of help from @Ralph-HA @IGIT @SCHLUE1  and others, it is solved.

 

THIS PROCESS IS WORKING!

 

Pay attention to the details, as a tiny detail can mess you up for days...ask me how I know...

 

Step One: GET Fulfillment_Orders API

 

This step creates the fulfillment and returns the fulfillment_order_id that you need.

 

GET

https://xxx.myshopify.com/admin/api/2022-10/orders/{Order : Id}/fulfillment_orders.json

 

Note: Make sure you use fulfillment_orders and not fulfillments.

 

This will send you: api.id, api.shop_id, api.order_id, etc., which you need for the next step. Use the api.id for the next step as it is the fulfillment_order_id, do not use api.order_id  as it is the order_id.

 

Step two: POST to API (or use your method of choice)

 

API: https://xxx.myshopify.com/admin/api/2022-10/fulfillments.json

 

JSON:

 

 

 

{
	"fulfillment": {
		"line_items_by_fulfillment_order": [{
    		"fulfillment_order_id": {api.id},
            "fulfillment_order_line_items": [{Line Items Fulfillment Array}]
  }],
      "tracking_info": {
          "company": "{Fulfillments: Tracking Company}", 
          "number": {Fulfillments: Tracking Number}, 
          "url": "{Tracking URL}"
      },
		"notify_customer": false,
		"location_id": {api.assigned_location_id}
	}

 

 

 

colleenc
Shopify Partner
91 9 21

This is an accepted solution.

After several attempts, this finally works. The previously posted solutions work if you only need to fulfill the entire order. This process takes into account back-ordered items as well. So this code will only fulfill line items that shipped and not automatically fulfill the entire order.

 

Sorry for any confusion, I thought it was working when the orders were fulfilled and then I realized the code was fulfilling the entire order including out-of-stock items. All fixed now.

 

Again, thank you everyone for your input and patience!

 

Step One:

 

GET

https://xxx.myshopify.com/admin/api/2022-10/orders/{Order : Id}/fulfillment_orders.json

 

Step Two: Parse the return for the following details

 

In the return, look for the column with the array in it and parse out the array. There are several columns of data needed from this array. Some of them are also outside of the array, but some are not. The array is called "api.fulfillment_orders line_items". The columns you need, depending on your requirements, are:

 

api.fulfillment_orders id = fulfillment_orders_id

api.fulfillment_orders assigned_location_id = location_id

api.fulfillment_orders order_id = order_id

api.fulfillment_orders line_items variant_id = variant_id

api.fulfillment_orders line_items id = line item identifier needed for your ship quantity array

 

Admittedly, there may have been something with the way I pulled in this data that caused the array to occur. So you may not have to parse out the data, but in case you do, those are the details. After that, put together an array with your shipping info (only if you need it).

 

 

{"id": {api.fulfillment_orders line_items id}, "quantity": {Quantity Shipped}}

 

 

Step Three: POST to API (or use your method of choice)

 

API: https://xxx.myshopify.com/admin/api/2022-10/fulfillments.json

 

JSON:

 

{
	"fulfillment": {
		"line_items_by_fulfillment_order": [{
    		"fulfillment_order_id": {api.fulfillment_orders id},
            "fulfillment_order_line_items": [{Line Items Fulfillment Array}]
  }],
      "tracking_info": {
          "company": "{Fulfillments: Tracking Company}", 
          "number": {Fulfillments: Tracking Number}, 
          "url": "{Tracking URL}"
      },
		"notify_customer": false,
		"location_id": {api.fulfillment_orders assigned_location_id}
	}
}

 

 

 

hexonsoft
Shopify Partner
7 0 3

Thank you so much for saving my day.
Its a big loss Shopify depreciated previous fulfilment api.

colleenc
Shopify Partner
91 9 21

You are welcome. It took me around a week and 116 runs to finally figure the whole thing out. The array inside an array was the key to it all in the end. I had everything right but was using the wrong "level" of column references. I didn't want anyone else to go through what I went through. 

 

Really happy this worked for you @hexonsoft!

submfg
Shopify Partner
5 0 0

For the life of me I can not get this to work in Postman.  I have tried everything even the most basic.  When I GET the fullfillment_orders.json I get a blank object "fulfillment_orders": []. And when Posting to fulfilments.json I get a 404. 

 

I am able to fulfill the order with orders/{orderID}/fulfillments.json but it fulfills the whole order instead of single line items.  Man this bugs. 

 

Where am I going wrong?

https://xxx.myshopify.com/admin/api/2022-10/fulfillments.json

{
    "fulfillment": {
        "line_items_by_fulfillment_order": [
            {
                "fulfillment_order_id": {order id},
                "fulfillment_order_line_items": [
                    {
                        "id": {line_items id},
                        "quantity": 1
                    }
                ]
            }
        ],
        "tracking_info": {
            "company": "usps",
            "number": 9470111298370372642929,
            "url": "www.usps.com"
        },
        "notify_customer": false,
        "location_id": {locationId}
    }
}

 

ShopifyDevSup
Shopify Staff
1453 238 524

Hi @submfg👋


Would you kindly check these requirements and review these steps to highlight exactly at which step you're running into errors? 

 

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

submfg
Shopify Partner
5 0 0
Hey Thanks for getting back. I have been traveling and now am having a large issue with this.

I am having issue with theStep 2: Receive fulfillment requests and cancellations. I have created a fulfillment service and can retrieve the order information but the fulfillment is still blank. fulfillment:[]

Maybe I am missing the concept here, or just really frustrated. Any help would be appreciated.

Thanks,
Jeremy DeBoer | General Manager
Kapil2022
Shopify Partner
11 0 4

 

Kapil2022_1-1674129215154.png

getting error while using

https://xxx.myshopify.com/admin/api/2022-10/orders/{Order : Id}/fulfillment_orders.json

 

what should I do.

dbelmonte
Shopify Partner
25 0 3

hello, I am following these steps but I always get "errors": "Not Found". 

I am using version 2022-10