PUT on Metafield for Order error

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-metafield-id

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"
}

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"

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