Anchor to giftCardCreategift
giftCardCreate
mutation
Requires access scope.
Create a gift card.
Anchor to Arguments
Arguments
- Anchor to inputinput•Gift
Card requiredCreate Input! The input fields to create a gift card.
Was this section helpful?
Anchor to GiftCardCreatePayload returnsGiftCardCreatePayload returns
- Anchor to giftCardgift•
Card The created gift card.
- Anchor to giftCardCodegift•
Card Code The created gift card's code.
- Anchor to userErrorsuser•
Errors [GiftCard non-nullUser Error!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a non-expiring gift card with a generated code for a customer
- Creates a gift card
- giftCardCreate reference
Examples
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();
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/2024-07/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();
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"
}
},
},
});
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)
Input variables
JSON{
"input": {
"initialValue": "27.84",
"customerId": "gid://shopify/Customer/743592264",
"note": "Refund for Order #1"
}
}
Response
JSON{
"giftCardCreate": {
"userErrors": [],
"giftCard": {
"id": "gid://shopify/GiftCard/1063936322",
"expiresOn": null,
"note": "Refund for Order #1",
"initialValue": {
"amount": "27.84"
},
"customer": {
"id": "gid://shopify/Customer/743592264"
}
},
"giftCardCode": "a5bhbh645b32934f"
}
}