Create Metafield
Creates a new metafield. Once it exists, you can set its value on records of the matching type. See Using Metafields on Other Resources.
HTTP Request
- URL:
/metafields - Method:
POST - Headers:
accessToken: Required. Your API access token.Content-Type:application/json
- Required scope: None. Any valid access token can call this endpoint.
Request Body
The request body is a JSON object with the following fields:
| Field | Type | Required | Description |
|---|---|---|---|
fieldType | String | Yes | Type of record the metafield belongs to. See the list below. |
label | String | Yes | Display label. |
code | String | Yes | Code used to set and filter values. Must be unique for the field type. |
valueType | String | Yes | Type of value. See the list below. |
description | String | No | Description of the metafield. |
allowAdminUpdate | Boolean | No | Whether admins can edit the value. Default is false. |
displayStorefront | Boolean | No | Whether the value is shown on the storefront. Default is false. |
displayAdmin | Boolean | No | Whether the value is shown in the admin panel. Default is false. |
displayFilter | Boolean | No | Whether the metafield is offered as a storefront filter. Default is false. |
hasPredefinedValues | Boolean | No | Whether values are chosen from a fixed list. Default is false. |
predefinedValues | Array | No | List of allowed values, as strings. |
Supported Field Types
customer, company, shippingAddress, billingAddress, category, product, variant, order, invoice, salesRep, shippingMethod
Supported Value Types
text, number, file, json, select, dateTime, boolean, product, multi-text, range, html-markdown, numberRange, category, company, customer, productFilter, salesRep
cURL Example
curl --location '<BASE_URL>/metafields' \
--header 'accessToken: <ACCESS_TOKEN>' \
--header 'Content-Type: application/json' \
--data '{
"fieldType": "product",
"label": "Material Type",
"code": "material_type",
"valueType": "select",
"displayStorefront": true,
"displayFilter": true,
"hasPredefinedValues": true,
"predefinedValues": ["Cotton", "Polyester", "Wool"]
}'
Response
- 200 OK: The metafield was created successfully.
- 400 Bad Request: A required field is missing, a value is not valid, or a metafield with the same code and field type already exists.
Sample JSON Response
{
"success": true,
"message": "Metafield created successfully",
"data": {
"fieldType": "product",
"label": "Material Type",
"code": "material_type",
"allowAdminUpdate": false,
"displayStorefront": true,
"displayAdmin": false,
"displayFilter": true,
"hasPredefinedValues": true,
"predefinedValues": ["Cotton", "Polyester", "Wool"],
"valueType": "select",
"createdAt": "2024-05-24T08:12:56.118Z",
"updatedAt": "2024-05-24T08:12:56.118Z"
}
}
Response Details
| Field | Type | Description |
|---|---|---|
success | Boolean | Whether the request was successful. |
message | String | Confirmation message. |
data | Object | The new metafield. See Metafield Data. |
Notes
- The combination of
codeandfieldTypemust be unique. - To look up the ID of the new metafield, call Get All Metafields with
code=<your code>.