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.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Updating a Shipping Zone using GraphQL

Solved

Updating a Shipping Zone using GraphQL

Lemonn
Visitor
3 1 2

Hi, I'm attempting to manage and change the shipping zone and rate for a Shipping Profile. My GraphQL query looks like this:

 

mutation { 
                deliveryProfileUpdate(
                    id: "{dp_id}",
                    profile: {
                        locationGroupsToUpdate: [{
                            zonesToUpdate: [{
                                countries: [{
                                    code: US
                                    provinces: [{code: "AK"},
                                                {code: "AS"},
                                                {code: "GU"},
                                                {code: "HI"},
                                                {code: "MP"},
                                                {code: "PR"},
                                                {code: "VI"},
                                                {code: "FM"},
                                                {code: "PW"},
                                                {code: "MH"},
                                                {code: "AA"},
                                                {code: "AE"},
                                                {code: "AP"
                                }]
                            }]
                        }]
                    }]
                 }
              )
                  {
                      profile {
                          id
                      }               
                      userErrors {
                          field
                          message
                      }
                  }
              }

 

 

The response I print out is the following:

 

{"data":{"deliveryProfileUpdate":{"profile":null,"userErrors":[{"field":null,"message":"Profile is invalid: ID must be present during an update."}]}},"extensions":{"cost":{"requestedQueryCost":10,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":100
0.0,"currentlyAvailable":990,"restoreRate":50.0}}}}

 

 

And the GID I pass in the query is this:

 

"gid://shopify/DeliveryProfile/75937513680"

 

 

What I'm trying to do is remove the states in the `provinces` list from the already existing "Domestic" shipping profile. Why am I getting an ID error? Am I even using the correct query/fields to update a `DeliveryProfile`'s zones? I'd appreciate any insight.

Accepted Solution (1)

Lemonn
Visitor
3 1 2

This is an accepted solution.

Update: Fixed it, you needed the `locationGroup` and `locationGroupZone` IDs for this to work.

This is the working query:

 

mutation {
                deliveryProfileUpdate(
                    id: "{dp_id}",
                    profile: {
                        locationGroupsToUpdate: [{
                            id: "{lg_id}",
                            zonesToUpdate: [{
                                id: "{lgz_id}",
                                name: "Domestic",
                                countries: [{
                                    code: US
                                    provinces: [{code: "AK"},
                                                {code: "AS"},
                                                {code: "GU"},
                                                {code: "HI"},
                                                {code: "MP"},
                                                {code: "PR"},
                                                {code: "VI"},
                                                {code: "FM"},
                                                {code: "PW"},
                                                {code: "MH"},
                                                {code: "AA"},
                                                {code: "AE"},
                                                {code: "AP"
                                }]
                            }]
                        }]
                    }]  
                }
            )
                {
                    profile {
                        id
                    }              
                    userErrors {
                        field
                        message
                    }
                }
            }

 

 

Where `dp_id` is the `deliveryProfile` ID, and `lg_id` and `lgz_id` are the `locationGroup` and `locationGroupZone` IDs respectively. This particular code updates the profile to only include the 13 states listed.

View solution in original post

Replies 2 (2)

Lemonn
Visitor
3 1 2

This is an accepted solution.

Update: Fixed it, you needed the `locationGroup` and `locationGroupZone` IDs for this to work.

This is the working query:

 

mutation {
                deliveryProfileUpdate(
                    id: "{dp_id}",
                    profile: {
                        locationGroupsToUpdate: [{
                            id: "{lg_id}",
                            zonesToUpdate: [{
                                id: "{lgz_id}",
                                name: "Domestic",
                                countries: [{
                                    code: US
                                    provinces: [{code: "AK"},
                                                {code: "AS"},
                                                {code: "GU"},
                                                {code: "HI"},
                                                {code: "MP"},
                                                {code: "PR"},
                                                {code: "VI"},
                                                {code: "FM"},
                                                {code: "PW"},
                                                {code: "MH"},
                                                {code: "AA"},
                                                {code: "AE"},
                                                {code: "AP"
                                }]
                            }]
                        }]
                    }]  
                }
            )
                {
                    profile {
                        id
                    }              
                    userErrors {
                        field
                        message
                    }
                }
            }

 

 

Where `dp_id` is the `deliveryProfile` ID, and `lg_id` and `lgz_id` are the `locationGroup` and `locationGroupZone` IDs respectively. This particular code updates the profile to only include the 13 states listed.

ShopifyDevSup
Shopify Staff
1453 239 535

Hi @SAJIDMASOOD 👋

You can surface `DeliveryLocationGroup.id` through the `deliveryProfiles` query:

{
    deliveryProfiles (first:3){
        nodes {
            id 
            profileLocationGroups {
                locationGroup { id } # <----- here
                ...
            }
        }
    }
}


Here it is in an example input for the `deliveryProfileUpdate` mutation:

{
    "id": "gid://shopify/DeliveryProfile/123",
    "profile": {
        "locationGroupsToUpdate": [{
            "id":  "gid://shopify/DeliveryLocationGroup/456",
            ...
        }]
    }
}

 

Hope that helps!

Developer Support @ Shopify
- Was this reply helpful? Click Like to let us know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog