Solved

Shopify admin APIs PUT and POST URLs not working with postman

Jitendrap_87
Shopify Partner
9 0 0

Hi,

 

I am trying to create & update product metafields using shopify admin APIs using postman but the apis not creating and updating the results in postman. 

if i am trying the same thing with code script using cURL it is working fine there.

 

I am using X-Shopify-Access-Token in Header of postman POST and PUT request and there is no cookies sending in the request as well.

 

Please check the attahced screenshot for the request i am trying with postman.

 

 

Accepted Solution (1)

Zameer
Shopify Staff
297 31 90

This is an accepted solution.

Hey there,

 

I was able to dig up both your cURL and Postman requests in our logs, and it seems that the issue is that the nested values you are passing in for the value parameter are not being parsed correctly.

 

Specifically, the value parameter of the metafield key is being joined with the value of the id you're passing in as a nested array for the value key. ie: we're seeing "value_24638787485796_h" as the key and not just "value" and therefore you are receiving a 422 error because the required "value" property is not present in the metafield body.

 

In order to avoid this error for Postman requests, you will have to ensure that the nested array you are passing in for the value is a string (which means all other quotation marks within this string are escaped). During my own testing, I've also found that the presence of newline characters will also cause the value to not be parsed as a string within Postman. You should therefore try to leave the entire value on a single line, without spaces (an odd issue within Postman/Insomnia, but something to be aware of none the less). 

 

Making these changes should allow you to successfully make the request to create new metafields on the product.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 3 (3)

Zameer
Shopify Staff
297 31 90

This is an accepted solution.

Hey there,

 

I was able to dig up both your cURL and Postman requests in our logs, and it seems that the issue is that the nested values you are passing in for the value parameter are not being parsed correctly.

 

Specifically, the value parameter of the metafield key is being joined with the value of the id you're passing in as a nested array for the value key. ie: we're seeing "value_24638787485796_h" as the key and not just "value" and therefore you are receiving a 422 error because the required "value" property is not present in the metafield body.

 

In order to avoid this error for Postman requests, you will have to ensure that the nested array you are passing in for the value is a string (which means all other quotation marks within this string are escaped). During my own testing, I've also found that the presence of newline characters will also cause the value to not be parsed as a string within Postman. You should therefore try to leave the entire value on a single line, without spaces (an odd issue within Postman/Insomnia, but something to be aware of none the less). 

 

Making these changes should allow you to successfully make the request to create new metafields on the product.

To learn more visit the Shopify Help Center or the Community Blog.

Jitendrap_87
Shopify Partner
9 0 0

Thanks Zameer,

 

I have checked the value parameter which is a nested array and corrected the format in a proper string (i.e. quotation marks within this string are escaped) and now the request is successfully made and update the metafields on the product.

 

Below is the attached request in which the value parameter is being parsed correctly.

 

Thanks for the reply.

sachin16
New Member
7 0 0

Hi,

 

I have a metafield on Shop resource which I am trying to update using Postman. the field type is Integer and I am making the request as below however I am not able to do it and getting the 404 error.

I have retrieved the metafield as - 

{
    "metafields": [
        {
            "id"12305803870293,
            "namespace""global",
            "key""custom-shipping-rate",
            "value"0,
            "value_type""integer",
            "description""source",
            "owner_id"27170275413,
            "created_at""2020-05-15T03:08:40-04:00",
            "updated_at""2020-05-15T03:08:40-04:00",
            "owner_resource""shop",
            "admin_graphql_api_id""gid://shopify/Metafield/12305803870293"
        }
    ]
}
 
Put request body
{
"metafield": {
"id": 12305803870293,
"value": 10,
"value_type": "integer"
}
}
Capture.PNG