# Metafield

Metafields are a flexible way to attach additional information to a Shopify resource (e.g. Product, Collection, etc.). Some examples of data stored using metafields include specifications, size charts, downloadable documents, release dates, images, or part numbers. Metafields are identified by an owner resource, a namespace, and a key and they store a value along with type information for that context.

Resources that can have metafields

## Resource Properties ### Metafield * created_at: The date and time (ISO 8601 format) when the metafield was created. * Type: x-string * Example: "2012-03-13T16:09:54-04:00" * description: The description of the metafield. * Type: x-string * Example: "The number of units at the warehouse." * id: The unique ID of the metafield.
Required when updating a metafield, but should not be included when creating as it's created automatically. * Type: x-string * Example: 915396206 * key: The unique identifier for a metafield within its namespace.
Must be 3-64 characters long and can contain alphanumeric, hyphen, and underscore characters. * Type: x-string * Example: "warehouse" * namespace: The container for a group of metafields that the metafield is or will be associated with. Used in tandem with `key` to lookup a metafield on a resource, preventing conflicts with other metafields with the same `key`.
Must be 3-255 characters long and can contain alphanumeric, hyphen, and underscore characters. * Type: x-string * Example: "inventory" * owner_id: The unique ID of the resource that the metafield is attached to. * Type: x-string * Example: 548380009 * owner_resource: The type of resource that the metafield is attached to. * Type: x-string * Example: "product" * updated_at: The date and time (ISO 8601 format) when the metafield was last updated. * Type: x-string * Example: "2012-08-24T14:02:15-04:00" * value: The data stored in the metafield. Always stored as a string, regardless of the metafield's type. * Type: x-string * Example: "25" * type: The type of data that is stored in the metafield. Refer to the list of supported types. * Type: x-string * Example: "single_line_text_field" ## Retrieve a list of metafields from the resource's endpoint Retrieves a list of metafields attached to a particular resource by using the resource's endpoint. ### Endpoint /admin/api/#{api_version}/blogs/{blog_id}/metafields.json (GET) ### Parameters * api_version (required): * blog_id (required): * created_at_max: Show metafields created before date (format: 2022-02-25T16:15:47-04:00) * created_at_min: Show metafields created after date (format: 2022-02-25T16:15:47-04:00) * fields: Retrieve only certain fields, specified by a comma-separated list of fields names. * key: Show metafields with given key * limit: The maximum number of results to show on a page. * namespace: Show metafields with given namespace * since_id: Show metafields created after the specified ID. * type: The type of data that the metafield stores in the `value` field. Refer to the list of supported types. * updated_at_max: Show metafields last updated before date (format: 2022-02-25T16:15:47-04:00) * updated_at_min: Show metafields last updated after date (format: 2022-02-25T16:15:47-04:00) ### Responses #### 200 Retrieve a list of metafields from the resource's endpoint Examples: ##### Retrieve metafields attached to a Blog Request: ``` GET /admin/api/unstable/blogs/382285388/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":1069228941,"namespace":"my_fields","key":"sponsor","value":"Shopify","description":null,"owner_id":382285388,"created_at":"2024-09-26T15:28:18-04:00","updated_at":"2024-09-26T15:28:18-04:00","owner_resource":"blog","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228941"}]} ``` ##### Retrieve metafields attached to a Collection Request: ``` GET /admin/api/unstable/collections/482865238/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":519046726,"namespace":"notes","key":"descriptionription","value":"Collection description","description":"Custom Collection notes","owner_id":482865238,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"collection","type":"string","admin_graphql_api_id":"gid://shopify/Metafield/519046726"},{"id":624849518,"namespace":"global","key":"description_tag","value":"Some seo description value","description":null,"owner_id":482865238,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"collection","type":"string","admin_graphql_api_id":"gid://shopify/Metafield/624849518"},{"id":1010236510,"namespace":"global","key":"title_tag","value":"Some seo title value","description":null,"owner_id":482865238,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"collection","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1010236510"},{"id":1069228938,"namespace":"my_fields","key":"discount","value":"25%","description":null,"owner_id":482865238,"created_at":"2024-09-26T15:28:08-04:00","updated_at":"2024-09-26T15:28:08-04:00","owner_resource":"collection","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228938"}]} ``` ##### Retrieve metafields attached to a Customer Request: ``` GET /admin/api/unstable/customers/207119551/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":220591908,"namespace":"discounts","key":"returning_customer","value":"no","description":"Customer deserves discount","owner_id":207119551,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"customer","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/220591908"},{"id":1069228944,"namespace":"discounts","key":"special","value":"yes","description":null,"owner_id":207119551,"created_at":"2024-09-26T15:28:25-04:00","updated_at":"2024-09-26T15:28:25-04:00","owner_resource":"customer","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228944"}]} ``` ##### Retrieve metafields attached to a Draft Order Request: ``` GET /admin/api/unstable/draft_orders/622762746/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":106172460,"namespace":"notes","key":"note","value":"B flat","description":"This is for notes","owner_id":622762746,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"draft_order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/106172460"},{"id":1069228946,"namespace":"my_fields","key":"purchase_order","value":"97453","description":null,"owner_id":622762746,"created_at":"2024-09-26T15:28:29-04:00","updated_at":"2024-09-26T15:28:29-04:00","owner_resource":"draft_order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228946"}]} ``` ##### Retrieve metafields attached to a Page Request: ``` GET /admin/api/unstable/pages/131092082/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":290519330,"namespace":"translation","key":"title_fr","value":"Le TOS","description":"Page French title translation","owner_id":131092082,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"page","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/290519330"},{"id":1069228947,"namespace":"my_fields","key":"subtitle","value":"A subtitle for my page","description":null,"owner_id":131092082,"created_at":"2024-09-26T15:28:29-04:00","updated_at":"2024-09-26T15:28:29-04:00","owner_resource":"page","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228947"}]} ``` ##### Retrieve metafields attached to a Product Request: ``` GET /admin/api/unstable/products/632910392/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":51714266,"namespace":"my_namespace","key":"my_key","value":"Hello","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/51714266"},{"id":116539875,"namespace":"descriptors","key":"subtitle","value":"The best ipod","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/116539875"},{"id":263497237,"namespace":"installments","key":"disable","value":true,"description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"boolean","admin_graphql_api_id":"gid://shopify/Metafield/263497237"},{"id":273160493,"namespace":"facts","key":"isbn","value":"978-0-14-004259-7","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/273160493"},{"id":524118066,"namespace":"facts","key":"ean","value":"0123456789012","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/524118066"},{"id":543636738,"namespace":"reviews","key":"rating_count","value":1,"description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"number_integer","admin_graphql_api_id":"gid://shopify/Metafield/543636738"},{"id":572384404,"namespace":"reviews","key":"rating","value":"{\"value\": \"3.5\", \"scale_min\": \"1.0\", \"scale_max\": \"5.0\"}","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"rating","admin_graphql_api_id":"gid://shopify/Metafield/572384404"},{"id":613330208,"namespace":"shopify_filter","key":"display","value":"retina","description":"This field keeps track of the type of display","owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"string","admin_graphql_api_id":"gid://shopify/Metafield/613330208"},{"id":779326701,"namespace":"facts","key":"upc","value":"012345678901","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/779326701"},{"id":845366454,"namespace":"translations","key":"title_fr","value":"produit","description":"French product title","owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"string","admin_graphql_api_id":"gid://shopify/Metafield/845366454"},{"id":861799889,"namespace":"my_other_fields","key":"organic","value":true,"description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"boolean","admin_graphql_api_id":"gid://shopify/Metafield/861799889"},{"id":870326793,"namespace":"descriptors","key":"care_guide","value":"Wash in cold water","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":null,"admin_graphql_api_id":"gid://shopify/Metafield/870326793"},{"id":908250163,"namespace":"my_other_fields","key":"shipping_policy","value":"Ships for free in Canada","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"multi_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/908250163"},{"id":925288667,"namespace":"my_other_fields","key":"year_released","value":2019,"description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"number_integer","admin_graphql_api_id":"gid://shopify/Metafield/925288667"},{"id":1001077698,"namespace":"my_fields","key":"best_for","value":"travel","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1001077698"},{"id":1029402048,"namespace":"my_other_fields","key":"ingredients","value":"[\"apple\", \"music\", \"u2\"]","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"list.single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1029402048"},{"id":1069228955,"namespace":"inventory","key":"warehouse","value":25,"description":null,"owner_id":632910392,"created_at":"2024-09-26T15:28:54-04:00","updated_at":"2024-09-26T15:28:54-04:00","owner_resource":"product","type":"number_integer","admin_graphql_api_id":"gid://shopify/Metafield/1069228955"}]} ``` ##### Retrieve metafields attached to a Product Image Request: ``` GET /admin/api/unstable/product_images/850703190/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":625663657,"namespace":"translation","key":"title_fr","value":"tbn","description":"French product image title","owner_id":498048120,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"media_image","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/625663657"},{"id":1069228936,"namespace":"translation","key":"title_spanish","value":"botas","description":null,"owner_id":498048120,"created_at":"2024-09-26T15:28:06-04:00","updated_at":"2024-09-26T15:28:06-04:00","owner_resource":"media_image","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228936"}]} ``` ##### Retrieve metafields attached to a Product Variant Request: ``` GET /admin/api/unstable/variants/49148385/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":1069228942,"namespace":"my_fields","key":"liner_material","value":"synthetic leather","description":null,"owner_id":49148385,"created_at":"2024-09-26T15:28:21-04:00","updated_at":"2024-09-26T15:28:21-04:00","owner_resource":"variant","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228942"}]} ``` ##### Retrieve metafields attached to an Article Request: ``` GET /admin/api/unstable/articles/674387490/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":1069228945,"namespace":"my_fields","key":"category","value":"outdoors","description":null,"owner_id":674387490,"created_at":"2024-09-26T15:28:28-04:00","updated_at":"2024-09-26T15:28:28-04:00","owner_resource":"article","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228945"}]} ``` ##### Retrieve metafields attached to an Order Request: ``` GET /admin/api/unstable/orders/450789469/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":915396079,"namespace":"notes","key":"buyer","value":"Notes about this buyer","description":"This field is for buyer notes","owner_id":450789469,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/915396079"},{"id":1069228935,"namespace":"my_fields","key":"purchase_order","value":"123","description":null,"owner_id":450789469,"created_at":"2024-09-26T15:28:05-04:00","updated_at":"2024-09-26T15:28:05-04:00","owner_resource":"order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228935"}]} ``` ##### Retrieve metafields attached to the Shop Request: ``` GET /admin/api/unstable/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":721389482,"namespace":"affiliates","key":"app_key","value":"app_key","description":null,"owner_id":548380009,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"shop","type":"string","admin_graphql_api_id":"gid://shopify/Metafield/721389482"}]} ``` ##### Retrieve metafields attached to the Shop after the specified ID Request: ``` GET /admin/api/unstable/metafields.json ``` Response: ``` HTTP/1.1 200 OK {"metafields":[{"id":1069228953,"namespace":"my_fields","key":"my_items","value":"{\"items\":[\"some item\"]}","description":null,"owner_id":548380009,"created_at":"2024-09-26T15:28:51-04:00","updated_at":"2024-09-26T15:28:51-04:00","owner_resource":"shop","type":"json","admin_graphql_api_id":"gid://shopify/Metafield/1069228953"}]} ``` ## Create a metafield You can create any number of metafields for a resource. To create metafields, use the corresponding resource's endpoint as listed on the examples. ### Endpoint /admin/api/#{api_version}/blogs/{blog_id}/metafields.json (POST) ### Parameters * api_version (required): * blog_id (required): ### Responses #### 201 Create a metafield Examples: ##### Create a metafield for a blog Request: ``` POST /admin/api/unstable/blogs/382285388/metafields.json {"metafield":{"namespace":"my_fields","key":"sponsor","type":"single_line_text_field","value":"Shopify"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228950,"namespace":"my_fields","key":"sponsor","value":"Shopify","description":null,"owner_id":382285388,"created_at":"2024-09-26T15:28:36-04:00","updated_at":"2024-09-26T15:28:36-04:00","owner_resource":"blog","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228950"}} ``` ##### Create a metafield for a collection Request: ``` POST /admin/api/unstable/collections/482865238/metafields.json {"metafield":{"namespace":"my_fields","key":"discount","type":"single_line_text_field","value":"25%"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228951,"namespace":"my_fields","key":"discount","value":"25%","description":null,"owner_id":482865238,"created_at":"2024-09-26T15:28:40-04:00","updated_at":"2024-09-26T15:28:40-04:00","owner_resource":"collection","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228951"}} ``` ##### Create a metafield for a customer Request: ``` POST /admin/api/unstable/customers/207119551/metafields.json {"metafield":{"namespace":"discounts","key":"special","value":"yes","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228949,"namespace":"discounts","key":"special","value":"yes","description":null,"owner_id":207119551,"created_at":"2024-09-26T15:28:31-04:00","updated_at":"2024-09-26T15:28:31-04:00","owner_resource":"customer","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228949"}} ``` ##### Create a metafield for a draft order Request: ``` POST /admin/api/unstable/draft_orders/622762746/metafields.json {"metafield":{"namespace":"my_fields","key":"purchase_order","type":"single_line_text_field","value":"97453"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228933,"namespace":"my_fields","key":"purchase_order","value":"97453","description":null,"owner_id":622762746,"created_at":"2024-09-26T15:28:04-04:00","updated_at":"2024-09-26T15:28:04-04:00","owner_resource":"draft_order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228933"}} ``` ##### Create a metafield for a page Request: ``` POST /admin/api/unstable/pages/131092082/metafields.json {"metafield":{"namespace":"my_fields","key":"subtitle","type":"single_line_text_field","value":"A subtitle for my page"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228934,"namespace":"my_fields","key":"subtitle","value":"A subtitle for my page","description":null,"owner_id":131092082,"created_at":"2024-09-26T15:28:05-04:00","updated_at":"2024-09-26T15:28:05-04:00","owner_resource":"page","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228934"}} ``` ##### Create a metafield for a product Request: ``` POST /admin/api/unstable/products/632910392/metafields.json {"metafield":{"namespace":"inventory","key":"warehouse","value":25,"type":"number_integer"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228948,"namespace":"inventory","key":"warehouse","value":25,"description":null,"owner_id":632910392,"created_at":"2024-09-26T15:28:30-04:00","updated_at":"2024-09-26T15:28:30-04:00","owner_resource":"product","type":"number_integer","admin_graphql_api_id":"gid://shopify/Metafield/1069228948"}} ``` ##### Create a metafield for a product image Request: ``` POST /admin/api/unstable/product_images/850703190/metafields.json {"metafield":{"namespace":"translation","key":"title_spanish","type":"single_line_text_field","value":"botas"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228954,"namespace":"translation","key":"title_spanish","value":"botas","description":null,"owner_id":850703190,"created_at":"2024-09-26T15:28:53-04:00","updated_at":"2024-09-26T15:28:53-04:00","owner_resource":"product_image","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228954"}} ``` ##### Create a metafield for a product variant Request: ``` POST /admin/api/unstable/variants/49148385/metafields.json {"metafield":{"namespace":"my_fields","key":"liner_material","type":"single_line_text_field","value":"synthetic leather"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228943,"namespace":"my_fields","key":"liner_material","value":"synthetic leather","description":null,"owner_id":49148385,"created_at":"2024-09-26T15:28:25-04:00","updated_at":"2024-09-26T15:28:25-04:00","owner_resource":"variant","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228943"}} ``` ##### Create a metafield for an article Request: ``` POST /admin/api/unstable/articles/674387490/metafields.json {"metafield":{"namespace":"my_fields","key":"category","type":"single_line_text_field","value":"outdoors"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228952,"namespace":"my_fields","key":"category","value":"outdoors","description":null,"owner_id":674387490,"created_at":"2024-09-26T15:28:43-04:00","updated_at":"2024-09-26T15:28:43-04:00","owner_resource":"article","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228952"}} ``` ##### Create a metafield for an order Request: ``` POST /admin/api/unstable/orders/450789469/metafields.json {"metafield":{"namespace":"my_fields","key":"purchase_order","type":"single_line_text_field","value":"123"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228939,"namespace":"my_fields","key":"purchase_order","value":"123","description":null,"owner_id":450789469,"created_at":"2024-09-26T15:28:15-04:00","updated_at":"2024-09-26T15:28:15-04:00","owner_resource":"order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1069228939"}} ``` ##### Create a metafield for the Shop resource Request: ``` POST /admin/api/unstable/metafields.json {"metafield":{"namespace":"my_fields","key":"my_items","value":"{\"items\":[\"some item\"]}","type":"json"}} ``` Response: ``` HTTP/1.1 201 Created {"metafield":{"id":1069228937,"namespace":"my_fields","key":"my_items","value":"{\"items\":[\"some item\"]}","description":null,"owner_id":548380009,"created_at":"2024-09-26T15:28:07-04:00","updated_at":"2024-09-26T15:28:07-04:00","owner_resource":"shop","type":"json","admin_graphql_api_id":"gid://shopify/Metafield/1069228937"}} ``` #### 422 Create a metafield Examples: ##### Creating a metafield without a key will fail and return an error Request: ``` POST /admin/api/unstable/metafields.json {"metafield":{"key":null}} ``` Response: ``` HTTP/1.1 422 Unprocessable Entity {"errors":{"type":["can't be blank"],"namespace":["can't be blank","is too short (minimum is 3 characters)"],"key":["can't be blank","is too short (minimum is 3 characters)"]}} ``` ## Retrieve a count of a resource's metafields. Get a count of all metafields that belong to a particular resource. ### Endpoint /admin/api/#{api_version}/blogs/{blog_id}/metafields/count.json (GET) ### Parameters * api_version (required): * blog_id (required): ### Responses #### 200 Retrieve a count of a resource's metafields. Examples: ##### Retrieve a count of metafields attached to a Blog Request: ``` GET /admin/api/unstable/blogs/382285388/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":0} ``` ##### Retrieve a count of metafields attached to a Collection Request: ``` GET /admin/api/unstable/collections/482865238/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":3} ``` ##### Retrieve a count of metafields attached to a Customer Request: ``` GET /admin/api/unstable/customers/207119551/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":1} ``` ##### Retrieve a count of metafields attached to a Draft Order Request: ``` GET /admin/api/unstable/draft_orders/622762746/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":1} ``` ##### Retrieve a count of metafields attached to a Page Request: ``` GET /admin/api/unstable/pages/131092082/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":1} ``` ##### Retrieve a count of metafields attached to a Product Request: ``` GET /admin/api/unstable/products/632910392/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":16} ``` ##### Retrieve a count of metafields attached to a Product Image Request: ``` GET /admin/api/unstable/product_images/850703190/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":1} ``` ##### Retrieve a count of metafields attached to a Product Variant Request: ``` GET /admin/api/unstable/variants/49148385/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":0} ``` ##### Retrieve a count of metafields attached to an Article Request: ``` GET /admin/api/unstable/articles/674387490/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":0} ``` ##### Retrieve a count of metafields attached to an Order Request: ``` GET /admin/api/unstable/orders/450789469/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":1} ``` ##### Retrieve a count of metafields attached to the Shop resource Request: ``` GET /admin/api/unstable/metafields/count.json ``` Response: ``` HTTP/1.1 200 OK {"count":1} ``` ## Retrieve a specific metafield Retrieve a metafield by specifying the ID. All fields of a metafield are returned unless specific fields are named. ### Endpoint /admin/api/#{api_version}/blogs/{blog_id}/metafields/{metafield_id}.json (GET) ### Parameters * api_version (required): * blog_id (required): * metafield_id (required): * fields: Retrieve only certain fields, specified by a comma-separated list of fields names. ### Responses #### 200 Retrieve a specific metafield Examples: ##### Retrieve a single metafield by its ID attached to a Blog Request: ``` GET /admin/api/unstable/blogs/382285388/metafields/534526895.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":534526895,"namespace":"translation","key":"title_fr","value":"Le iPod","description":"Blog French title translation","owner_id":241253187,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"blog","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/534526895"}} ``` ##### Retrieve a single metafield by its ID attached to a Collection Request: ``` GET /admin/api/unstable/collections/482865238/metafields/1010236510.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":1010236510,"namespace":"global","key":"title_tag","value":"Some seo title value","description":null,"owner_id":482865238,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"collection","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1010236510"}} ``` ##### Retrieve a single metafield by its ID attached to a Customer Request: ``` GET /admin/api/unstable/customers/207119551/metafields/220591908.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":220591908,"namespace":"discounts","key":"returning_customer","value":"no","description":"Customer deserves discount","owner_id":207119551,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"customer","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/220591908"}} ``` ##### Retrieve a single metafield by its ID attached to a Draft Order Request: ``` GET /admin/api/unstable/draft_orders/622762746/metafields/106172460.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":106172460,"namespace":"notes","key":"note","value":"B flat","description":"This is for notes","owner_id":622762746,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"draft_order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/106172460"}} ``` ##### Retrieve a single metafield by its ID attached to a Page Request: ``` GET /admin/api/unstable/pages/131092082/metafields/290519330.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":290519330,"namespace":"translation","key":"title_fr","value":"Le TOS","description":"Page French title translation","owner_id":131092082,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"page","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/290519330"}} ``` ##### Retrieve a single metafield by its ID attached to a Product Request: ``` GET /admin/api/unstable/products/632910392/metafields/1001077698.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":1001077698,"namespace":"my_fields","key":"best_for","value":"travel","description":null,"owner_id":632910392,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1001077698"}} ``` ##### Retrieve a single metafield by its ID attached to a Product Image Request: ``` GET /admin/api/unstable/product_images/850703190/metafields/625663657.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":625663657,"namespace":"translation","key":"title_fr","value":"tbn","description":"French product image title","owner_id":498048120,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"media_image","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/625663657"}} ``` ##### Retrieve a single metafield by its ID attached to a Product Variant Request: ``` GET /admin/api/unstable/variants/49148385/metafields/323119633.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":323119633,"namespace":"my_fields","key":"color","value":"Pink","description":null,"owner_id":808950810,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"variant","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/323119633"}} ``` ##### Retrieve a single metafield by its ID attached to an Article Request: ``` GET /admin/api/unstable/articles/674387490/metafields/838981074.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":838981074,"namespace":"translation","key":"title_fr","value":"Le Article","description":"Article French title translation","owner_id":134645308,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"article","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/838981074"}} ``` ##### Retrieve a single metafield by its ID attached to an Order Request: ``` GET /admin/api/unstable/orders/450789469/metafields/915396079.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":915396079,"namespace":"notes","key":"buyer","value":"Notes about this buyer","description":"This field is for buyer notes","owner_id":450789469,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/915396079"}} ``` ##### Retrieve a single metafield by its ID attached to the Shop resource Request: ``` GET /admin/api/unstable/metafields/721389482.json ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"id":721389482,"namespace":"affiliates","key":"app_key","value":"app_key","description":null,"owner_id":548380009,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:08:21-04:00","owner_resource":"shop","type":"string","admin_graphql_api_id":"gid://shopify/Metafield/721389482"}} ``` ## Updates a metafield Updates a metafield. The properties that can be updated are value and type. ### Endpoint /admin/api/#{api_version}/blogs/{blog_id}/metafields/{metafield_id}.json (PUT) ### Parameters * api_version (required): * blog_id (required): * metafield_id (required): ### Responses #### 200 Updates a metafield Examples: ##### Update a metafield for a Blog Request: ``` PUT /admin/api/unstable/blogs/382285388/metafields/534526895.json {"metafield":{"id":534526895,"value":"a translated blog title","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"a translated blog title","owner_id":241253187,"namespace":"translation","key":"title_fr","id":534526895,"description":"Blog French title translation","created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:32-04:00","owner_resource":"blog","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/534526895"}} ``` ##### Update a metafield for a Collection Request: ``` PUT /admin/api/unstable/collections/482865238/metafields/1010236510.json {"metafield":{"id":1010236510,"value":"seo title","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"seo title","owner_id":482865238,"namespace":"global","key":"title_tag","id":1010236510,"description":null,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:17-04:00","owner_resource":"collection","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1010236510"}} ``` ##### Update a metafield for a Customer Request: ``` PUT /admin/api/unstable/customers/207119551/metafields/220591908.json {"metafield":{"id":220591908,"value":"yes","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"yes","owner_id":207119551,"namespace":"discounts","key":"returning_customer","id":220591908,"description":"Customer deserves discount","created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:21-04:00","owner_resource":"customer","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/220591908"}} ``` ##### Update a metafield for a Draft Order Request: ``` PUT /admin/api/unstable/draft_orders/622762746/metafields/106172460.json {"metafield":{"id":106172460,"value":"110000","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"110000","owner_id":622762746,"namespace":"notes","key":"note","id":106172460,"description":"This is for notes","created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:22-04:00","owner_resource":"draft_order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/106172460"}} ``` ##### Update a metafield for a Page Request: ``` PUT /admin/api/unstable/pages/131092082/metafields/290519330.json {"metafield":{"id":290519330,"value":"An updated translation","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"An updated translation","owner_id":131092082,"namespace":"translation","key":"title_fr","id":290519330,"description":"Page French title translation","created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:13-04:00","owner_resource":"page","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/290519330"}} ``` ##### Update a metafield for a Product Request: ``` PUT /admin/api/unstable/products/632910392/metafields/1001077698.json {"metafield":{"id":1001077698,"value":"having fun","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"having fun","owner_id":632910392,"namespace":"my_fields","key":"best_for","id":1001077698,"description":null,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:47-04:00","owner_resource":"product","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/1001077698"}} ``` ##### Update a metafield for a Product Image Request: ``` PUT /admin/api/unstable/product_images/850703190/metafields/625663657.json {"metafield":{"id":625663657,"value":"translated description","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"translated description","owner_id":498048120,"namespace":"translation","key":"title_fr","id":625663657,"description":"French product image title","created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:35-04:00","owner_resource":"media_image","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/625663657"}} ``` ##### Update a metafield for a Product Variant Request: ``` PUT /admin/api/unstable/variants/49148385/metafields/323119633.json {"metafield":{"id":323119633,"value":"Red","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"Red","owner_id":808950810,"namespace":"my_fields","key":"color","id":323119633,"description":null,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:35-04:00","owner_resource":"variant","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/323119633"}} ``` ##### Update a metafield for a Shop resource Request: ``` PUT /admin/api/unstable/metafields/721389482.json {"metafield":{"id":721389482,"value":"[\"something new\"]","type":"list.single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"[\"something new\"]","owner_id":548380009,"namespace":"affiliates","key":"app_key","id":721389482,"description":null,"created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:27-04:00","owner_resource":"shop","type":"list.single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/721389482"}} ``` ##### Update a metafield for an Article Request: ``` PUT /admin/api/unstable/articles/674387490/metafields/838981074.json {"metafield":{"id":838981074,"value":"a translated title","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"a translated title","owner_id":134645308,"namespace":"translation","key":"title_fr","id":838981074,"description":"Article French title translation","created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:46-04:00","owner_resource":"article","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/838981074"}} ``` ##### Update a metafield for an Order Request: ``` PUT /admin/api/unstable/orders/450789469/metafields/915396079.json {"metafield":{"id":915396079,"value":"Provided a discount code","type":"single_line_text_field"}} ``` Response: ``` HTTP/1.1 200 OK {"metafield":{"value":"Provided a discount code","owner_id":450789469,"namespace":"notes","key":"buyer","id":915396079,"description":"This field is for buyer notes","created_at":"2024-09-26T15:08:21-04:00","updated_at":"2024-09-26T15:28:41-04:00","owner_resource":"order","type":"single_line_text_field","admin_graphql_api_id":"gid://shopify/Metafield/915396079"}} ``` ## Deletes a metafield by its ID Deletes a metafield by its ID. ### Endpoint /admin/api/#{api_version}/blogs/{blog_id}/metafields/{metafield_id}.json (DELETE) ### Parameters * api_version (required): * blog_id (required): * metafield_id (required): ### Responses #### 200 Deletes a metafield by its ID Examples: ##### Delete a metafield by its ID for a Blog Request: ``` DELETE /admin/api/unstable/blogs/382285388/metafields/534526895.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for a Collection Request: ``` DELETE /admin/api/unstable/collections/482865238/metafields/1010236510.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for a Customer Request: ``` DELETE /admin/api/unstable/customers/207119551/metafields/220591908.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for a Draft Order Request: ``` DELETE /admin/api/unstable/draft_orders/622762746/metafields/106172460.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for a Page Request: ``` DELETE /admin/api/unstable/pages/131092082/metafields/290519330.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for a Product Request: ``` DELETE /admin/api/unstable/products/632910392/metafields/1001077698.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for a Product Image Request: ``` DELETE /admin/api/unstable/product_images/850703190/metafields/625663657.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for a Product Variant Request: ``` DELETE /admin/api/unstable/variants/49148385/metafields/323119633.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for an Article Request: ``` DELETE /admin/api/unstable/articles/674387490/metafields/838981074.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for an Order Request: ``` DELETE /admin/api/unstable/orders/450789469/metafields/915396079.json ``` Response: ``` HTTP/1.1 200 OK {} ``` ##### Delete a metafield by its ID for the Shop resource Request: ``` DELETE /admin/api/unstable/metafields/721389482.json ``` Response: ``` HTTP/1.1 200 OK {} ```