App reviews, troubleshooting, and recommendations
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
Is it possible to get product data in different languages via API ?
Hello @resboss
You will need to use the @inContext
directive. The @inContext
the directive allows you to specify the language that you want to retrieve product data in. For example, the following query will retrieve product data in French:
{
products(first: 10, reverse: true) {
edges {
node {
id
translations(locale: "fr") {
key
locale
value
}
}
}
}
}
translations
object will contain all of the translations for the product, including the title, description, and options. The locale
property will indicate the language of the translation.You can also use the Accept-Language
HTTP header to specify the language that you want to retrieve product data in. For example, the following request will retrieve product data in the language of the user's browser:
curl -X GET \
-H "Accept-Language: fr" \
"https://my-store.myshopify.com/admin/api/2022-04/products.json" \
-H "X-Shopify-Access-Token: xxxxx"
The Shopify API will return the product data in the language that you specified.
Array ( [errors] => Array ( [0] => Array ( [message] => Field 'translations' doesn't exist on type 'Product' [locations] => Array ( [0] => Array ( [line] => 6 [column] => 9 ) ) [path] => Array ( [0] => query [1] => products [2] => edges [3] => node [4] => translations ) [extensions] => Array ( [code] => undefinedField [typeName] => Product [fieldName] => translations ) ) ) )
You can create a translation using translationsRegister (requires write_translations access_scope).
You can retrieve the translation content of the product using translatableResource (requires read_translations access_scope).