Anchor to section titled 'undefined'

privateMetafieldUpsert
mutation
deprecated

Creates or updates a private metafield. Use private metafields when you don't want the metafield data to be accessible by merchants or other apps. Private metafields are accessible only by the application that created them and only from the GraphQL Admin API.

An application can create a maximum of 10 private metafields per shop resource. Metafields created using a reserved namespace are private by default. See our guide for migrating private metafields.


Specifies the input fields for the private metafield.


Was this section helpful?

The private metafield that was created or updated.

The list of errors that occurred from executing the mutation.


Was this section helpful?

Examples

Hide code
DescriptionCopy
mutation productUpdate($input: ProductInput!) {
  productUpdate(input: $input) {
    product {
      privateMetafields(first: 10) {
        edges {
          node {
            namespace
            key
            value
          }
        }
      }
    }
  }
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2024-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation productUpdate($input: ProductInput!) { productUpdate(input: $input) { product { privateMetafields(first: 10) { edges { node { namespace key value } } } } } }",
 "variables": {
    "input": {
      "id": "gid://shopify/Product/632910392",
      "privateMetafields": [
        {
          "owner": "gid://shopify/Product/632910392",
          "namespace": "wholesale",
          "key": "price",
          "valueInput": {
            "value": "5",
            "valueType": "INTEGER"
          }
        }
      ]
    }
  }
}'
const { admin } = await authenticate.admin(request);

const response = await admin.graphql(
  `#graphql
  mutation productUpdate($input: ProductInput!) {
    productUpdate(input: $input) {
      product {
        privateMetafields(first: 10) {
          edges {
            node {
              namespace
              key
              value
            }
          }
        }
      }
    }
  }`,
  {
    variables: {
      "input": {
        "id": "gid://shopify/Product/632910392",
        "privateMetafields": [
          {
            "owner": "gid://shopify/Product/632910392",
            "namespace": "wholesale",
            "key": "price",
            "valueInput": {
              "value": "5",
              "valueType": "INTEGER"
            }
          }
        ]
      }
    },
  },
);

const data = await response.json();
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
  mutation productUpdate($input: ProductInput!) {
    productUpdate(input: $input) {
      product {
        privateMetafields(first: 10) {
          edges {
            node {
              namespace
              key
              value
            }
          }
        }
      }
    }
  }
QUERY

variables = {
  "input": {
    "id": "gid://shopify/Product/632910392",
    "privateMetafields": [{"owner"=>"gid://shopify/Product/632910392", "namespace"=>"wholesale", "key"=>"price", "valueInput"=>{"value"=>"5", "valueType"=>"INTEGER"}}]
  }
}

response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
  data: {
    "query": `mutation productUpdate($input: ProductInput!) {
      productUpdate(input: $input) {
        product {
          privateMetafields(first: 10) {
            edges {
              node {
                namespace
                key
                value
              }
            }
          }
        }
      }
    }`,
    "variables": {
      "input": {
        "id": "gid://shopify/Product/632910392",
        "privateMetafields": [
          {
            "owner": "gid://shopify/Product/632910392",
            "namespace": "wholesale",
            "key": "price",
            "valueInput": {
              "value": "5",
              "valueType": "INTEGER"
            }
          }
        ]
      }
    },
  },
});
use Shopify\Clients\Graphql;

$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
  mutation productUpdate($input: ProductInput!) {
    productUpdate(input: $input) {
      product {
        privateMetafields(first: 10) {
          edges {
            node {
              namespace
              key
              value
            }
          }
        }
      }
    }
  }
QUERY;

$variables = [
  "input" => [
    "id" => "gid://shopify/Product/632910392",
    "privateMetafields" => [{"owner"=>"gid://shopify/Product/632910392", "namespace"=>"wholesale", "key"=>"price", "valueInput"=>{"value"=>"5", "valueType"=>"INTEGER"}}],
  ],
];

$response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{
  "input": {
    "id": "gid://shopify/Product/632910392",
    "privateMetafields": [
      {
        "owner": "gid://shopify/Product/632910392",
        "namespace": "wholesale",
        "key": "price",
        "valueInput": {
          "value": "5",
          "valueType": "INTEGER"
        }
      }
    ]
  }
}
Hide code
Response
JSON
{
  "productUpdate": {
    "product": {
      "privateMetafields": {
        "edges": [
          {
            "node": {
              "namespace": "wholesale",
              "key": "price",
              "value": "5"
            }
          }
        ]
      }
    }
  }
}