Please experts solve this problem, I am unable to create new metafield or update metafield through restapi in postman but i am able to get list. Although I can create metafield through inbuilt graphiql app. I am stuck on this since 2 days. Kindly solve this
Hi Jayeshsst,
From your explanation, it seems the problem is likely related to how you’re structuring your request in Postman. Follow the steps below to properly create a metafield using the REST API in Postman:
-
Make sure you’re using the correct HTTP method. For creating a metafield, you should be using POST.
-
Verify the URL endpoint you’re hitting. For creating a metafield, the URL should be
https://{shop}.myshopify.com/admin/api/2022-01/metafields.jsonwhere{shop}should be replaced by your shop name. -
Check your request’s headers. You should include
Content-Type: application/jsonandX-Shopify-Access-Token: {your-access-token} -
Ensure your request body is properly structured. For example:
{
"metafield": {
"namespace": "inventory",
"key": "warehouse",
"value": 25,
"value_type": "integer"
}
}
-
If you’re trying to create a metafield for a specific product, you should be hitting the endpoint
https://{shop}.myshopify.com/admin/api/2022-01/products/{product_id}/metafields.jsonand the request body should look like the above. -
For updating a metafield, use the endpoint
https://{shop}.myshopify.com/admin/api/2022-01/metafields/{metafield_id}.jsonwith the PUT method, and your request body should look like this:
{
"metafield": {
"id": 721389482,
"value": 30,
"value_type": "integer"
}
}
If you’re still experiencing issues, try testing creating a new metafield outside of postman (ie with an API call as shown in our docs. This might indicate that there’s an issue within Postman, for example is auth is not set up correctly.
Hope this helps!
