Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
I am encountering an issue while using GraphQL to create and assign metafields to products in my Shopify store. Specifically, the problem arises when I attempt to assign a list of metafields of the type 'single_line_text_field'.
Here's a brief overview of the situation:
1. Issue Description:
2. GraphQL Query Used:
I am attaching the exact GraphQL query I used for this operation. Note that I am using the "list." + "single_line_text_field" as explained in the documentation
shopify.GraphQL().execute(
query="mutation metafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
key,
namespace,
value
}
userErrors {
field
message
}
}
}",
variables={
"metafields": [
{
{
"key": "gender",
"namespace": "XXXXX",
"ownerId": "gid://shopify/Product/XXXXXXXXXXXXX",
"type": "list.single_line_text_field",
"value": "[\\"Female\\", \\"Male\\"]"
}
}
]
}
)
3. API Response Received:
The response from the API was as follows:
{
"data": {
"metafieldsSet": {
"metafields": [
{
"key": "gender",
"namespace": "XXXXXX",
"value": "[\"Female\",\"Male\"]"
}
],
"userErrors": []
}
},
"extensions": {
"cost": {
"requestedQueryCost": 10,
"actualQueryCost": 10,
"throttleStatus": {
"maximumAvailable": 1000.0,
"currentlyAvailable": 990,
"restoreRate": 50.0
}
}
}
}
4. Shopify backoffice
The metafiled definition is created but there is no values inside,
Is this issue a bug in the API, or am I not using the API properly?
Thanks in advanced
Solved! Go to the solution
This is an accepted solution.
Después de 2 días se solucionó el problema. Puedo pensar que mis llamadas iniciales generaron algun tipo de métrica interna que el equipo de Shopify solucionó rápidamente, ya que el problema ha desaparecido haciendo exactamente la misma batería de tests por mi parte. Marco el issue como solucionado.
Hi Stock23,
If you navigate to the product that you're looking to add a metafield value for on the admin, are you seeing the value that you are passing through the mutation appearing? (You should see it on the bottom of the product page, rather than on the metafield setting page).
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 Liam,
I don't see it because it is not pinned, that's why I took the screenshot from the setting page. Do you think that pinning a metafield could affect on that?
Thanks for the support!
Do you see it if you click on "Show all" on the product page > metafields section?
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
Yes, I see there the metafield "Gender", but without values. The screenshots above of the point 4 show exactly this section (with spanish interface).
This is an accepted solution.
Después de 2 días se solucionó el problema. Puedo pensar que mis llamadas iniciales generaron algun tipo de métrica interna que el equipo de Shopify solucionó rápidamente, ya que el problema ha desaparecido haciendo exactamente la misma batería de tests por mi parte. Marco el issue como solucionado.
I am experiencing the same issue as described. The solution seems to indicate that this was fixed internally by shopify, but it seems it may not have been. Would appreciate any guidance or support. @Liam