--- title: metafields - GraphQL Admin description: A paginated list of metafields. api_version: unstable api_name: admin source_url: html: https://shopify.dev/docs/api/admin-graphql/unstable/queries/metafields md: https://shopify.dev/docs/api/admin-graphql/unstable/queries/metafields.md --- # metafields query A paginated list of metafields. ## MetafieldConnection arguments [MetafieldConnection!](https://shopify.dev/docs/api/admin-graphql/unstable/connections/MetafieldConnection) * after [String](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/String) The elements that come after the specified [cursor](https://shopify.dev/api/usage/pagination-graphql). * before [String](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/String) The elements that come before the specified [cursor](https://shopify.dev/api/usage/pagination-graphql). * first [Int](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/Int) The first `n` elements from the [paginated list](https://shopify.dev/api/usage/pagination-graphql). * last [Int](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/Int) The last `n` elements from the [paginated list](https://shopify.dev/api/usage/pagination-graphql). * namespace [String](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/String) Filter metafields by namespace. * owner [ID!](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/ID) required Filter metafields to a specific owner. Recommend using the `metafields` connection from [HasMetafields](https://shopify.dev/api/admin/graphql/reference/common-objects/HasMetafields) directly from the owner instead. * reverse [Boolean](https://shopify.dev/docs/api/admin-graphql/unstable/scalars/Boolean) Default:false Reverse the order of the underlying list. *** ## Possible returns * edges [\[Metafield​Edge!\]!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/MetafieldEdge) non-null The connection between the node and its parent. Each edge contains a minimum of the edge's cursor and the node. * nodes [\[Metafield!\]!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/Metafield) non-null A list of nodes that are contained in MetafieldEdge. You can fetch data about an individual node, or you can follow the edges to fetch data about a collection of related nodes. At each node, you specify the fields that you want to retrieve. * page​Info [Page​Info!](https://shopify.dev/docs/api/admin-graphql/unstable/objects/PageInfo) non-null An object that’s used to retrieve [cursor information](https://shopify.dev/api/usage/pagination-graphql) about the current page. *** ## Examples * ### Retrieve metafields belonging to a resource #### Description Retrieve all metafields belonging to a product. It's recommended to use the \`metafields\` connection from \[HasMetafields]\(https\://shopify.dev/api/admin/graphql/reference/common-objects/HasMetafields) directly from the owner instead. Refer to \[this example instead]\(https\://shopify.dev/api/admin/graphql/reference/common-objects/product#examples-Get\_metafields\_attached\_to\_a\_product). #### Query ```graphql query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { metafields(first: 2, owner: \"gid://shopify/Product/20995642\") { edges { node { namespace key value } } } }" }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } }`, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } }`, }); ``` #### Response ```json { "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "materials", "value": "95% Cotton/n 5% Spandex" } } ] } } ``` * ### Retrieve metafields within a namespace #### Description Retrieve all metafields that are under the same namespace. It's recommended to use the \`metafields\` connection from \[HasMetafields]\(https\://shopify.dev/api/admin/graphql/reference/common-objects/HasMetafields) directly from the owner instead. Refer to \[this example instead]\(https\://shopify.dev/api/admin/graphql/reference/common-objects/product#examples-Get\_metafields\_attached\_to\_a\_product). #### Query ```graphql query { metafields(first: 2, owner: "gid://shopify/Product/20995642", namespace: "my_fields") { edges { node { namespace key value } } } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { metafields(first: 2, owner: \"gid://shopify/Product/20995642\", namespace: \"my_fields\") { edges { node { namespace key value } } } }" }' ``` #### React Router ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { metafields(first: 2, owner: "gid://shopify/Product/20995642", namespace: "my_fields") { edges { node { namespace key value } } } }`, ); const json = await response.json(); return json.data; } ``` #### Ruby ```ruby session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query { metafields(first: 2, owner: "gid://shopify/Product/20995642", namespace: "my_fields") { edges { node { namespace key value } } } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { metafields(first: 2, owner: "gid://shopify/Product/20995642", namespace: "my_fields") { edges { node { namespace key value } } } }`, }); ``` #### Response ```json { "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "materials", "value": "95% Cotton\n5% Spandex" } }, { "node": { "namespace": "my_fields", "key": "manufactured", "value": "Made in Canada" } } ] } } ``` [Open in GraphiQL](http://localhost:3457/graphiql?query=query%20%7B%0A%20%20metafields\(first%3A%202%2C%20owner%3A%20%22gid%3A%2F%2Fshopify%2FProduct%2F20995642%22\)%20%7B%0A%20%20%20%20edges%20%7B%0A%20%20%20%20%20%20node%20%7B%0A%20%20%20%20%20%20%20%20namespace%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%20%20value%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%0A%7D) ```javascript import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } }`, ); const json = await response.json(); return json.data; } ``` ##### GQL ``` query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } } ``` ##### cURL ``` curl -X POST \ https://your-development-store.myshopify.com/admin/api/unstable/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { metafields(first: 2, owner: \"gid://shopify/Product/20995642\") { edges { node { namespace key value } } } }" }' ``` ##### React Router ``` import { authenticate } from "../shopify.server"; export const loader = async ({request}) => { const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } }`, ); const json = await response.json(); return json.data; } ``` ##### Node.js ``` const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } }`, }); ``` ##### Ruby ``` session = ShopifyAPI::Auth::Session.new( shop: "your-development-store.myshopify.com", access_token: access_token ) client = ShopifyAPI::Clients::Graphql::Admin.new( session: session ) query = <<~QUERY query { metafields(first: 2, owner: "gid://shopify/Product/20995642") { edges { node { namespace key value } } } } QUERY response = client.query(query: query) ``` ## Response JSON ```json { "metafields": { "edges": [ { "node": { "namespace": "my_fields", "key": "materials", "value": "95% Cotton/n 5% Spandex" } } ] } } ```