How to fulfil a specific product on an order

How to fulfil a specific product on an order

brentonMN
Shopify Partner
10 0 5

I've got an App, can pull the order, check the products, and a webhook.

 

I cannot figure out the API call to modify a specific product as fulfilled in a specific order.

Replies 5 (5)

ShopifyDevSup
Shopify Staff
1453 238 498

Hey @brentonMN, thanks for getting in touch. I'm not certain which version of the Admin API you're using, but the functionality is fairly similar. I'll use REST for this example. Here are some quick steps:

1. Retrieve an order's Fulfillment Order ID and the fulfillment order line item ID for the inventory item you'd like to fulfill by making a GET request for a specific order's fulfillment order info (more details here).
2. Pass the fulfillment order ID and the line item ID through a POST request on the fulfillments endpoint. Here's an example of what this would look like using Node.js, for reference:


const fulfillment = new shopify.rest.Fulfillment({session: session});
fulfillment.message = "The package was shipped this morning.";
fulfillment.notify_customer = false;
fulfillment.tracking_info = {
 "number": 1562678,
 "url": "https://www.my-shipping-company.com",
 "company": "my-shipping-company"
};
fulfillment.line_items_by_fulfillment_order = [
 {
   "fulfillment_order_id": 1046000784,
   "fulfillment_order_line_items": [
     {
       "id": 1058737493,
       "quantity": 1
     }
   ]
 }
];
await fulfillment.save({
 update: true,
});

We have a pretty helpful guide here that goes over some of the requirements and scopes required to manage fulfillments/fulfillment orders as a fulfillment app, so I wanted to share that just in case it helps. 

Let us know if we can clarify anything on our end! 

 

Al | Shopify Developer Support

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

brentonMN
Shopify Partner
10 0 5

I did find the Dev document, but testing it, it doesn't seem to work. I tested it with CURL through terminal (attached is the Dev document example).

curl -d '{"fulfillment":{"message":"The package was shipped this morning.","notify_customer":false,"tracking_info":{"number":1562678,"url":"https://www.my-shipping-company.com","company":"my-shipping-company"},"line_items_by_fulfillment_order":[{"fulfillment_order_id":1046000784,"fulfillment_order_line_items":[{"id":1058737493,"quantity":1}]}]}}' \
-X POST "https://your-development-store.myshopify.com/admin/api/2023-01/fulfillments.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

 

brentonMN
Shopify Partner
10 0 5

This is my call:

var req = await unirest.post(`${process.env.BASE_URL}/admin/api/2023-01/fulfillments.json`)
    .headers({
        'X-Shopify-Access-Token': process.env.API_KEY
    })
    .send({
        "fulfillment": {
            "message":"Fulfilled Donation.",
            "line_items_by_fulfillment_order": [
                {
                    "fulfillment_order_id": item.fulfillment_order_id,
                    "fulfillment_order_line_items": [
                        {
                            "id": item.id,
                            "quantity": item.quantity
                        }
                    ]
                }
            ]
        }
    })


I've got the program to a point where it is now needing to push an update to the fulfillment order. However, it returns:

{ errors: { fulfillment: 'Required parameter missing or invalid' } }

 

Doesn't make sense as I've done as instructed via the dev docs here.

ShopifyDevSup
Shopify Staff
1453 238 498

Hi @brentonMN 

 

That doesn't show what the `item` is defined as in your call, but I suspect the issue is using the wrong value in one or more of your request's variables, like in this other thread.

 

It sounds like you are building an Order management app, and if that's the case I would also recommend checking out the workflow for managing fulfillments in that section of our guides. 

 

Hope that helps.

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

brentonMN
Shopify Partner
10 0 5

This is the 'item' example below:

{
  id: 12845771489414,
  shop_id: #########,
  fulfillment_order_id: 6088493203590,
  quantity: 1,
  line_item_id: 12683754569862,
  inventory_item_id: 42211229401222,
  fulfillable_quantity: 1,
  variant_id: 40114867044486
}