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.

Mark order fulfilled using GraphQL api

Solved

Mark order fulfilled using GraphQL api

mtc_dev
Shopify Partner
6 2 7

I am looking to mark order Fulfilled using GraphQL api. 

This is the relevant API documentation I believe: 
https://shopify.dev/api/admin-rest/2021-10/resources/fulfillment#top
But this doesn't explain the theory behind fulfilments.

Can anyone share what steps ar involved in marking an order Fulfilled using GraphQL admin API, please? 

Looking to mark the whole order as fulfilled at first, then on to partial fulfillements. 

Thanks

Accepted Solution (1)

mtc_dev
Shopify Partner
6 2 7

This is an accepted solution.

Answering my own question as usual.

Assuming the order is to be shipped from a single location (which should cover 99% cases), your order will have a single FulfillmentOrder which you need to get the id of

 

{
order(id:"gid://shopify/Order/123456") {
    fulfillmentOrders (first:1) {
      edges {
        node {
          id
        }
      }
    }
  }
}

 

To mark whole order as Fulfilled, use the FulfillmentOrder id to mark the order Fulfilled:

 

sprintf('
            mutation {
                fulfillmentCreateV2(
                    fulfillment: {
                        lineItemsByFulfillmentOrder:{
                            fulfillmentOrderId:"%s"
                        }
                        notifyCustomer:true
                        trackingInfo: {
                            number: "xxx"
                            url: ""
                            company: ""
                        }
                    }
                ) {
                    fulfillment {
                        id
                    }
                }
            }
        ',
            $fulfillment_order_id
        );

To mark individual lines, you'll need to use individual LineItem ids. 

The documentation: 

https://shopify.dev/api/admin-graphql/2021-10/mutations/fulfillmentcreatev2

 

View solution in original post

Replies 4 (4)

mtc_dev
Shopify Partner
6 2 7

This is an accepted solution.

Answering my own question as usual.

Assuming the order is to be shipped from a single location (which should cover 99% cases), your order will have a single FulfillmentOrder which you need to get the id of

 

{
order(id:"gid://shopify/Order/123456") {
    fulfillmentOrders (first:1) {
      edges {
        node {
          id
        }
      }
    }
  }
}

 

To mark whole order as Fulfilled, use the FulfillmentOrder id to mark the order Fulfilled:

 

sprintf('
            mutation {
                fulfillmentCreateV2(
                    fulfillment: {
                        lineItemsByFulfillmentOrder:{
                            fulfillmentOrderId:"%s"
                        }
                        notifyCustomer:true
                        trackingInfo: {
                            number: "xxx"
                            url: ""
                            company: ""
                        }
                    }
                ) {
                    fulfillment {
                        id
                    }
                }
            }
        ',
            $fulfillment_order_id
        );

To mark individual lines, you'll need to use individual LineItem ids. 

The documentation: 

https://shopify.dev/api/admin-graphql/2021-10/mutations/fulfillmentcreatev2

 

TonyToms
Tourist
11 0 1

Hey Mtc_dev

 

Thank you so much. I need to ask something regarding your query. How do i specify the lines which i need to fulfil?

Here order-> fulfillmentOrders has lineItems but the ID is the actual 'order line Item ID' and not the 'fulfillment Order LineItem ID'. 

Hope you would understand my concern.

ShopifyDevSup
Shopify Staff
1453 238 518

Hi TonyToms,

 

In order to fulfill specific line items when creating a Fulfillment for an existing Fulfillment Order, you would want to use the ID from the fulfillmentOrder.lineItems connector. These line item ID's are different from the actual Order line items, and they are actually considered a FulfillmentOrderLineItem object.

If you have the Order that you want to get the specific Fulfillment Order Line Items for, you can do so with the following query:
 

{
   order(id: "gid://shopify/Order/12345678910"){
       fulfillmentOrders(first: 10){
           edges{
               node{
                   lineItems(first: 50){
                       edges{
                           node{
                               id
                           }
                       }
                   }
               }
           }
       }
   }

Here's some additional Shopify.dev documentation you can reference as well:

 

I hope this helps, and I hope you have a great day 🙂

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

vicvans20
Shopify Partner
14 1 9

Adding to the answer, I had to add the merchant_managed_fulfillment_orders and 

third_party_fulfillment_orders scopes to the app to be able to make it work, without these the fulfillmentOrders query would return me an empty list.