How to edit existing shipping rates via graphQL shopify API

How to edit existing shipping rates via graphQL shopify API

HiT2
Tourist
7 0 1

Hello,

I am trying to update some existing shipping rates using graphQL, but I keep getting an error saying : Profile is invalid: ID must be present during an update.

This is my code: 

 

 

mutation {
	deliveryProfileUpdate(
    # Specify the delivery profile ID to update.
    id: "gid://shopify/DeliveryProfile/84574077117"
	profile: {
      locationGroupsToUpdate: [
        {
		  id: "gid://shopify/DeliveryLocationGroup/87830823101"
          ,
        zonesToUpdate: {
		  id: "gid://shopify/DeliveryZone/386121531581"
          methodDefinitionsToUpdate: [{
			
			name: "Standard - Royal Mail Tracked 24"		
            rateDefinition: {price: { amount: 30, currencyCode: GBP } } 
			    
                                }

			{
 			name: "Standard - Royal Mail Tracked 24"
			rateDefinition: { price: { amount: 50, currencyCode: GBP } } 
			
                                }
      {
      name: "Standard - Royal Mail Tracked 48"
  		rateDefinition: { price: { amount: 5.05, currencyCode: GBP } } 
  		
                                }   
        {
  			name: "Standard - Royal Mail Tracked 48"
  		  rateDefinition: { price: { amount: 5.70, currencyCode: GBP } } 
  		  
                                } 
        {
        name: "Premium DHL/DPD Tracked 24"
    		rateDefinition: { price: { amount: 6.35, currencyCode: GBP } } 
    		
                                  }   
          {
    			name: "Premium DHL/DPD Tracked 24"
    		  rateDefinition: { price: { amount: 6.86, currencyCode: GBP } } 
    		  
                                  }
          {
          name: "Premium DHL/DPD Pre-Noon"
      		rateDefinition: { price: { amount: 11.16, currencyCode: GBP } } 
      		
                                    }                      

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

 

 

 I suspect there is something wrong with the methodDefitionsToUpdate, where I believe there needs to be an ID. However, I could not find anything online to be able to retrieve the method definition ID/

Thank you for your help

Reply 1 (1)

ShopifyDevSup
Shopify Staff
1453 238 511

Hi @HiT2 👋

 

The payload is missing `DeliveryMethodDefinitionInput.id`, which is required when updating a method definition. This query should locate it for you:

 

{
    deliveryProfile(id:"gid://shopify/DeliveryProfile/123"){
        profileLocationGroups (locationGroupId: "gid://shopify/DeliveryLocationGroup/456") {
            locationGroupZones (first:3) {
                nodes {
                    methodDefinitions (first: 3){
                        nodes {
                            id # <----- need this one
                        }
                    }
                }
            }
        }
    }
}

 

Below is an example `deliveryProfileUpdate` mutation where prices of the rateDefinition is updated:

mutation ($id: ID!, $profile: DeliveryProfileInput!) {
    deliveryProfileUpdate(id: $id, profile: $profile) {
        profile {
            profileLocationGroups {
                locationGroupZones (first:3) {
                    nodes {
                        methodDefinitions (first:3){
                            nodes {
                                id
                                name
                                rateProvider {
                                    ... RateProvider
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

fragment RateProvider on DeliveryRateProvider {
    __typename
    ... on DeliveryParticipant {
        id
        fixedFee {
            amount
            currencyCode
        }
    }
    ... on DeliveryRateDefinition {
        id
        price {
            amount
            currencyCode
        }
    }
}

 

with variables:

{
    "id": "gid://shopify/DeliveryProfile/123",
    "profile": {
        "locationGroupsToUpdate": [{
            "id":  "gid://shopify/DeliveryLocationGroup/234",
            "zonesToUpdate": {
                "id": "gid://shopify/DeliveryZone/345",
                "methodDefinitionsToUpdate": [{
                    "id":"gid://shopify/DeliveryMethodDefinition/456",
                    "rateDefinition":{
                        "id": "gid://shopify/DeliveryRateDefinition/567",
                        "price": {
                            "amount": 101,
                            "currencyCode": "CAD"
                        }
                    }
                }]
            }
        }]
    }
}

 

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