Issue trying to create metafield for product

Highlighted
Tourist
6 0 3

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 https://[KEY]:[PASS]@[SHOP_NAME].myshopify.com/admin/api/2020-04/products/[PRODUCT_ID}/metafields.json

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?

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

Hey @DSL 

 

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

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes
Highlighted
Tourist
6 0 3

Yes, content-type is set to application/json

0 Likes
Highlighted
Shopify Staff
Shopify Staff
1041 140 170

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

Notice; Out of office, replies will be delayed until my return. Thanks!
0 Likes
Highlighted
New Member
3 0 0

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 Key}:{Password}@{MyStore}.myshopify.com/admin/products/{product-id}/metafields.json
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:
 
<html>

<body>
    <noscript>
        <a
    </noscript>

    <script type="text/javascript" defer>
        window.location = "https:\/\/accounts.shopify.com\/oauth\/authorize?client_id=xxxxxxxxxxxxxxxxxxx\u0026destination_uuid=4xxxxxxxxxxxxxxxxxxxx\u0026nonce=xxxxxxxxxxxxxxxxxxx\u0026prompt=merge\u0026redirect_uri=https%3A%2F%2Fxxxxxxx.myshopify.com%2Fadmin%2Fauth%2Fidentity%2Fcallback\u0026response_type=code\u0026scope=email%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fdestinations.readonly%20openid%20profile%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fpartners.collaborator-relationships.readonly%20https%3A%2F%2Fapi.shopify.com%2Fauth%2Fbanking.manage\u0026state=xxxxxxxxxxxxxxxxx\u0026ui_locales=en\u0026ux=shop";
    </script>
</body>

</html>


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.

0 Likes
Highlighted
Shopify Expert
10006 116 1818

@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-Authen...

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
0 Likes