Have your say in Community Polls: What was/is your greatest motivation to start your own business?
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.

How to force to compute for shipping rates

How to force to compute for shipping rates

ericute
Shopify Partner
61 4 14

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
171 21 44

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
61 4 14

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
61 4 14

@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
171 21 44

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