Skip to main content

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:

FieldTypeRequiredDescription
fieldTypeStringYesType of record the metafield belongs to. See the list below.
labelStringYesDisplay label.
codeStringYesCode used to set and filter values. Must be unique for the field type.
valueTypeStringYesType of value. See the list below.
descriptionStringNoDescription of the metafield.
allowAdminUpdateBooleanNoWhether admins can edit the value. Default is false.
displayStorefrontBooleanNoWhether the value is shown on the storefront. Default is false.
displayAdminBooleanNoWhether the value is shown in the admin panel. Default is false.
displayFilterBooleanNoWhether the metafield is offered as a storefront filter. Default is false.
hasPredefinedValuesBooleanNoWhether values are chosen from a fixed list. Default is false.
predefinedValuesArrayNoList 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​

FieldTypeDescription
successBooleanWhether the request was successful.
messageStringConfirmation message.
dataObjectThe new metafield. See Metafield Data.

Notes​

  • The combination of code and fieldType must be unique.
  • To look up the ID of the new metafield, call Get All Metafields with code=<your code>.