Updating a Shipping Zone using GraphQL

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.

1 Like

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.

1 Like

Hi @SAJIDMASOOD :waving_hand:

You can surface [DeliveryLocationGroup.id](https://shopify.dev/docs/api/admin-graphql/2023-04/objects/DeliveryLocationGroup#field-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!