REST API adding metafields to products

Topic summary

Issue: When adding a product metafield via Shopify REST API (POST to /admin/api/2024-01/products/1234567890/metafields.json), the response is always 201 Created, even if a matching metafield already exists.

Context: Metafields are custom fields attached to products. The user expected a duplicate to trigger an error, not a create response.

Key question: Is this behavior by design (i.e., does POST replace an existing metafield), or should the API reject duplicates?

Status: No resolution or guidance provided yet; the poster is seeking clarification on expected behavior and duplication handling.

Summarized with AI on January 3. AI used: gpt-5.

I’ve noticed some unexpected behavior when adding a metafield to a product using the metafields REST API.

I’m making a POST to the following url: …/admin/api/2024-01/products/1234567890/metafields.json

I’m receiving a create (201) status code for each call, even if there is an existing matching metafield assigned to the product. I’d assumed I would receive an error if I attempted to add a metafield that existed. Is this by design, i.e. if you try to add an existing metafield it replaces the pre-existing?

Thanks