I have encountered a problem while trying to add a pre-set metafield to a product via API in my store.
Below are the details of the issue:
-
Metafield Creation:
- I created a Product Metafield in my Shopify store.
- Metafield Type: Single Line Text Field
- Setting Enabled: Limit to Preset Choices
-
API Request:
-
I attempted to add this metafield to a product using the following API request:
jsonCopy code
{ “metafield”: { “namespace”: “custom”, “key”: “era”, “type”: “list.single_line_text_field”, “value”: [ “40s” ] } }
-
-
Error Response:
-
I received the following error response:
jsonCopy code
{ “errors”: { “value”: [ “can’t be blank.” ] } }
-
Here’s my request:
url -X POST “/admin/api/2023-10/products//metafields.json” -H “X-Shopify-Access-Token: ” -H “Content-Type: application/json” -d ‘{“metafield”: {“namespace”: “custom”,“key”: “Era”,“type”: “list.single_line_text_field”,“value”:[“40s”]}}’
I tried posting different type:
{
“errors”: {
“type”: [“‘single_line_text_field’ must be consistent with the definition’s type: ‘list.single_line_text_field’.”],
“value”: [" does not exist in provided choices: ["40s", "50s", "60s", "70s", "80s", "90s", "2000s"]."]
}
}