A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hi I need read the traslation that are stored in shopify, I need to do from CURL (by MSSQL) to insert into table
the problem is the double quote for the idMetafield
curl -H "Content-Type: application/json" -H "X-Shopify-Access-Token: mykey" -X POST "https://mydomain.myshopify.com/admin/api/2022-04/graphql.json" -d"{query {translatableResource(resourceId: \" gid://shopify/Metafield/29751869047048\") {resourceId resourceId translations(locale: \"it\") {key value}}}}"
To insert I don't have problem, I use the "pre-request" and after I insert the value.. but for read?
curl -H "Content-Type: application/json" -H "X-Shopify-Access-Token: mykey" -X POST "https://mysite.myshopify.com/admin/api/2022-04/graphql.json" -d"{\"query\": \"mutation CreateTranslation($id: ID!, $translations: [TranslationInput!]!) { translationsRegister(resourceId: $id, translations: $translations) { userErrors {message field} translations {locale key value} } }\",\"variables\": {\"id\": \"gid://shopify/Metafield/29751869047048\",\"translations\": [{\"key\": \"value\",\"value\": \"Francese\",\"locale\": \"it\",\"translatableContentDigest\": \"mydigest\"},{\"key\": \"value\",\"value\": \"Français\",\"locale\": \"fr\",\"translatableContentDigest\": \"7fc9b39f0e2450f734b162015bff9222637dca7c25fc1c7318bc5c87357456db\"},{\"key\": \"value\",\"value\": \"Französisch\",\"locale\": \"de\",\"translatableContentDigest\": \"7fc9b39f0e2450f734b162015bff9222637dca7c25fc1c7318bc5c87357456db\"},{\"key\": \"value\",\"value\": \"Francés\",\"locale\": \"es\",\"translatableContentDigest\": \"7fc9b39f0e2450f734b162015bff9222637dca7c25fc1c7318bc5c87357456db\"}]}}"
Why? I need create for the "read" the same structure?
Solved! Go to the solution
This is an accepted solution.
Ok I find solution, put \\\"
-d "{\"query\": \"query { translatableResource(resourceId: \\\"gid://shopify/Metafield/29751869047048\\\")
Hi CStefano,
Just to confirm, you're trying to read the translations stored in Shopify using a CURL command? If so, you'll need to use the query
operation in your GraphQL request. Your CURL command seems correct, but it appears that you are having trouble with the double quotes in the resourceId
.
One solution could be to use single quotes ('
) to wrap the entire data payload -d
, and use double quotes ("
) in your JSON as normal. Here's how your CURL command could look:
curl -H "Content-Type: application/json" -H "X-Shopify-Access-Token: mykey" -X POST "https://mydomain.myshopify.com/admin/api/2022-04/graphql.json" -d'{"query": "{translatableResource(resourceId: \"gid://shopify/Metafield/29751869047048\") {resourceId translations(locale: \"it\") {key value}}}}"
This command will retrieve the translated resource with the given resourceId
. For creating (or updating) translations, you need to use the mutation
operation in your GraphQL request. The structure of the mutation
operation is different from the query
operation. In your case, your CURL command for creating translations looks correct.
If you are still having issues, could you please provide more details or any error messages you are getting? Hope this helps!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me 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
hi, thank for the reply but I can't remove the ", the curl from DOS\Windows need " and for separate " I need put \" in the 'details'
I don't understand why if I run a query
curl -X POST \
https://mysite.myshopify.com/admin/api/2023-07/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: mykey' \
-d '{
"query": "query { translatableResources(first: 5, resourceType: PRODUCT) { edges { node { resourceId translatableContent { key value digest locale } } } } }"}'
is ok but if I try to read the traslation go to error
curl -X POST \
https://mysite.myshopify.com/admin/api/2023-10/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: mykey' \
-d '{"query": "query { translatableResource(resourceId: "gid://shopify/Metafield/29751869047048") { resourceId translatableContent { key value digest locale } } }"}'
Bad Request
Hey @CStefano
Looking at the query itself that is contained in your CURL request, there's nothing there that would prevent it from working, that's formatted properly. The most likely reason is the use of quotes in your CURL request, as identified by Liam.
The first request works because it doesn't have any nested double quotes in the JSON string. The second request fails because it has nested double quotes in the JSON string, which leads to a "Bad Request" error.
Here's a working Curl request that I exported directly from postman after testing.
curl --location 'https://[your-store-name].myshopify.com/admin/api/2023-07/graphql.json' \
--header 'X-Shopify-Access-Token: [your-access-token]' \
--header 'Content-Type: application/json' \
--data '{"query":"{translatableResource(resourceId: \"gid://shopify/Metafield/[your-metafield-id]\") {resourceId translatableContent {key value digest locale}}}", "variables":{}}'
You'll notice in this version the double quotes inside the JSON string are escaped using a backslash (\")
Hope that helps!
- Kyle G.
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
Hi, for linux is perfect the problem is for windows\dos... to send the CURL we must use " not ' if I send CURL 'site' receive a error... I need send curl "site" and the parameter the same with " but when I need send the resource "gid://.." there is the problem... I need to find a solution to send the double quota
with \"\" receive a error the same with \"\"\"
This is an accepted solution.
Ok I find solution, put \\\"
-d "{\"query\": \"query { translatableResource(resourceId: \\\"gid://shopify/Metafield/29751869047048\\\")
Hey @CStefano , thanks for sharing that resolution you found! I'm sure it will help many other developers running in to the sam issue with windows/dos!
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
Sorry I don't understand... I want read the metafield traslation... too see if correct and update only the wrong...