Delivery Profiles via GrahQL API - How to add products?

Solved
Highlighted
Excursionist
26 0 1

Hello,

We are using the GraphQL version of the Shopify API.

The documentation for the deliveryProfileUpdate is here.

This thread on these forums helps a little bit.

 

Yet still a huge doubt:  How can I add products to a delivery profile?

Via the Shopify administration (web control panel) I created a new Shipping Profile.

I then used the GraphiQL app to get the profile's gid.  That returned:

"id": "gid://shopify/DeliveryProfile/1234567890",
            "name": "Test Shipping Profile"

 

So my super duper question: How can we add products to that profile?

Would it be with the mutation for deliveryProfileUpdate?

If so, can somebody post an example?

 

Thank you, yet after much reading, I am still lost as to how this can be created / done.

EOL

0 Likes
Highlighted
Shopify Partner
520 38 109

According to the API documentation for this method (https://shopify.dev/docs/admin-api/graphql/reference/mutation/deliveryprofileupdate?api[version]=202...), you would presumably define the item(s) to the variantsToAssociate field. Specifically the GID for each ProductVariant.   

0 Likes
Highlighted
Excursionist
26 0 1

Thanks @Greg_Kujawa ... yet I'm still at a loss.

 

If I try to do this with variables, using the method in this message, it blows up with an error.

The error states "expected String to be a Hash".

 

To date, I am still in disbelief that somebody actually uses variables in Shopify's Python GraphQL API.

I've just never seen it.

 

Any and all examples would be greatly welcomed.

I'll post what I'm doing below.

0 Likes
Highlighted
Excursionist
26 0 1

This is the code I'm running:

 

import shopify
import json

version = "2020-01"
#################
store       = 'myStore'
domain      = 'myStore.myshopify.com'
api_key     = '123'
password    = 'shppa_123'
#################

session = shopify.Session("{0}".format(domain), version, password)
shopify.ShopifyResource.activate_session(session)
client = shopify.GraphQL()

profile_update_query = """
                        mutation deliveryProfileUpdate($id: ID!, $profile: DeliveryProfileInput!) {
                            deliveryProfileUpdate(id: $id, profile: $profile) {
                            profile {
                            id
                        }
                        userErrors {
                            field
                        message
                        }
                        }
                        }
                        """
print("---200")

variables_profile    = """
                        {
                          id      : "gid://shopify/deliveryprofile/123",
                          profile : {
                                      "variantsToAssociate" : "gid://shopify/Product/123"
                                    }
                        }
                        """



print("---300")
json_text = client.execute(profile_update_query, variables_profile)
print("------------------")
print(json_text)
print("------------------")

 

 

When this runs, I get an error back stating:

 

 

b'{"errors":{"variables":"expected String to be a Hash"}}'

 

EDIT:

This guy in stackoverflow might have some light on the subject.

 

0 Likes
Highlighted
Shopify Partner
520 38 109

This is an accepted solution.

If your issue is directly related to this Python library, then I'm at a loss. But below is an example JSON request payload, and the JSON response from a successful test call I just made. Using the Shopify GraphiQL app plugged into my test shop. Hope this helps a little at least.

{
   "query":"mutation deliveryProfileUpdate($id: ID!, $profile: DeliveryProfileInput!) {  deliveryProfileUpdate(id: $id, profile: $profile) {    profile {      id    }    userErrors {      field      message    }  }}",
   "variables":{
      "id":"gid://shopify/DeliveryProfile/64987037858",
      "profile":{
         "variantsToAssociate":"gid://shopify/ProductVariant/31620852416564"
      }
   },
   "operationName":"deliveryProfileUpdate"
}

 

{
   "data":{
      "deliveryProfileUpdate":{
         "profile":{
            "id":"gid:\/\/shopify\/DeliveryProfile\/64987037858"
         },
         "userErrors":[

         ]
      }
   },
   "extensions":{
      "cost":{
         "requestedQueryCost":10,
         "actualQueryCost":10,
         "throttleStatus":{
            "maximumAvailable":1000.0,
            "currentlyAvailable":990,
            "restoreRate":50.0
         }
      }
   }
}
1 Like
Highlighted
Excursionist
26 0 1

Thank you @Greg_Kujawa 

 

Yes, I am using the Python library for Shopify API using GraphQL.

 

I stopped using the GraphiQL app inside Shopify's control panel, because the jump between it and the Python library was too big.

 

I will keep on trying.

If anybody has any suggestions, please do let me know.

 

Thanks again Greg!

0 Likes
Highlighted
Shopify Partner
520 38 109

I might have stumbled upon your possible solution. According to some other posts it appears as if the variables are just passed as straight JSON in the Python library. See https://stackoverflow.com/questions/48693825/making-a-graphql-mutation-from-my-python-code-getting-e... for specifics.

So your Python code should look like this I'm thinking:

variables_profile = { id: 'gid://shopify/deliveryprofile/123', profile : { 'variantsToAssociate': 'gid://shopify/Product/123' }}

 

I could be wrong, since I've never used this Python library before but it's worth a shot...lol.

1 Like
Highlighted
Excursionist
26 0 1

Wowza!! Going to try this the night after tomorrow. I will update back asap. Thank you @Greg!!!

0 Likes
Highlighted
Excursionist
26 0 1

Finally got around to try the code.

 

I get the error message stating:

b'{"errors":{"variables":"expected String to be a Hash"}}'

 

The variables look like this:

variables_profile    = """
                            {
                                id: "gid://shopify/deliveryprofile/12345",
                                profile : {
                                            variantsToAssociate : "gid://shopify/Product/12345"
                                          }
                            }
                        """

 

I still haven't figured this out.

0 Likes
Highlighted
Excursionist
26 0 1

Ok, the working variable is as follows:

variables_profile = { "id" : "gid://shopify/deliveryprofile/12345", "profile" : { "variantsToAssociate" : "gid://shopify/Product/12345" }}
0 Likes