Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
I am attempting to update a custom metafield for each product. We have tens of thousands of products and I was hoping to send the update metafield information using something like this:
https://MYSHOP/admin/products/7050337351.json
sending JSON as:
{
"product": {
"metafield": [{
"namespace": "custom_fields",
"key": "warehouse_location",
"value": "1234",
"value_type": "string"
}]
}
}
It seems I need to first capture the ID of each metafield previously created before I can update a metafield? Is that correct??? Given that we have tens of thousands of products do I first need to obtain every metafield ID of every product and store it locally before making a second API call to then update the metafield?
I was hoping to simply update the metafield using the product ID as the API would have enough information to process the update?
I note many other people on the forum have a similar issue.
Any help would be appreciated? Thank you for reading.
If you store to a metafield with the same namespace/key then it will rewrite what was previously set inside of that metafield.
Note that the metafields themselves have relativly large character limits, while the key and namespace are pretty locked down.
Key limit: 30 characters
Namespace limit: 20 characters
( https://help.shopify.com/api/reference/metafield )
Value limits: 65,535
( https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/maximum-characters-in-metafield-335323 )
The company I work for went down this route as well with indexing a large range of product information, and ended up writing a custom JSON array, storing it to the customer's assets folder in their theme then calling that with some liquid. Though once you get a number of products in there, it can get pretty large.
For anyone interested, managed to get this working (updating the metafield) by using the following:
{
"metafield": {
"namespace": "custom_fields",
"key": "warehouse_location",
"value": "2345",
"value_type": "string"
}
}
and using POST to:
https://MY-SHOP/admin/products/PRODUCT-CODE/metafields.json
Hope the information helps someone else.
That syntax gives a bad request error.
{
"errors": {
"metafield": "Required parameter missing or invalid"
}
}
Fabian - It would be worth seeing the complete data you are posting to the API call along with the url you are using you are posting to. If using a private API key be sure to remove both the key and password before posting.