Issue trying to create metafield for product

Reference:

https://shopify.dev/docs/admin-api/rest/reference/metafield

I am trying to add a metafield for a product by making a REST call using format:

POST [email removed]

with body:

{> “metafield”:> {> “namespace”: “resource”,> “value_type”: “string”,> “value”: “my custom value”,> “key”: “my_custom_key”,> “description”: “The description.”> }> }

But I receiving a response with status 400 like:

{> > “size”:0,> > “timeout”:0> > }

What am I doing wrong?

Hey @DSL

400 indicates a bad request. How are you sending the request? Is the Content-Type application/json?

Yes, content-type is set to application/json

Are you able to capture a request ID from the response headers?

Has a solution ever been provided? I too cannot create a metafield for a product using the admin api. I did the following:
URL: https://{API [email removed]
Action: Post
Body:

{
“metafield”: {
“namespace”: “global”,
“key”: “Test_Metafield”,
“value”: “Value for test metafield”,
“value_type”: “string”,
“description”: “This is the description”
}
}

When I try sending it I get a status 200 but with HTML as the response but no metafield was created for the product:

Continue

I even tried using basic authentication with the username set to my API key and the password with my API password and removed those values from the URL but I still get the same response in which no metafield gets created.

@robertjla - I’ve replied on your other thread.
https://community.shopify.com/c/Shopify-APIs-SDKs/Can-t-Perform-POST-using-REST-API-and-Basic-Authentication/m-p/891090