Solved

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

pmd85
Shopify Partner
23 0 2

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"
]
}
}
Accepted Solution (1)
Dave_Pelletier
Shopify Staff (Retired)
27 3 5

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.

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 3 (3)

Dave_Pelletier
Shopify Staff (Retired)
27 3 5

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.

To learn more visit the Shopify Help Center or the Community Blog.

pmd85
Shopify Partner
23 0 2

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 

Dave_Pelletier
Shopify Staff (Retired)
27 3 5

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.

To learn more visit the Shopify Help Center or the Community Blog.