AdminAPI/REST Reference - New type property in the metafields and other APIs

Solved
pmd85
Tourist
21 0 1

I read the changes in the new API version 2021-07. There is a change in the metafields(new type property). I tested it in the Metafields API and it works. But I can add metafields also in the others APIs and this change doesn't work there. APIs still require value_type property. 

This change does not affect other APIs?

 

If I send this request I get error 

{
"product": {
"title": "Burton Custom Freestyle 12",
"body_html": "<strong>Good snowboard!</strong>",
"vendor": "Burton",
"product_type": "Snowboard",
"metafields": [
{
"key": "new",
"value": 123458,
"namespace": "global",
"type": "number_integer"
 
}
]
}
}

 

Returned error

{
"errors": {
"value_type": [
"is not included in the list"
]
}
}
0 Likes
Dave_Pelletier
Shopify Staff
Shopify Staff
25 3 1

You are correct that the new type property is only available in 2021-07, the most recent version of the API. Older API versions are locked when they are released and do not change. If you use an older version of the API (before 2021-07) you need to use the value_type property.

0 Likes
pmd85
Tourist
21 0 1

Yo don't understand me.

I used latest API 2021-07. You can add metafields also directly when create/update products, orders, customers,...

 

Check example on this site https://shopify.dev/api/admin/rest/reference/products/product#create-2021-07

There is an example:

Create a product with a metafield

POST /admin/api/2021-07/products.json
{
  "product": {
    "title": "Burton Custom Freestyle 151",
    "body_html": "<strong>Good snowboard!</strong>",
    "vendor": "Burton",
    "product_type": "Snowboard",
    "metafields": [
      {
        "key": "new",
        "value": "newvalue",
        "value_type": "string",
        "namespace": "global"
      }
    ]
  }
}

My question is - what about these metafields(operations) and new type property?

 

Thanks 

0 Likes
Dave_Pelletier
Shopify Staff
Shopify Staff
25 3 1

This is an accepted solution.

Thanks for that clarification! I see what you mean now. You are correct that this is missing from the 2021-07 version for the products.json endpoint. If you'd like to use the new type system for Metafields that was released with 2021-07, you have two options:


1. Use the Metafield resource directly to set the Metafield values (e.g. /admin/api/2021-07/products/PRODUCT_ID/metafields.json)

2. Use the GraphQL Admin API which correctly includes the replacement of value_type with type wherever Metafields are used

I'll make sure that this gets corrected for the products.json endpoint for the 2021-10 Release Candidate version as soon as possible.

0 Likes