Unable to create metafield through restapi or postman

Unable to create metafield through restapi or postman

jayeshsst
Visitor
3 0 0

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

Replies 2 (2)

Liam
Shopify Staff
2873 312 821

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:

  1. Make sure you're using the correct HTTP method. For creating a metafield, you should be using POST.

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

  3. Check your request's headers. You should include Content-Type: application/json and X-Shopify-Access-Token: {your-access-token}

  4. Ensure your request body is properly structured. For example:

{
  "metafield": {
    "namespace": "inventory",
    "key": "warehouse",
    "value": 25,
    "value_type": "integer"
  }
}
  1. 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.

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

jayeshsst
Visitor
3 0 0

Screenshot 2023-08-28 142916.jpg

see this my request body and after hitting request i am getting those metafield which i created manually through custom data