Issue trying to create metafield for product

DSL
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
SBD_
Shopify Staff
Shopify Staff
1071 143 189

Hey @DSL 

 

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

0 Likes
DSL
Tourist
6 0 3

Yes, content-type is set to application/json

0 Likes
SBD_
Shopify Staff
Shopify Staff
1071 143 189

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

0 Likes
robertjla
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
Jason
Shopify Expert
10260 142 1940

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

I jump on these forums to help and share some insights. Not looking to be hired, and not looking for work.

Don't hand out staff invites or give admin password to forum members unless absolutely needed. In most cases the help you need can be handled without that.


★ http://freakdesign.com.au ★
0 Likes