-
Notifications
You must be signed in to change notification settings - Fork 476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when updating metafields on a product #813
Comments
This method worked for me, but uses extra API calls. Is there a way to make my original request work?
This isn't ideal, because in my full code (I only posted a snippet for clarity above), I'm updating other order properties such as the product title and product vendor, and it would be ideal to only have to hit the API at So I'm having to go from this:
to
Unless I'm missing something. |
Hi, @skillmatic-co! That sounds super frustrating. I'll take a look into this for you and see if I can find you a better solution. |
Something I did think of, if you're willing to delve into GraphQL, you may be able to use [this productUpdate mutation] (https://shopify.dev/docs/admin-api/graphql/reference/products-and-collections/productupdate) to update multiple metafields in a single request. This mutation accepts both |
Same problem for me, I can confirm the issue. And I use more of less the same workaround than skillmatic |
Unfortunately the REST API doesn't support the action of updating metafields through the Product resource, you're only able to create new ones. Let me know if there are any more questions! I'll be closing the issue for now since this isn't a shopify_api bug. |
Well, can it become a feature request? ;) |
Pass this suggestion along to to Partner Support! :) |
Shopify API should really support this. It takes extreme overhead to update a single entity. |
Agree, this should be supported. Facing the same issue for customers. |
I think I could solve it! First I got the id of the metafield like this:
Then with help of this reference: https://shopify.dev/api/admin-rest/2021-10/resources/metafield#put-metafields-metafield-id , I could update my customer's metafield.
I hope it helps! |
Hello guys. my name is Bernardo. There is a way to update the metafields without so many problems. I hope my example helps you. To update the metafield through the customer API it is necessary to pass the id of the metafield that will work. Enter in: Then just run this code snippet that updates the customer data: const body = {
customer: {
id,
first_name,
last_name,
phone,
metafields: [
{ id: 20263173128307, namespace: "my_fields", type: "date", key: "bithday", value: bithday }
],
}
}
try {
const response = await this.shopifyStore.put({
path: `/admin/api/2022-04/customers/${id}.json`,
data: body,
type: DataType.JSON
});
const customer = response.body;
console.log(customer);
} catch (error) {
throw new Error(error.message);
} |
You can use the Product API to update or create a metafield when you call {
product: {
metafields: [
{ id: 12345, value: "" }, // update a metafield
{ key: "", value: "", type: "single_line_text_field", namespace: "global" } // create a new metafield
]
}
} But after you save a product you don't get the metafields, so you need to call first |
I'm using GraphQL productUpdate mutation, facing the same issue, not being able to update the value of metafields, it says |
Once there is a namespace/key combination for a product, you need to send the ID of the metafield along with the changes. Otherwise, you will get the "Key must be unique within this namespace on this resource" error. The best is to store the metafield ID locally when you first create the product. |
If you are not updating other fields of the product then you can use metafieldsSet instead. Manage metafields section of the documentation doesn't even mention this mutation. |
When I try to do this:
I'm getting this error:
:key=>["must be unique within this namespace on this resource"]
This namespace/key already exists on this product, I'm just trying to update its value to "new value", but this error is preventing it. How do I do this?
#419 could be related.
The text was updated successfully, but these errors were encountered: