Create multiple shipping zones and rates graphQL

Hello I am trying to create multiple shipping zones with their respective rates via graphQL. This is what I have :

mutation {
	deliveryProfileUpdate(
    # Specify the delivery profile ID to update.
    id: "gid://shopify/DeliveryProfile/102925435191"
	profile: {
      locationGroupsToCreate: {
        locations: "gid://shopify/Location/82401394999"
        # Create a delivery zone.
        zonesToCreate: [{
          name: "UK Domestic"
          # Add countries to the delivery zone.
          countries: [{ code: GB,  provinces : [
						{
                    code: "NIR"
						}]
		}],
          methodDefinitionsToCreate: [{
            name: "Standard - Royal Mail Tracked 24"
            rateDefinition: { price: { amount: 5.70, currencyCode: GBP } } 
			      weightConditionsToCreate: [ { 
                                    criteria: {
                                        unit: GRAMS,
                                        value: 0,
                                    },
                                    operator: GREATER_THAN_OR_EQUAL_TO
                                },
                                 {
                                    criteria: {
                                        unit: GRAMS,
                                        value: 1000,
                                    },
                                    operator: LESS_THAN_OR_EQUAL_TO
                                } ]
			     
                                }
          ]
      },
      {
        name: "UK Domestic"
        # Add countries to the delivery zone.
        countries: [{ code: IE
  }],
        methodDefinitionsToCreate: [{
          name: "testest"
          rateDefinition: { price: { amount: 10.70, currencyCode: GBP } } 
          weightConditionsToCreate: [ { 
                                  criteria: {
                                      unit: GRAMS,
                                      value: 0,
                                  },
                                  operator: GREATER_THAN_OR_EQUAL_TO
                              },
                               {
                                  criteria: {
                                      unit: GRAMS,
                                      value: 1000,
                                  },
                                  operator: LESS_THAN_OR_EQUAL_TO
                              } ]
         
                              }
        ]
    }

      ]
      }
      }
  	) {
    profile {
      id
      profileLocationGroups {
        locationGroupZones(first: 5) {
          edges {
            node {
              zone {
                id
                name
                countries {
                  id
                  name
                  provinces {
                    id
                    name
                    code
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}

When I run it, it does not return any error, however it does not create what I want. Thank you very much for your help

Hi @HiT2 ,

To see the errors that the mutation generates you need to request the userErrors { message field } in the return value. Then you’ll be able to work through the errors and resolve the issues. There’s an example with userErrors included at the upper right of the doc page for the deliveryUpdateMutation.

As an example, when testing this payload in a test store with a deliveryProfileCreate mutation the error returned through userErrors was “Profile is invalid: Cannot create zones with non-unique names.”. This happened because there’s 2 zones with the same name “UK Domestic” being specified in the ‘zonesToCreate’ section.

Hope you have a great day

1 Like