How to force to compute for shipping rates

ericute
Shopify Partner
57 4 7

For subscription orders, is there a mutation to get a new shipping rate? For example, the customer changes their address. We'd like Shopify to recompute the rate based on the new address.

Replies 4 (4)

Brian_S
Shopify Partner
157 19 39

You can always grab the shipping options available on a SubscriptionDraft: https://shopify.dev/api/admin-graphql/2022-04/objects/SubscriptionDraft#field-subscriptiondraft-ship...

 

That said - you'll have to implement a retry mechanism bc it fails (or returns an empty array) often and if there are too many lines it fails every time.

Brian Singer
CTO & Cofounder of Subscription Service - Awtomic
ericute
Shopify Partner
57 4 7

Hi, @Brian_S.

 

Here's a sample GraphQL query I have. I'm passing in a Draft ID on it and a new address.

 

query ($id:ID!) {
    subscriptionDraft(id: $id) {
    deliveryPrice{
        amount
    }
    shippingOptions(
        deliveryAddress: {
            firstName: "Eric",
            lastName: "Test",
            address1: "4754 Irving Road",
            address2: "",
            city: "Athens",
            provinceCode: "OH",
            countryCode: US,
            zip: "45701"
        }
    ) {
        __typename
        ... on SubscriptionShippingOptionResultSuccess {
            shippingOptions {
                title
                presentmentTitle
                description
                code
                price {
                amount
                currencyCode
                }
            }
        }
    }
    id
    status
    }
}

 

 

Here's the response from Postman.

 

{
    "data": {
        "subscriptionDraft": {
            "deliveryPrice": {
                "amount": "0.0"
            },
            "shippingOptions": {
                "__typename": "SubscriptionShippingOptionResultSuccess",
                "shippingOptions": []
            },
            "id": "gid://shopify/SubscriptionDraft/125750378712",
            "status": "ACTIVE"
        }
    },
    "extensions": {
        "cost": {
            "requestedQueryCost": 3,
            "actualQueryCost": 3,
            "throttleStatus": {
                "maximumAvailable": 10000.0,
                "currentlyAvailable": 9997,
                "restoreRate": 500.0
            }
        }
    }
}

 

 

I'm getting a "0.0" delivery price. Is this supposed to recompute the shipping rate?

ericute
Shopify Partner
57 4 7

@Brian_S I get it now. We're getting shippingOptions but it almost always returns empty array as seen in my snippet above.

Brian_S
Shopify Partner
157 19 39

That's right. This is one of the most difficult parts of the subscription apis.  There used to be Shopify docs around this stuff but I can't find them now. 

 

Sometimes the shipping options are empty, null and sometimes we get an error response.. we've just found that a retry mechanism is required and it leads to slower processing/UI

Brian Singer
CTO & Cofounder of Subscription Service - Awtomic