mutation createProductMetafields($input: ProductInput!) {
productCreate(input: $input) {
product {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
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": "mutation createProductMetafields($input: ProductInput!) { productCreate(input: $input) { product { id metafields(first: 3) { edges { node { id namespace key value } } } } userErrors { message field } } }",
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "liner_material",
"type": "single_line_text_field",
"value": "Synthetic Leather"
}
],
"title": "Hiking Boots"
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation createProductMetafields($input: ProductInput!) {
productCreate(input: $input) {
product {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
{
variables: {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "liner_material",
"type": "single_line_text_field",
"value": "Synthetic Leather"
}
],
"title": "Hiking Boots"
}
},
},
);
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 createProductMetafields($input: ProductInput!) {
productCreate(input: $input) {
product {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY
variables = {
"input": {
"metafields": [{"namespace"=>"my_field", "key"=>"liner_material", "type"=>"single_line_text_field", "value"=>"Synthetic Leather"}],
"title": "Hiking Boots"
}
}
response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation createProductMetafields($input: ProductInput!) {
productCreate(input: $input) {
product {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}`,
"variables": {
"input": {
"metafields": [
{
"namespace": "my_field",
"key": "liner_material",
"type": "single_line_text_field",
"value": "Synthetic Leather"
}
],
"title": "Hiking Boots"
}
},
},
});
use Shopify\Clients\Graphql;
$client = new Graphql("your-development-store.myshopify.com", $accessToken);
$query = <<<QUERY
mutation createProductMetafields($input: ProductInput!) {
productCreate(input: $input) {
product {
id
metafields(first: 3) {
edges {
node {
id
namespace
key
value
}
}
}
}
userErrors {
message
field
}
}
}
QUERY;
$variables = [
"input" => [
"metafields" => [{"namespace"=>"my_field", "key"=>"liner_material", "type"=>"single_line_text_field", "value"=>"Synthetic Leather"}],
"title" => "Hiking Boots",
],
];
$response = $client->query(["query" => $query, "variables" => $variables]);