Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello,
I'm having a problem with the productUpdate API in graphQL.
I've created a metafield to enter the location of my product. (Namespace: "custom", key: "location");
I'm trying to do this via the shopify-graphiql-app test console. I don't get any errors, but nothing goes up on my product.
It's as if the API doesn't take my request into account.
I'm on the GraphQL 2024-04 API. Here's my code:
mutation updateProductMetafields($input: ProductInput!) { productUpdate(input: $input) { product { id metafields(first: 10) { edges { node { id namespace key value } } } } userErrors { message field } } }
Variables :
{ "input": { "id": "gid://shopify/Product/8865022411079", "metafields": [ { "id": "gid://shopify/Metafield/45831948927303", "type": "list.single_line_text_field", "value": "Castafiore" } ] } }
The id corresponds to my desired metafield. Here's an example, done by hand on a product and fetching the same product.
{ "node": { "id": "gid://shopify/Metafield/45831948927303", "namespace": "custom", "key": "emplacement", "value": "France" } }
I tested several things before asking you.
There's no problem with productCreate but productUpdate bug.
Any ideas?
Solved! Go to the solution
This is an accepted solution.
Hi @tonyricher,
As I see in variables, your metafield type is `list.single_line_text_field` but your value is `Castafiore` just a text. I think you should change type into `single_line_text_field` or remove it from variables because that field is optional when updating.
In case you want your metafield to be a list, and you are pushing more text into metafield, you need to modify the value from "France" to "[\"France\",\"Castafiore\"]"
Hope you can fix the issue soon.
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
This is an accepted solution.
Hi @tonyricher,
As I see in variables, your metafield type is `list.single_line_text_field` but your value is `Castafiore` just a text. I think you should change type into `single_line_text_field` or remove it from variables because that field is optional when updating.
In case you want your metafield to be a list, and you are pushing more text into metafield, you need to modify the value from "France" to "[\"France\",\"Castafiore\"]"
Hope you can fix the issue soon.
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
That was exactly my problem. I found the solution a few minutes later.
Thank you 🙂
const variables = {
input: {
id: product.id,
"metafields": [
{
"namespace": "custom",
"key": "emplacement",
"id": "gid://shopify/Metafield/45831948927303",
"type": "single_line_text_field",
"value": value
}
]
}
};
Glad to hear that. Finding out the solution by self is such a great feeling 😁
B2B Wholesale Solution: Streamline your B2B operation with advanced features like wholesale registration forms, custom pricing.
B2B Portal, Quote, Net 30: Speed up purchasing and streamline your quotation process with advanced features like quick order, request for quote.
B2B Lock Password Protect: Easily control access to pages, products, and pricing with robust features.
BSS Commerce - Full-service eCommerce Agency I Use Shopify for 1$ in the first month now
Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024