Conversations about creating, managing, and using metafields to store and retrieve custom data for apps and themes.
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.json
where {shop}
should be replaced by your shop name.
Check your request's headers. You should include Content-Type: application/json
and X-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.json
and 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}.json
with 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!
Liam | Developer Advocate @ Shopify
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
see this my request body and after hitting request i am getting those metafield which i created manually through custom data