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
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation giftCardCreate($input: GiftCardCreateInput!) {6 giftCardCreate(input: $input) {7 userErrors {8 message9 field10 }11 giftCard {12 id13 expiresOn14 note15 initialValue {16 amount17 }18 customer {19 id20 }21 }22 giftCardCode23 }24 }`,25 {26 variables: {27 "input": {28 "initialValue": "27.84",29 "customerId": "gid://shopify/Customer/743592264",30 "note": "Refund for Order #1"31 }32 },33 },34);3536const data = await response.json();37
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-04/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
JSON1{2 "input": {3 "initialValue": "27.84",4 "customerId": "gid://shopify/Customer/743592264",5 "note": "Refund for Order #1"6 }7}
Response
JSON1{2 "giftCardCreate": {3 "userErrors": [],4 "giftCard": {5 "id": "gid://shopify/GiftCard/1063936322",6 "expiresOn": null,7 "note": "Refund for Order #1",8 "initialValue": {9 "amount": "27.84"10 },11 "customer": {12 "id": "gid://shopify/Customer/743592264"13 }14 },15 "giftCardCode": "a5bhbh645b32934f"16 }17}