Create Matefield

Creates a new metafield for a specific resource.

This API is especially useful for:

  1. Adding custom metadata to various resources such as products, customers, or orders.
  2. Storing structured information (like text, images, or numbers) related to resources.
  3. Extending resource functionality for better customization.

Note: The operation is scoped to a specific shop, identified by its unique domain prefix (shopdomain), ensuring all updates are applied to the correct store.

Request Parameters

Public Request Parameters

📘

Public Request Parameters

Path Parameters

FieldTypeRequiredExampleDescription
resourcestringYesproductThe type of resource the metafield is attached to. Available values: shop, product, product_image, product_variant, order, page, customer, collection, blog, article.
resource_idstringNo1234567890The unique ID of the resource to which the metafield is attached.

Body Parameters

FieldTypeRequiredExampleDescription
definition_idstringYes374034306256875562The ID of the metafield definition.
namespacestringYescustomA container for grouping metafields to avoid conflicts with other metafields.
keystringYescolor_codeThe key for the metafield.
valuestringYes{"color": "#FFFFFF"}The data to store in the metafield
typestringYessingle_line_text_fieldThe type of data the metafield stores. Valid types: \n- date \n- date_time \n- weight \n- volume \n- dimension \n- integer \n- number_decimal \n- file_reference \n- single_line_text_field \n- multi_line_text_field \n- json \n- color \n- rating \n- url \n- boolean.
descriptionstringNoCustom field for colorA brief description of the metafield.

Response Explanation

Public Response Parameters

📘

Public Response Parameters

Successful Response

FieldTypeExampleDescription
metafieldobjectMetafield object containing all metafield details.
metafield.idstring374087540346466346Unique identifier for the metafield.
metafield.store_idinteger633130Store ID associated with the metafield.
metafield.created_atstring2024-04-28T06:52:36.101927450ZCreation timestamp in UTC.
metafield.updated_atstring2024-04-28T06:52:36.101927568ZLast update timestamp in UTC.
metafield.owner_resourcestringproductThe resource type the metafield is attached to.
metafield.owner_idstringa1a88be0-a1d4-47e4-a2f2-ba6e131cf447ID of the resource to which the metafield is attached.
metafield.namespacestringshirtNamespace to group the metafield.
metafield.keystringweight1Key to identify the metafield.
metafield.typestringweightType of data stored in the metafield.
metafield.valuestring10Value stored in the metafield.
metafield.descriptionstringweightBrief description of the metafield.
metafield.definition_idstring374087760941687850ID of the metafield definition used.

Error Response

Error responses in the API can be represented using two different fields: errors and error. Both fields provide details about issues encountered during request processing. Below is an explanation of the fields with their respective examples and descriptions.

FieldTypeExampleDescription
errorsarray["No metafield definition found"]A list of errors encountered during the request processing.
FieldTypeExampleDescription
errorString "store is not active"Indicates an error encountered during the process

Error Detail

Status CodeMessagePossible ReasonExample Response
UnauthorizedThe request is missing valid authentication credentials or the credentials provided are invalid.Unauthorized
400Bad RequestInvalid input format or request structure (e.g., missing required fields or incorrect data types).Bad Request
namespace is a required field
key is a required field
type is a required field
value is a required field
invalid own resources
invalid key value type

API Structure Overview

Language
Credentials
Header
URL
Click Try It! to start a request and see the response here!