'variables': 'expected String to be a Hash'}} Error when use python to translate language

Highlighted
New Member
2 0 0

Hi I try to use the python to translate the language with GraphQL API. but show {'errors': {'variables': 'expected String to be a Hash'}}.  Any one know what is wrong? Thank you very much. This work without the variables

from setting import API_KEY, PASSWORD,API_VERSION,SHOP_NAME,SHARED_SECRET
import requests

headers = {
        'accept':"application/json",
        'Content-Type':'application/json',
        'X-Shopify-Access-Token': PASSWORD
    }

query='''
mutation CreateTranslation($id: ID!, $translations: [TranslationInput!]!) {
  translationsRegister(resourceId: $id, translations: $translations) {
    userErrors {
      message
      field
    }
    translations {
      locale
      key
      value
    }
  }
}
    '''
variables='''
  {
  "id": "gid://shopify/Link/779818184",
  "translations": [
    {
      "key": "title",
      "value": "Produkte",
      "locale": "de",
      "translatableContentDigest": "4edc8bfafc6bd936b849f38c009454eac0febc8982f990e734724156584d56f9"
    }
  ]
}
'''

r=requests.post("https://feiyutech.myshopify.com/admin/api/2020-01/graphql.json",json={'query':query,'variables':variables},headers=headers)

Array=r.json()
print(Array)
0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 167

Hey @feiyutech,

 

Sounds like your variables are coming through as a string.

 

I'm not familiar with Python, but some threads to follow here: https://community.shopify.com/c/Shopify-APIs-SDKs/Python-GraphQL-query-with-variables/td-p/541545

 

Let me know if you get stuck.

 

Notice; Out of office, replies will be delayed until my return. Thanks!
1 Like
Highlighted
Excursionist
26 0 1

NOTE: The below information is wrong.

I will keep it here and update it when I find a solution.

The message below is WRONG!

=================================

I received this message:

'variables': 'expected String to be a Hash'}}

When trying to use variables in Shopify's GraphQL API using the shopify_python_api library.

I had no idea *where* to place the variables.

Hoping this helps others:

The variables go at the end of your query.

So say you have

query_for_api = """
mutations and stuff.... {
}

"variables" : { whatever it is you put here... maybe from the GraphiQL application.
}
"""

Then just send the entire query to be executed:

client.execute(query_for_api)

I hope this helps someone.

 

EOL

0 Likes
Highlighted
New Member
1 0 0

Hello Guys,

 

I'm also trying to solve this without any progress. Is there any solution?

 

I read the threads posted here and other sources. 

 

Here is what I created until now:

 

The params:

{
    "input": {
        "descriptionHtml": "xxx",
        "title": "xxx",
        "tags": "xxx",
        "variants": [
            {
                "title": "sport Layouts Shiney TightsDamen gr\u00fcn Gr\u00f6\u00dfe XS",
                "barcode": "7314840007567",
                "price": "39.29",
                "options": [
                    "XS"
                ]
            }
        ]
    }
}

The requests I send:

response = requests.post(shop_url, json={"query":query, "variables": param})

 

0 Likes
Highlighted
Excursionist
26 0 1

Check this answer out, on this thread: GraphQL Variables Help Please

 

I asked over there, and one of the Shopify Staff replied and explained how to do it.

0 Likes