gift Card Createmutation
mutation
2025-01release candidate
Requires
write_gift_cards
access scope. Also: User needs create_and_edit_gift_cards permission.
Create a gift card.
Arguments
The input fields to create a gift card.
Was this section helpful?
GiftCardCreatePayload returns
The created gift card.
The created gift card's code.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
Hide code
Copy
mutation giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { userErrors { message field } giftCard { id expiresOn note initialValue { amount } customer { id } } giftCardCode } }
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 giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { userErrors { message field } giftCard { id expiresOn note initialValue { amount } customer { id } } giftCardCode } }", "variables": { "input": { "initialValue": "27.84", "customerId": "gid://shopify/Customer/743592264", "note": "Refund for Order #1" } } }'
const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { userErrors { message field } giftCard { id expiresOn note initialValue { amount } customer { id } } giftCardCode } }`, { variables: { "input": { "initialValue": "27.84", "customerId": "gid://shopify/Customer/743592264", "note": "Refund for Order #1" } }, }, ); 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 giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { userErrors { message field } giftCard { id expiresOn note initialValue { amount } customer { id } } giftCardCode } } QUERY variables = { "input": { "initialValue": "27.84", "customerId": "gid://shopify/Customer/743592264", "note": "Refund for Order #1" } } response = client.query(query: query, variables: variables)
const client = new shopify.clients.Graphql({session}); const data = await client.query({ data: { "query": `mutation giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { userErrors { message field } giftCard { id expiresOn note initialValue { amount } customer { id } } giftCardCode } }`, "variables": { "input": { "initialValue": "27.84", "customerId": "gid://shopify/Customer/743592264", "note": "Refund for Order #1" } }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $query = <<<QUERY mutation giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { userErrors { message field } giftCard { id expiresOn note initialValue { amount } customer { id } } giftCardCode } } QUERY; $variables = [ "input" => [ "initialValue" => "27.84", "customerId" => "gid://shopify/Customer/743592264", "note" => "Refund for Order #1", ], ]; $response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "input": { "initialValue": "27.84", "customerId": "gid://shopify/Customer/743592264", "note": "Refund for Order #1" } }
Hide code
Response
JSON
{ "giftCardCreate": { "userErrors": [], "giftCard": { "id": "gid://shopify/GiftCard/1063936316", "expiresOn": null, "note": "Refund for Order #1", "initialValue": { "amount": "27.84" }, "customer": { "id": "gid://shopify/Customer/743592264" } }, "giftCardCode": "29cd47a94g68fe42" } }