How to assign a product/variant to a deliveryProfile - via a script?

Solved
Highlighted
New Member
4 0 0

trying to assign products to the new Shipping Profiles  (which are call deliveryProfiles in the graphql-API).

Seems that product/variants are linked to the deliveryProfile via the ProfileItems Object.

If I understand correctly the ProfileItems Object is the one that captures which product-variant belongs to which delivery profile, so updating/adding/deleting for that object would move the product to a different (or general) shipping profile.


I'm not able to find which REST-API endpoint or which graphQL mutation will help me assign the product to a profile.

Am I looking at the right place or can this right now only be done in the admin screens?

tx. 

 

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 129

This is an accepted solution.

Hi @go4it ,

 

In order to assign Products and Product Variants (and thereby add ProfileItems) to your Shipping/Delivery Profiles programmatically via our GraphQL Admin API, you need to use the mutation of `deliveryProfileCreate` or `deliveryProfileUpdate`. When calling these mutations, you need to include the input of "profile" which will be an object of type "DeliveryProfileInput". In this "profile" object you can include the field of "variantsToAdd", which will then be populated by the product variant IDs of the products you would like to assign to your new Shipping Profiles.

 

Here is an example of the `deliveryProfileCreate` mutation being called to create a new Shipping Profile with a product added to it:

mutation {
  deliveryProfileCreate (profile: { 
    	name: "Name of your Shipping Profile",
      variantsToAssociate: [
        "gid://shopify/ProductVariant/{Insert-Product-Variant-ID-Here}",
      ]
  }) {
    profile {
      id
      name
      profileItems (first: 10) {
        edges {
          node {
            product {
              id
            }
            variants (first:10) {
              edges {
                node {
                  id
                  displayName
                }
              }
            }
          }
        }
      }
    } userErrors {
      field
      message
    }
	}
}

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

Highlighted
New Member
4 0 0

@hassain 
Perfect. Thanks for pointing out that this goes via the deliveryProfileUpdate mutation. (with the input of mutation). 
Your example is much appriciate as getting some of the GQL syntax is a bit confusing :-) 

Is working now. 

 

Sorry to the late reply, got sidetracked on other work. 

Regards, 

0 Likes
Highlighted
New Member
1 0 0

@hassain 

 

Is there a method to remove a product from a shipping profile?

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 129

@MaxShineOn ,

 

Yeah as I mentioned in my earlier comment there us `deliveryProfileUpdate` https://shopify.dev/docs/admin-api/graphql/reference/mutation/deliveryprofileupdate

 

In the input of this mutation you would want to use the variantsToDissociate field 

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

Highlighted
Shopify Partner
2 0 0

Can the delivery profile be changed with Shopify's Admin REST API? (for a particular product like above)

 

I wasn't able to find documentation. But maybe I'm missing something.

0 Likes
Highlighted
Shopify Staff (Retired)
Shopify Staff (Retired)
624 102 129

Hi @danrichards ,

 

In the REST API you can use the resource of ShippingZones - https://shopify.dev/docs/admin-api/rest/reference/store-properties/shippingzone

 

After API version 2019-07 this endpoint returns 3 values related to delivery profiles:

  • profile_id: The ID of the zone’s delivery profile
  • location_group_id: The ID of the zone’s location group
  • admin_graphql_api_id: The zone’s ID for use with the GraphQL Admin AP

Also I would recommend reading this documentation that describes how you can update your app from using legacy API endpoints to making use of delivery profiles https://shopify.dev/tutorials/migrate-your-app-to-support-delivery-profiles#shippingzone

Hassain | Developer Support Specialist @ Shopify
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution 

0 Likes