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: Order Fulfillment not fulfilling

Solved

Order Fulfillment not fulfilling

MatrixZA
Shopify Partner
5 1 0

One of the functions of my app is to create a Shopify Order, depending on certain info it receives it will either create the order as fulfilled, partially fulfilled or not fulfilled, the creation of an order, and even when creating a new order as fulfilled works perfectly.

The problem comes in when I want to fulfil an existing order after it has already been created (but wasn't created as fulfilled, so either not or partially fulfilled).

The documentation itself is not very clear at all in regards to fulfilment of an existing order and the internet is a vast variety of different way of doing it, some with API endpoints that aren't even listed on the Shopify docs.

it seems order fulfilment has changed dramatically over the past 2 years, so its a lucky packet of info out on the internet.

I have also noticed there seems to be ways to fulfil separate items on an order, or the entire order as a whole, but like it said the docs are not very clear surround this.

I basically just want to fulfil the entire order (not individual items) and then add a tracking number to the order,
so basically selecting "Other" as the tracking company, and the number will be the Purchase order number, nothing fancy.

If someone can please point me in the right direction, or advise on the data I need to post to the API & also which API endpoint it would be greatly appreciated ❤️

If additional information is required please feel free to ask & I will supply it to the best of my ability.

Coding is my Zen
Accepted Solution (1)
MatrixZA
Shopify Partner
5 1 0

This is an accepted solution.

Ok never mind I came right...thank the gods and thank you @Liam 

I see I was missing that I had to wrap the array inside a 'fulfillment' array 😞 what a pain, and probs lack of sleep didnt ever help anyone.

For anyone who is having the same issue this is what the data needs to look like that you post.

 

[
    'fulfillment' => [
        'line_items_by_fulfillment_order' => [
            [
                'fulfillment_order_id' => 6300186411289
            ]
        ],
        'notify_customer' => false,
        'tracking_info' => [
            'number' => 'PO#92273476',
            'company' => 'Other',
        ],
        'location_id' => 80255713561
    ]
]

 

Coding is my Zen

View solution in original post

Replies 6 (6)

Liam
Community Manager
3108 344 889

Hi MatrixZA,

 

Would this Create a fulfillment with a tracking number of a Shopify unsupported tracking carrier, and therefore with a tracking url provided example be what you're looking for here?

 

// Session is built by the OAuth process

const fulfillment = new shopify.rest.Fulfillment({session: session});
fulfillment.line_items_by_fulfillment_order = [
  {
    "fulfillment_order_id": 1046000853
  }
];
fulfillment.tracking_info = {
  "number": "MS1562678",
  "url": "https://www.my-shipping-company.com?tracking_number=MS1562678"
};
await fulfillment.save({
  update: true,
});

This is written in node.js but you can see how it would be structured with curl, Ruby or PHP on our docs here. There's also other examples from the docs that you can modify to work with your preferred use case. 

 

Hope this helps!

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

MatrixZA
Shopify Partner
5 1 0

Hi @Liam, You deff put me on the right direction.

I am currently posting the following to this REST API endpoint: 

/admin/api/2023-07/fulfillments.json

 

 

[
    'line_items_by_fulfillment_order' => [
        [
            'fulfillment_order_id' => 6300186411289
        ]
    ],
    'notify_customer' => false,
    'tracking_info' => [
        'number' => 'PO#92273476',
        'company' => 'Other',
    ],
    'location_id' => 80255713561
]

 

 

 
But I am getting the following error returned from Shopify: Required parameter missing or invalid.

If you could advise where im going wrong or what param's im missing or have invalid it would be much appreciated.

I got a lot of insight from this post, but sadly still no luck 😞
https://community.shopify.com/c/fulfillment-and-inventory/how-to-fulfill-orders-using-rest-api/td-p/...

Coding is my Zen
MatrixZA
Shopify Partner
5 1 0

This is an accepted solution.

Ok never mind I came right...thank the gods and thank you @Liam 

I see I was missing that I had to wrap the array inside a 'fulfillment' array 😞 what a pain, and probs lack of sleep didnt ever help anyone.

For anyone who is having the same issue this is what the data needs to look like that you post.

 

[
    'fulfillment' => [
        'line_items_by_fulfillment_order' => [
            [
                'fulfillment_order_id' => 6300186411289
            ]
        ],
        'notify_customer' => false,
        'tracking_info' => [
            'number' => 'PO#92273476',
            'company' => 'Other',
        ],
        'location_id' => 80255713561
    ]
]

 

Coding is my Zen
Liam
Community Manager
3108 344 889

Great to here you figured this out MatrixZA! And thanks for coming back to post your solution 🙂 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me 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

imaiyuan
Visitor
1 0 0

May I ask for fulfillment_ Order_ Is the ID the ID of the order? If not, how can I obtain this ID

MatrixZA
Shopify Partner
5 1 0

Hi @imaiyuan,

To get the 'fulfillment_order_id' you need to do a GET request to the following endpoint.

 

 

/admin/api/2023-07/orders/{$orderId}/fulfillment_orders.json

 

 

Which will return an array that you will need to use to build the 'line_items_by_fulfillment_order' array.

Hope this makes sense

 

 

Coding is my Zen