Applying local delivery or in-store pick up options to draft order

I am trying to use the newly stable draftOrderAvailableDeliveryOptions graphql api call.

Here is my query:

query GetAvailableDeliveryOptions(
    $input: DraftOrderAvailableDeliveryOptionsInput!
  ) {
    draftOrderAvailableDeliveryOptions(input: $input) {
      availableShippingRates {
        handle
        title
        code
      }
      availableLocalDeliveryRates {
        handle
        title
        code
        source
        price {
          amount
          currencyCode
        }
      }
      availableLocalPickupOptions {
        handle
        title
        code
        locationId
        source
      }
    }
  }

I am able to successfully retrieve local pickup options via this call. However, I am struggling to apply the local pickup rate to the draftorder via the draftOrderCreate mutation.

When I supply the handle and title to the shippingLine field, it doesn’t go through. When I include a price field, I get an error back “A destination address is required in order to continue.”

When applying a local pickup option through the admin ui in Shopify, the request looks like this:

...
"shippingLine":
{
    "price": "0",
    "title": "630 Shannonville Rd",
    "shippingRateHandle": "2e6d17352d193a561152fd91eac544c4",
    "code": "630 Shannonville Rd",
    "source": "shopify",
    "deliveryMethodType": "PICK_UP",
    "locationId": "gid://shopify/Location/73026928928"
}
...

I can’t find any further documentation surrounding how to apply this to draft orders via the graphql mutations. The structure of the shipping line input is just this:

Thanks in advance!

Hi @ozzyonfire

Can you post the full draftOrderCreate mutation you’re using that’s generating the “A destination address is required in order to continue.” error? You’re not adding any shippingAddress field, correct?

Also have you tried the same method to update an existing draft order, with draftOrderUpdate using the same shippingLine structure?

Hi Liam,

Thanks for the quick reply. Here is the example draftOrderCreate mutation. I’ve tried with or without the shipping address, get the same error back either way.

{
    "operationName": "createDraftOrder",
    "variables": {
        "input": {
            "email": "dennis@ecstasycrafts.com",
            "billingAddress": {
                "firstName": "John",
                "lastName": "Smith",
                "address1": "630 Shannonville Rd",
                "city": "Shannonville",
                "provinceCode": "ON",
                "zip": "K0K 3A0"
            },
            "tags": [
                "test"
            ],
            "note": "This is a note on the order",
            "useCustomerDefaultAddress": false,
            "taxExempt": false,
            "paymentTerms": {
                "paymentTermsTemplateId": "gid://shopify/PaymentTermsTemplate/1"
            },
            "customAttributes": [],
            "localizedFields": [],
            "visibleToCustomer": false,
            "purchasingEntity": {
                "customerId": "gid://shopify/Customer/8861268607264"
            },
            "lineItems": [
                {
                    "variantId": "gid://shopify/ProductVariant/49804869075232",
                    "sku": "A006",
                    "quantity": 1,
                    "customAttributes": [],
                    "title": "A006"
                }
            ],
            "shippingLine": {
                "shippingRateHandle": "2e6d17352d193a561152fd91eac544c4",
                "title": "630 Shannonville Rd",
                "priceWithCurrency": {
                    "amount": 0,
                    "currencyCode": "CAD"
                }
            }
        }
    },
    "query": "mutation createDraftOrder($input: DraftOrderInput!) {\n  draftOrderCreate(input: $input) {\n    draftOrder {\n      id\n      customer {\n        id\n        __typename\n      }\n      __typename\n    }\n    userErrors {\n      field\n      message\n      __typename\n    }\n    __typename\n  }\n}"
}

GraphQL Response:

{
    "draftOrder": null,
    "userErrors": [
        {
            "field": null,
            "message": "A destination address is required in order to continue.",
            "__typename": "UserError"
        }
    ],
    "__typename": "DraftOrderCreatePayload"
}

I also tried the alternative structure for a shipping line in a mutation however it gave me GraphQL Errors about unknown fields for “locationId” and “deliveryMethodType” etc…

Variable $input of type DraftOrderInput! was provided invalid value for shippingLine.code (Field is not defined on ShippingLineInput), shippingLine.source (Field is not defined on ShippingLineInput), shippingLine.deliveryMethodType (Field is not defined on ShippingLineInput), shippingLine.locationId (Field is not defined on ShippingLineInput)

Thanks for your help.

Hi again @ozzyonfire

If you’re seeing options being returned by draftOrderAvailableDeliveryOptions that are not usable in the draftOrderCreate mutation, this feels like it could be a bug on our side. Can you post the full response for the draftOrderAvailableDeliveryOptions query (replacing any sensitive info with demo data)?

Update on this: it’s a known limitation that currently draftOrderCreate doesn’t allow setting a local pickup option as the shipping line without needing a shipping address in the input. They are working on supporting this in the coming weeks.

Until then you’ll need to include a shipping address in the input as well for draftOrderCreate.

Hi Liam,

Thanks for the response.

Unfortunately, (as stated above) the draftOrderCreate method does not accept the shipping line with or without the shippingAddress field.

Here is my request to draftOrderAvailableDeliveryOptions:

{
    "operationName": "GetAvailableDeliveryOptions",
    "variables": {
        "input": {
            "lineItems": [
                {
                    "variantId": "gid://shopify/ProductVariant/49804869075232",
                    "sku": "A006",
                    "quantity": 1,
                    "customAttributes": [],
                    "title": "A006"
                }
            ],
            "purchasingEntity": {
                "customerId": "gid://shopify/Customer/8861268607264"
            },
            "shippingAddress": {
                "firstName": "John",
                "lastName": "Smith",
                "address1": "630 Shannonville Rd",
                "city": "Shannonville",
                "provinceCode": "ON",
                "zip": "K0K 3A0"
            }
        }
    },
    "query": "query GetAvailableDeliveryOptions($input: DraftOrderAvailableDeliveryOptionsInput!) {\n  draftOrderAvailableDeliveryOptions(input: $input) {\n    availableShippingRates {\n      handle\n      title\n      code\n      __typename\n    }\n    availableLocalDeliveryRates {\n      handle\n      title\n      code\n      source\n      price {\n        amount\n        currencyCode\n        __typename\n      }\n      __typename\n    }\n    availableLocalPickupOptions {\n      handle\n      title\n      code\n      locationId\n      source\n      __typename\n    }\n    __typename\n  }\n}"
}

And the response:

{
    "data": {
        "draftOrderAvailableDeliveryOptions": {
            "availableShippingRates": [],
            "availableLocalDeliveryRates": [],
            "availableLocalPickupOptions": [
                {
                    "handle": "2e6d17352d193a561152fd91eac544c4",
                    "title": "630 Shannonville Rd",
                    "code": "630 Shannonville Rd",
                    "locationId": "gid://shopify/Location/73026928928",
                    "source": "shopify",
                    "__typename": "PickupInStoreLocation"
                }
            ],
            "__typename": "DraftOrderAvailableDeliveryOptions"
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 4,
            "actualQueryCost": 4,
            "throttleStatus": {
                "maximumAvailable": 2000,
                "currentlyAvailable": 1996,
                "restoreRate": 100
            }
        }
    }
}

Still getting the A destination address is required in order to continue. error back even when sending in a shippingAddress.

Again, this is what is looks like when I do it through the admin UI (via inspecting the GraphQL call).

{
    "price": "0",
    "title": "630 Shannonville Rd",
    "shippingRateHandle": "2e6d17352d193a561152fd91eac544c4",
    "code": "630 Shannonville Rd",
    "source": "shopify",
    "deliveryMethodType": "PICK_UP",
    "locationId": "gid://shopify/Location/73026928928"
}

Which seems like we are supposed to be sending in the locationId along with the shippingLine, however the GraphQL mutation rejects the ShippingLine structure.

Thanks for your continued help on this.

Any update on this? Can you provide a working example of how to use the returned shipping line with the DraftOrderInput? I have some customers that need this feature integrated into our app…

Thanks!

Hey - checking this out on my side! Will update asap

Hi again @ozzyonfire

We am confirm this does work with a shipping address in the input. The steps are:

  1. Query draftOrderAvailableDeliveryOptions, and grab the local pickup option’s handle


3. Run the draftOrderCreate mutation with the handle passed in as the shippingLineInput.shippingRateHandle

mutation DraftOrderCreate($input: DraftOrderInput!) {
  draftOrderCreate(input: $input) {
    draftOrder {
      lineItems(first: 100) {
        edges {
          node {
            quantity
            requiresShipping
            title
          }
        }
      }
      shippingLine {
        id
        custom
        shippingRateHandle
        title
        originalPriceSet {
          presentmentMoney {
            amount
            currencyCode
          }
        }
      }
      shippingAddress {
        address1
        city
        provinceCode
        country
      }
    }
    userErrors {
      field
      message
    }
  }
}

input:

{
  "input": {
    "shippingLine": {
      "shippingRateHandle": "4e8227a87f8171a98584cc2959680be7"
    },
    "shippingAddress": {
      "address1": "123 Main St",
      "city": "Waterloo",
      "province": "Ontario",
      "country": "Canada",
      "zip": "A1A 1A1"
    },
    "billingAddress": {
      "address1": "456 Main St",
      "city": "Toronto",
      "province": "Ontario",
      "country": "Canada",
      "zip": "Z9Z 9Z9"
    },
    "lineItems": [
      {
        "title": "Custom product",
        "originalUnitPrice": 100,
        "quantity": 1,
        "requiresShipping": true
      }
    ]
  }
}

Thanks for the example @Liam-Shopify.

However, I am still having troubles. I am able to get a draft order created successfully, but the resulting draft order does not contain anything in the shippingLine field for the created draftOrder.

This is what I tried initially, however the resulting shippingLine is null, and if I view the draft order in the admin area, the “In store pickup” shipping method isn’t selected. This is what prompted me to try to add a price field which is when it started giving me the above errors.

Can you confirm that your resulting draft order actually does contain the specified shippingLine?

Here is my draftOrderInput:

{
  "billingAddress": {
    "firstName": "John",
    "lastName": "Smith",
    "address1": "630 Shannonville Rd",
    "city": "Shannonville",
    "provinceCode": "ON",
    "zip": "K0K 3A0"
  },
  "shippingAddress": {
    "firstName": "John",
    "lastName": "Smith",
    "address1": "630 Shannonville Rd",
    "city": "Shannonville",
    "provinceCode": "ON",
    "zip": "K0K 3A0"
  },
  "tags": [
    "test"
  ],
  "note": "This is a note on the order",
  "useCustomerDefaultAddress": false,
  "taxExempt": false,
  "paymentTerms": {
    "paymentTermsTemplateId": "gid://shopify/PaymentTermsTemplate/1"
  },
  "customAttributes": [],
  "localizedFields": [],
  "visibleToCustomer": false,
  "purchasingEntity": {
    "customerId": "gid://shopify/Customer/8861268607264"
  },
  "lineItems": [
    {
      "quantity": 1,
      "requiresShipping": true,
      "title": "Medium - Violin",
      "originalUnitPriceWithCurrency": {
        "amount": 1.23,
        "currencyCode": "CAD"
      },
      "weight": {
        "unit": "GRAMS",
        "value": 1
      },
      "taxable": true,
      "customAttributes": []
    }
  ],
  "shippingLine": {
    "shippingRateHandle": "2e6d17352d193a561152fd91eac544c4"
  }
}

And here is the returned draftOrder.

{
  "draftOrder": {
    "id": "gid://shopify/DraftOrder/1213712466208",
    "customer": {
      "id": "gid://shopify/Customer/8861268607264",
      "__typename": "Customer"
    },
    "shippingLine": null,
    "__typename": "DraftOrder"
  },
  "userErrors": [],
  "__typename": "DraftOrderCreatePayload"
}

Note the shippingLine is null.

Thanks again for your help on this.

I finally found the issue after banging my head against the desk… I was sending in the shipping and billing addresses without a valid country code. Oddly, this created the draft order without and errors, and the shipping and billing addresses looked okay on the draft order, but the shippingLine would never apply.

Thanks for your help on getting this resolved!