mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
key
namespace
value
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-01/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) { metafieldsSet(metafields: $metafields) { metafields { key namespace value createdAt updatedAt } userErrors { field message code } } }",
"variables": {
"metafields": [
{
"key": "materials",
"namespace": "my_fields",
"ownerId": "gid://shopify/Product/20995642",
"type": "multi_line_text_field",
"value": "95% Cotton\n5% Spandex"
},
{
"key": "manufactured",
"namespace": "my_fields",
"ownerId": "gid://shopify/Product/20995642",
"type": "single_line_text_field",
"value": "Made in Canada"
}
]
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
key
namespace
value
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}`,
{
variables: {
"metafields": [
{
"key": "materials",
"namespace": "my_fields",
"ownerId": "gid://shopify/Product/20995642",
"type": "multi_line_text_field",
"value": "95% Cotton\n5% Spandex"
},
{
"key": "manufactured",
"namespace": "my_fields",
"ownerId": "gid://shopify/Product/20995642",
"type": "single_line_text_field",
"value": "Made in Canada"
}
]
},
},
);
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 MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
key
namespace
value
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}
QUERY
variables = {
"metafields": [{"key"=>"materials", "namespace"=>"my_fields", "ownerId"=>"gid://shopify/Product/20995642", "type"=>"multi_line_text_field", "value"=>"95% Cotton\n5% Spandex"}, {"key"=>"manufactured", "namespace"=>"my_fields", "ownerId"=>"gid://shopify/Product/20995642", "type"=>"single_line_text_field", "value"=>"Made in Canada"}]
}
response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
key
namespace
value
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}`,
"variables": {
"metafields": [
{
"key": "materials",
"namespace": "my_fields",
"ownerId": "gid://shopify/Product/20995642",
"type": "multi_line_text_field",
"value": "95% Cotton\n5% Spandex"
},
{
"key": "manufactured",
"namespace": "my_fields",
"ownerId": "gid://shopify/Product/20995642",
"type": "single_line_text_field",
"value": "Made in Canada"
}
]
},
},
});
use Shopify\Clients\Graphql;
$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
mutation MetafieldsSet($metafields: [MetafieldsSetInput!]!) {
metafieldsSet(metafields: $metafields) {
metafields {
key
namespace
value
createdAt
updatedAt
}
userErrors {
field
message
code
}
}
}
QUERY;
$variables = [
"metafields" => [{"key"=>"materials", "namespace"=>"my_fields", "ownerId"=>"gid://shopify/Product/20995642", "type"=>"multi_line_text_field", "value"=>"95% Cotton\n5% Spandex"}, {"key"=>"manufactured", "namespace"=>"my_fields", "ownerId"=>"gid://shopify/Product/20995642", "type"=>"single_line_text_field", "value"=>"Made in Canada"}],
];
$response = $client->query(["query" => $query, "variables" => $variables]);