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 gift card with a customer and a recipient
- 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) {
giftCard {
id
initialValue {
amount
}
customer {
id
}
recipientAttributes {
recipient {
id
}
message
preferredName
sendNotificationAt
}
}
userErrors {
message
field
code
}
}
}`,
{
variables: {
"input": {
"initialValue": "100.0",
mutation giftCardCreate($input: GiftCardCreateInput!) {
giftCardCreate(input: $input) {
giftCard {
id
initialValue {
amount
}
customer {
id
}
recipientAttributes {
recipient {
id
}
message
preferredName
sendNotificationAt
}
}
userErrors {
message
field
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 giftCardCreate($input: GiftCardCreateInput!) { giftCardCreate(input: $input) { giftCard { id initialValue { amount } customer { id } recipientAttributes { recipient { id } message preferredName sendNotificationAt } } userErrors { message field code } } }",
"variables": {
"input": {
"initialValue": "100.0",
"customerId": "gid://shopify/Customer/331283560",
"recipientAttributes": {
"id": "gid://shopify/Customer/743592264",
"message": "Happy Birthday!",
"preferredName": "Dad",
"sendNotificationAt": "2024-10-01T12:00:00Z"
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation giftCardCreate($input: GiftCardCreateInput!) {
giftCardCreate(input: $input) {
giftCard {
id
initialValue {
amount
}
customer {
id
}
recipientAttributes {
recipient {
id
}
message
preferredName
sendNotificationAt
}
}
userErrors {
message
field
code
}
}
}`,
{
variables: {
"input": {
"initialValue": "100.0",
"customerId": "gid://shopify/Customer/331283560",
"recipientAttributes": {
"id": "gid://shopify/Customer/743592264",
"message": "Happy Birthday!",
"preferredName": "Dad",
"sendNotificationAt": "2024-10-01T12:00:00Z"
}
}
},
},
);
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) {
giftCard {
id
initialValue {
amount
}
customer {
id
}
recipientAttributes {
recipient {
id
}
message
preferredName
sendNotificationAt
}
}
userErrors {
message
field
code
}
}
}`,
"variables": {
"input": {
"initialValue": "100.0",
"customerId": "gid://shopify/Customer/331283560",
"recipientAttributes": {
"id": "gid://shopify/Customer/743592264",
"message": "Happy Birthday!",
"preferredName": "Dad",
"sendNotificationAt": "2024-10-01T12:00:00Z"
}
}
},
},
});
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) {
giftCard {
id
initialValue {
amount
}
customer {
id
}
recipientAttributes {
recipient {
id
}
message
preferredName
sendNotificationAt
}
}
userErrors {
message
field
code
}
}
}
QUERY
variables = {
"input": {
"initialValue": "100.0",
"customerId": "gid://shopify/Customer/331283560",
"recipientAttributes": {
"id": "gid://shopify/Customer/743592264",
"message": "Happy Birthday!",
"preferredName": "Dad",
"sendNotificationAt": "2024-10-01T12:00:00Z"
}
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"input": {
"initialValue": "100.0",
"customerId": "gid://shopify/Customer/331283560",
"recipientAttributes": {
"id": "gid://shopify/Customer/743592264",
"message": "Happy Birthday!",
"preferredName": "Dad",
"sendNotificationAt": "2024-10-01T12:00:00Z"
}
}
}
Response
JSON{
"giftCardCreate": {
"giftCard": {
"id": "gid://shopify/GiftCard/1063936324",
"initialValue": {
"amount": "100.0"
},
"customer": {
"id": "gid://shopify/Customer/331283560"
},
"recipientAttributes": {
"recipient": {
"id": "gid://shopify/Customer/743592264"
},
"message": "Happy Birthday!",
"preferredName": "Dad",
"sendNotificationAt": "2024-10-01T12:00:00Z"
}
},
"userErrors": []
}
}