Solved

Mark order fulfilled using GraphQL api

mtc_dev
Shopify Partner
5 2 6

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
5 2 6

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 2 (2)

mtc_dev
Shopify Partner
5 2 6

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

 

vicvans20
Shopify Partner
13 1 7

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.