API - Metafields - Update when Inserting

Good morning,

Regarding the API handling of metafields for the following: POST /admin/api/2021-04/metafields.json

If we were to send, the following initially to create a metafield:

“metafield”: {
“namespace”: “accentuate”,
“key”: “players”,
“value”: 2,
“value_type”: “integer”
}

If we were then to send the following at a later date:

“metafield”: {
“namespace”: “accentuate”,
“key”: “players”,
“value”: 4,
“value_type”: “integer”
}

Would this key then be updated to a value of 4? Or instead would it be rejected as a failure?

Many thanks for your assistance!

Hi @Asmodee

Hope you’re having a great day!

As specified by Shopify:

Metafields have four components: namespace, key, value, and description (optional). Namespaces will be used to group different metafields, keys will be used to reference our information, and values will contain our unique content. We can also specify if the value is a string or integer.

Would this key then be updated to a value of 4?

Yes. The value (in the same namespace and with the specified key) will be updated.

Useful resources:

Using Metafields in Your Shopify Theme

If you found this comment useful, hit the ‘Like’ and ‘Accepted solution’ buttons.