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

1 Like