What's your biggest current challenge? Have your say in Community Polls along the right column.
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.

Create multiple shipping zones and rates graphQL

Solved

Create multiple shipping zones and rates graphQL

HiT2
Tourist
7 0 1

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 

Accepted Solution (1)

ShopifyDevSup
Shopify Staff
1453 238 525

This is an accepted solution.

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

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

View solution in original post

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 525

This is an accepted solution.

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

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