A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
Hello,
I'm able to get the products translation via GraphQL API but I can't figure out how and if it's possible to get translated metafields as well. More specifically I need to recover the variant metafields.
This is my current call with untranslated metafield
query getProduct { product(id: "gid://shopify/Product/6550868590685") { en: translations(locale: "en") { key locale value } de: translations(locale: "de") { key locale value } fr: translations(locale: "fr") { key locale value } variants(first: 1) { edges { node { metafield1: metafield(namespace: "custom", key: "main_color") { value } } } } } }
Could someone help me?
Thanks so much
Solved! Go to the solution
This is an accepted solution.
Hi @egiuliani & @Kalen_Jordan 👋
To query translatable resources for metafields, you can specify the `resourceType` to be `METAFIELD`, or query them by the metafield ID:
{
translatableResources(first: 3, resourceType: METAFIELD) {
nodes {
resourceId
translatableContent {
key
value
}
}
}
translatableResourcesByIds(first: 5, resourceIds: [
"gid://shopify/Metafield/123",
"gid://shopify/Metafield/456"
]) {
nodes {
resourceId
translatableContent {
key
value
}
}
}
}
For variant metafields, it would involve a 2 step process:
1. fetch all the metafield IDs for the variants:
{
productVariants(first:5) {
nodes {
metafield(namespace:"custom", key:"main_color"){
id
}
}
}
}
2. then use the returned metafields in the `translatableResourcesByIds` query:
{
translatableResourcesByIds(first: 5, resourceIds: [
"gid://shopify/Metafield/123", ...
]) {
nodes {
resourceId
translatableContent {
key
value
}
}
}
}
Hope that helps!
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
I still have the same problem, does anyone have a solution? I need a way to extract metafield translations via API, translations are entered via Translate & Adapt
Thanks
did you found solution?
Also looking for help with this.
This is an accepted solution.
Hi @egiuliani & @Kalen_Jordan 👋
To query translatable resources for metafields, you can specify the `resourceType` to be `METAFIELD`, or query them by the metafield ID:
{
translatableResources(first: 3, resourceType: METAFIELD) {
nodes {
resourceId
translatableContent {
key
value
}
}
}
translatableResourcesByIds(first: 5, resourceIds: [
"gid://shopify/Metafield/123",
"gid://shopify/Metafield/456"
]) {
nodes {
resourceId
translatableContent {
key
value
}
}
}
}
For variant metafields, it would involve a 2 step process:
1. fetch all the metafield IDs for the variants:
{
productVariants(first:5) {
nodes {
metafield(namespace:"custom", key:"main_color"){
id
}
}
}
}
2. then use the returned metafields in the `translatableResourcesByIds` query:
{
translatableResourcesByIds(first: 5, resourceIds: [
"gid://shopify/Metafield/123", ...
]) {
nodes {
resourceId
translatableContent {
key
value
}
}
}
}
Hope that helps!
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