Create Fulfilment using Rest Admin API

Hi,

I’m trying to understand new policy for marking order as “fulfilled” and setting up tracking number, but I can’t

The article: https://shopify.dev/api/admin-rest/2022-07/resources/fulfillment says that there should be a “fulfillment_order_id” to pass but how to get one if my order doesn’t have it? The order fulfillment array is empty

How to generate an order fulfillment then?

This article: https://shopify.dev/api/admin-rest/2022-07/resources/fulfillmentorder doesn’t explain how to do this. Something is missing here

Looking forward to your reply

Best regards, Anton.

2 Likes

I’m having the same problem here, I had to revert to the lower API version just to use the fulfillment services. Even the support does not know what the fulfillment_order_id references. Any help from the devs would be great.

2 Likes

yes, you are right this is a workaround, but I hope that this will be resolved till this becomes not supported API version :slightly_smiling_face:

1 Like

@Shopify_77 Any help would be much appreciated. 2 months and 0 reply!
This is not funny at all when the API docs says “Fulfillment orders are created automatically when an order is created.” but by the fact all website’s I see do not have this information. So how we should fulfill the order then?

I found solution:

  1. You need to have app to cover all the fulfilment scopes

  2. now you are good to request FulfilmentOrder: https://shopify.dev/api/admin-rest/2022-10/resources/fulfillmentorder#get-orders-order-id-fulfillment-orders

  3. You need to get id and then also fulfilment line ids using order line ids, of course if you partly do it, otherwise - you can ignore this part

  4. now you are free to fulfill the order: https://shopify.dev/api/admin-rest/2022-10/resources/fulfillment#post-fulfillments

Hope that this helps!

2 Likes

To anyone struggling with this in Python, below is a small function I created to create fulfillments in the new 2023-01 version of the REST API:

# fulfill shopify orders
def fulfill_order(self, order_id, tracking_number):
    import requests

    # get fulfillment_order_id from order_id
    headers = {"Content-Type": "application/json"}
    url = (
        self.url_prefix + f"/api/2023-01/orders/{order_id}/fulfillment_orders.json"
    )
   
    fulfillment_order_id = requests.get(url).json()["fulfillment_orders"][-1]["id"]

    # create fulfillment
    payload = {
        "fulfillment": {
            "message": "",
            "notify_customer": False,
            "tracking_info": {
                "number": tracking_number,
                "url": f"https://www.fedex.com/fedextrack/?trknbr={tracking_number}",
                "company": "FedEx",
            },
            "line_items_by_fulfillment_order": [
                {
                    "fulfillment_order_id": fulfillment_order_id,
                    "fulfillment_order_line_items": [],
                }
            ],
        }
    }

    url = self.url_prefix + "/api/2023-01/fulfillments.json"
    r = requests.post(url, json=payload, headers=headers)

    if r.status_code == 201:
        print("success")
    else:
        print("- WARNING: Unable to fulfill order!")
        print(r.text)

For anyone else experiencing the same problem, I was getting no results when requesting the list of fulfillment_orders for a specific order until I gave the app the “read_merchant_managed_fulfillment_orders” permission.

1 Like

To anyone who experiences the same problem in the future, granting the “read_merchant_managed_fulfillment_orders” permission to your application will work.