Manage gift cards with the GraphQL Admin API
Gift cards are products that merchants can sell through their stores. Customers use gift cards as a payment method to make purchases. This tutorial shows you how to create, retrieve, update, and disable gift cards for a store using the GraphQL Admin API.
How gift cards workAnchor link to section titled "How gift cards work"
A gift card is a special type of product and an alternative payment method. Its value can be used as payment toward future orders from an online store.
Each gift card has a unique code that is entered during checkout. Its balance can be redeemed over multiple checkouts. Optionally, a gift card code can be assigned to a specific customer.
After a gift card is created, the gift card code can't be updated. Only the customer, expiry date, note, and template suffix can be updated. The gift card code can't be retrieved after it's created — only the last four characters can be retrieved.
RequirementsAnchor link to section titled "Requirements"
- Your app must be either private or custom and installed on a Shopify Plus store.
- You've completed our Getting started with the GraphQL Admin and REST Admin APIs guide and you're authenticated with the API.
- You've activated the gift card feature in the Shopify admin of your store.
To use the GraphQL queries and mutations, your app needs to request the following access scopes for a Shopify store:
read_gift_cards: Allows an app to read gift cards.
write_gift_cards: Allows an app to write gift cards.
Create a gift cardAnchor link to section titled "Create a gift card"
To create a new gift card, run the
giftCardCreate mutation. The returned fields include the ID of the gift card (
id), the redacted gift card code (
maskedCode), the timestamp of when the gift card was created (
createdAt), and the full gift card code (
giftCardCode). In the following example, the initial value of the gift card is supplied as an input variable.
Retrieve gift cardsAnchor link to section titled "Retrieve gift cards"
To retrieve existing gift cards, you can query
giftCards on the
QueryRoot. In the following example, the response body returns the first five gift cards and their corresponding IDs.
Update a gift cardAnchor link to section titled "Update a gift card"
To update a gift card, you can run the
giftCardUpdate mutation. For example, if you want to update a gift card's expiration date, you can supply the gift card ID (
id) and new expiration date (
expiresOn) as input variables in the mutation. In the following example, the gift card's expiration date is updated to December 26, 2025.
Disable a gift cardAnchor link to section titled "Disable a gift card"
To disable a gift card, run the
giftCardDisable mutation and supply the ID of the gift card that you want to disable. After you disable a gift card, the merchant can't sell the gift card in their store and customers can't use the gift card to make purchases.