Can product data be accessed in multiple languages via API?

resboss
Shopify Partner
29 0 5

Is it possible to get product data in different languages via API ?

Replies 3 (3)

magecomp
Shopify Partner
264 20 32

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
        }
      }
    }
  }
}
The 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.

Helping voluntarily. Please like and accept the solution if it helps. Thanks!
Our Bestseller Shopify Apps    |      Mobile App Builder by MageComp    |      Limit Qty Purchase

Need a developer?  Just visit MageComp website
olehbro
Visitor
1 0 0
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
                        )

                )

        )

)

remy727
Shopify Partner
40 2 22

 

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). 

Looking for a Shopify App developer? Please visit: https://github.com/remy727