Anchor to giftCardDebitgift
giftCardDebit
mutation
Requires access scope.
Debit a gift card.
Anchor to Arguments
Arguments
- Anchor to debitInputdebit•
Input GiftCard requiredDebit Input! The input fields to debit a gift card.
- •ID!required
The ID of the gift card to be debited.
Was this section helpful?
Anchor to GiftCardDebitPayload returnsGiftCardDebitPayload returns
- Anchor to giftCardDebitTransactiongift•
Card Debit Transaction The gift card debit transaction that was created.
- Anchor to userErrorsuser•
Errors [GiftCard non-nullTransaction User Error!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Debit a gift card by ID
- giftCardDebit reference
Examples
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation giftCardDebit($id: ID!, $debitInput: GiftCardDebitInput!) {
giftCardDebit(id: $id, debitInput: $debitInput) {
giftCardDebitTransaction {
id
amount {
amount
currencyCode
}
processedAt
note
giftCard {
id
balance {
amount
currencyCode
}
}
}
userErrors {
message
field
code
}
}
}`,
{
variables: {
mutation giftCardDebit($id: ID!, $debitInput: GiftCardDebitInput!) {
giftCardDebit(id: $id, debitInput: $debitInput) {
giftCardDebitTransaction {
id
amount {
amount
currencyCode
}
processedAt
note
giftCard {
id
balance {
amount
currencyCode
}
}
}
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 giftCardDebit($id: ID!, $debitInput: GiftCardDebitInput!) { giftCardDebit(id: $id, debitInput: $debitInput) { giftCardDebitTransaction { id amount { amount currencyCode } processedAt note giftCard { id balance { amount currencyCode } } } userErrors { message field code } } }",
"variables": {
"id": "gid://shopify/GiftCard/411106674",
"debitInput": {
"debitAmount": {
"amount": "10",
"currencyCode": "USD"
},
"processedAt": "2024-09-09T12:48:33-04:00",
"note": "A note."
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation giftCardDebit($id: ID!, $debitInput: GiftCardDebitInput!) {
giftCardDebit(id: $id, debitInput: $debitInput) {
giftCardDebitTransaction {
id
amount {
amount
currencyCode
}
processedAt
note
giftCard {
id
balance {
amount
currencyCode
}
}
}
userErrors {
message
field
code
}
}
}`,
{
variables: {
"id": "gid://shopify/GiftCard/411106674",
"debitInput": {
"debitAmount": {
"amount": "10",
"currencyCode": "USD"
},
"processedAt": "2024-09-09T12:48:33-04:00",
"note": "A note."
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation giftCardDebit($id: ID!, $debitInput: GiftCardDebitInput!) {
giftCardDebit(id: $id, debitInput: $debitInput) {
giftCardDebitTransaction {
id
amount {
amount
currencyCode
}
processedAt
note
giftCard {
id
balance {
amount
currencyCode
}
}
}
userErrors {
message
field
code
}
}
}`,
"variables": {
"id": "gid://shopify/GiftCard/411106674",
"debitInput": {
"debitAmount": {
"amount": "10",
"currencyCode": "USD"
},
"processedAt": "2024-09-09T12:48:33-04:00",
"note": "A note."
}
},
},
});
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 giftCardDebit($id: ID!, $debitInput: GiftCardDebitInput!) {
giftCardDebit(id: $id, debitInput: $debitInput) {
giftCardDebitTransaction {
id
amount {
amount
currencyCode
}
processedAt
note
giftCard {
id
balance {
amount
currencyCode
}
}
}
userErrors {
message
field
code
}
}
}
QUERY
variables = {
"id": "gid://shopify/GiftCard/411106674",
"debitInput": {
"debitAmount": {
"amount": "10",
"currencyCode": "USD"
},
"processedAt": "2024-09-09T12:48:33-04:00",
"note": "A note."
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON{
"id": "gid://shopify/GiftCard/411106674",
"debitInput": {
"debitAmount": {
"amount": "10",
"currencyCode": "USD"
},
"processedAt": "2024-09-09T12:48:33-04:00",
"note": "A note."
}
}
Response
JSON{
"giftCardDebit": {
"giftCardDebitTransaction": {
"id": "gid://shopify/GiftCardDebitTransaction/1064273912",
"amount": {
"amount": "-10.0",
"currencyCode": "USD"
},
"processedAt": "2024-09-09T16:48:33Z",
"note": "A note.",
"giftCard": {
"id": "gid://shopify/GiftCard/411106674",
"balance": {
"amount": "15.0",
"currencyCode": "USD"
}
}
},
"userErrors": []
}
}