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

Highlighted
New Member
1 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
Shopify Staff
Shopify Staff
216 36 37

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 

0 Likes