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
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation giftCardCreate($input: GiftCardCreateInput!) {6 giftCardCreate(input: $input) {7 giftCard {8 id9 initialValue {10 amount11 }12 customer {13 id14 }15 recipientAttributes {16 recipient {17 id18 }19 message20 preferredName21 sendNotificationAt22 }23 }24 userErrors {25 message26 field27 code28 }29 }30 }`,31 {32 variables: {33 "input": {34 "initialValue": "100.0",35 "customerId": "gid://shopify/Customer/331283560",36 "recipientAttributes": {37 "id": "gid://shopify/Customer/743592264",38 "message": "Happy Birthday!",39 "preferredName": "Dad",40 "sendNotificationAt": "2024-10-01T12:00:00Z"41 }42 }43 },44 },45);4647const data = await response.json();48
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/unstable/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
JSON1{2 "input": {3 "initialValue": "100.0",4 "customerId": "gid://shopify/Customer/331283560",5 "recipientAttributes": {6 "id": "gid://shopify/Customer/743592264",7 "message": "Happy Birthday!",8 "preferredName": "Dad",9 "sendNotificationAt": "2024-10-01T12:00:00Z"10 }11 }12}
Response
JSON1{2 "giftCardCreate": {3 "giftCard": {4 "id": "gid://shopify/GiftCard/1063936324",5 "initialValue": {6 "amount": "100.0"7 },8 "customer": {9 "id": "gid://shopify/Customer/331283560"10 },11 "recipientAttributes": {12 "recipient": {13 "id": "gid://shopify/Customer/743592264"14 },15 "message": "Happy Birthday!",16 "preferredName": "Dad",17 "sendNotificationAt": "2024-10-01T12:00:00Z"18 }19 },20 "userErrors": []21 }22}