Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

Re: PUT on Metafield for Order error

Solved

PUT on Metafield for Order error

DeonSmit
Shopify Partner
15 1 5

Hi

 

I have created a metafield on my orders. but following the documentation on the API call 

 

https://shopify.dev/docs/api/admin-rest/2023-01/resources/metafield#put-blogs-blog-id-metafields-met...

 

Order id 

4969826058433

Metafield ID

2337276097

PUT Done to 

 

 

https://DEVSTORE.myshopify.com/admin/api/2023-01/orders/4969826058433/metafields/2337276097.json

 

 

 

 

Body Of Postman

 

{
   "metafield":{
      "id":2337276097,
      "value":"Ready for Collection",
      "type":"single_line_text_field"
   }
}

Error

 

{
    "errors": "Not Found"
}

 

 

Accepted Solution (1)
DeonSmit
Shopify Partner
15 1 5

This is an accepted solution.

I am Updating a Metafield. I see that each orders Metafield has an Unique id that is generated. That was my issue. Got is resolved.

 

I see your call is to create one. PUT method to update once it is populated

 

Managed to get it working in Rest API. 

Just Migrated to GraphQL which I can use and update multiple Metafields at the same time.

 

For anybody reading this.  It is not the Metafield ID where you create the Metafield. Also if a Metafield value don't exit you have to first create it via API in that order. 

To test get the Metafield ID generated here is your admin portal If the order has Metafield data populated. To get it via API you have to query the orders metafields to get the ID. 

/orders/{orderid}/metafields.json

View solution in original post

Replies 2 (2)

Liam
Community Manager
3108 342 884

Hi DeonSmit,

 

Just to confirm are you creating or updating an existing metafield? Could you try the same API call but with curl to rule out some issue on Postmans side, eg:

 

curl -d '{"metafield":{"namespace":"my_fields","key":"purchase_order","type":"single_line_text_field","value":"Ready for Collection"}}' \
-X POST "https://your-development-store.myshopify.com/admin/api/2023-01/orders/4969826058433/metafields.json" \
-H "X-Shopify-Access-Token: {access_token}" \
-H "Content-Type: application/json"

 

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

DeonSmit
Shopify Partner
15 1 5

This is an accepted solution.

I am Updating a Metafield. I see that each orders Metafield has an Unique id that is generated. That was my issue. Got is resolved.

 

I see your call is to create one. PUT method to update once it is populated

 

Managed to get it working in Rest API. 

Just Migrated to GraphQL which I can use and update multiple Metafields at the same time.

 

For anybody reading this.  It is not the Metafield ID where you create the Metafield. Also if a Metafield value don't exit you have to first create it via API in that order. 

To test get the Metafield ID generated here is your admin portal If the order has Metafield data populated. To get it via API you have to query the orders metafields to get the ID. 

/orders/{orderid}/metafields.json