Post/put requests to add/update metafield on product using REST API do nothing and return no error

polel01
Visitor
1 0 0

I've seen answers to posts that sound similar.  They include having a metafield definition first (I do), doing a GET first to retrieve the the metafield id (which I have), but nothing is helping.  Every time I try a POST or a PUT, instead of receiving back a 201 Created, I'm receiving back a 200 OK, with the response body showing that no change has been made.

Here is my POST request:

POST url: https://sanduskybay.myshopify.com/admin/api/2024-04/products/8653986922809/metafields.json

Body payload:

{
    "metafield": {
            "namespace": "seo",
            "key": "keywords",
            "value": "[\"sandusky bay \"]",
            "type": "list.single_line_text_field",
            "admin_graphql_api_id": "gid://shopify/Metafield/37698712600889"
        }
}
I've tried many variations of the payload, such as "single_line_text_field" instead of "list.single_line_text_field" for type, "id": 37698712600889 instead of the admin_graphql_api_id, id along with admin_graphql_api_id, leaving out both id and admin_graphql_api_id, "sandusky bay " instead of "[\"sandusky bay \"]" for value, etc., etc.
Here is my PUT request:
Body payload:
{
    "metafield":
        {
            "id": 37698712600889,
            "namespace": "seo",
            "key": "keywords",
            "value": "[\"lake life, sandusky bay \"]",
            "description": null,
            "owner_id": 8803990667577,
            "created_at": "2024-05-23T09:25:07-04:00",
            "updated_at": "2024-05-23T09:25:07-04:00",
            "owner_resource": "product",
            "type": "list.single_line_text_field",
            "admin_graphql_api_id": "gid://shopify/Metafield/37698712600889"
        }
}
I'm using Postman just for simplicity of testing, but when running these in my C# code, I get the same results.
When I run the GET request, this is my return for the product which has a metafield added to it manually through the UI (product id 8803990667577):
Response:
{
    "metafields": [
        {
            "id": 37698712600889,
            "namespace": "seo",
            "key": "keywords",
            "value": "[\"lake life \"]",
            "description": null,
            "owner_id": 8803990667577,
            "created_at": "2024-05-23T09:25:07-04:00",
            "updated_at": "2024-05-23T09:25:07-04:00",
            "owner_resource": "product",
            "type": "list.single_line_text_field",
            "admin_graphql_api_id": "gid://shopify/Metafield/37698712600889"
        }
    ]
When I run the GET on the product which does not have any metafields with namespace "seo" yet (product id 8653986922809), I just get a blank array:
Request:
Response:
{
    "metafields": []
}
On all my request I'm including both the X-Shopify-Access-Token header with my access token and the Content-Type header with application/json as the value.
What am I doing wrong?  Thank you.
Replies 0 (0)