--- title: privateMetafields - GraphQL Admin description: Returns a list of private metafields associated to a resource. api_version: 2024-10 api_name: admin type: query api_type: graphql source_url: html: 'https://shopify.dev/docs/api/admin-graphql/2024-10/queries/privateMetafields' md: >- https://shopify.dev/docs/api/admin-graphql/2024-10/queries/privateMetafields.txt --- # private​Metafields query Deprecated. Metafields created using a reserved namespace are private by default. See our guide for [migrating private metafields](https://shopify.dev/docs/apps/custom-data/metafields/migrate-private-metafields). This will be removed in 2025-01. Returns a list of private metafields associated to a resource. ## PrivateMetafieldConnection arguments [PrivateMetafieldConnection!](https://shopify.dev/docs/api/admin-graphql/2024-10/connections/PrivateMetafieldConnection) * after [String](https://shopify.dev/docs/api/admin-graphql/2024-10/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/2024-10/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/2024-10/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/2024-10/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/2024-10/scalars/String) Filter the private metafields by namespace. * owner [ID!](https://shopify.dev/docs/api/admin-graphql/2024-10/scalars/ID) required Retrieve the private metafields of a certain resource, specified by the resource ID. * reverse [Boolean](https://shopify.dev/docs/api/admin-graphql/2024-10/scalars/Boolean) Default:false Reverse the order of the underlying list. *** ## Possible returns * edges [\[Private​Metafield​Edge!\]!](https://shopify.dev/docs/api/admin-graphql/2024-10/objects/PrivateMetafieldEdge) non-null The connection between the node and its parent. Each edge contains a minimum of the edge's cursor and the node. * nodes [\[Private​Metafield!\]!](https://shopify.dev/docs/api/admin-graphql/2024-10/objects/PrivateMetafield) non-null A list of nodes that are contained in PrivateMetafieldEdge. 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/2024-10/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 a list of private metafields #### Description To retrieve a list of private metafields associdated to a resource, use the \`privateMetafields\` query. The following example shows how to retrieve the private metafields associated to an \`Order\`. #### Query ```graphql query { privateMetafields(owner: "gid://shopify/Order/148977776", first: 2) { edges { node { id key namespace value } } } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { privateMetafields(owner: \"gid://shopify/Order/148977776\", first: 2) { edges { node { id key namespace value } } } }" }' ``` #### Remix ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { privateMetafields(owner: "gid://shopify/Order/148977776", first: 2) { edges { node { id key namespace value } } } }`, ); const data = await response.json(); ``` #### 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 { privateMetafields(owner: "gid://shopify/Order/148977776", first: 2) { edges { node { id key namespace value } } } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { privateMetafields(owner: "gid://shopify/Order/148977776", first: 2) { edges { node { id key namespace value } } } }`, }); ``` #### Response ```json { "privateMetafields": { "edges": [ { "node": { "id": "gid://shopify/PrivateMetafield/1060470842", "key": "buyer", "namespace": "notes", "value": "Notes about this buyer" } }, { "node": { "id": "gid://shopify/PrivateMetafield/1060470843", "key": "reviews", "namespace": "feedback", "value": "Feedback about the order" } } ] } } ``` * ### Retrieve a list of private metafields from the Shop resource #### Description To retrieve a list of private metafields associdated to a resource, use the \`privateMetafields\` query. The following example shows how to retrieve the private metafields associated to the \`Shop\`. #### Query ```graphql query { shop { name privateMetafields(first: 2) { edges { node { id key namespace value } } } } } ``` #### cURL ```bash curl -X POST \ https://your-development-store.myshopify.com/admin/api/2024-10/graphql.json \ -H 'Content-Type: application/json' \ -H 'X-Shopify-Access-Token: {access_token}' \ -d '{ "query": "query { shop { name privateMetafields(first: 2) { edges { node { id key namespace value } } } } }" }' ``` #### Remix ```javascript const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { shop { name privateMetafields(first: 2) { edges { node { id key namespace value } } } } }`, ); const data = await response.json(); ``` #### 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 { shop { name privateMetafields(first: 2) { edges { node { id key namespace value } } } } } QUERY response = client.query(query: query) ``` #### Node.js ```javascript const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: `query { shop { name privateMetafields(first: 2) { edges { node { id key namespace value } } } } }`, }); ``` #### Response ```json { "shop": { "name": "John Smith Test Store", "privateMetafields": { "edges": [ { "node": { "id": "gid://shopify/PrivateMetafield/769645494", "key": "test_key", "namespace": "nested_namespace", "value": "this is a test value" } }, { "node": { "id": "gid://shopify/PrivateMetafield/1060470841", "key": "fantastic_app", "namespace": "private_keys", "value": "TA432RZ" } } ] } } } ``` [Open in GraphiQL](http://localhost:3457/graphiql?query=query%20%7B%0A%20%20privateMetafields\(owner%3A%20%22gid%3A%2F%2Fshopify%2FOrder%2F148977776%22%2C%20first%3A%202\)%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%20id%0A%20%20%20%20%20%20%20%20key%0A%20%20%20%20%20%20%20%20namespace%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 const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql query { privateMetafields(owner: "gid://shopify/Order/148977776", first: 2) { edges { node { id key namespace value } } } }`, ); const data = await response.json(); ``` ## Response JSON ```json { "privateMetafields": { "edges": [ { "node": { "id": "gid://shopify/PrivateMetafield/1060470842", "key": "buyer", "namespace": "notes", "value": "Notes about this buyer" } }, { "node": { "id": "gid://shopify/PrivateMetafield/1060470843", "key": "reviews", "namespace": "feedback", "value": "Feedback about the order" } } ] } } ```