Documentation
Feedback
Guides
API Reference

Guides
Integration Guides
Gift Card
Managing VTEX gift cards

This guide describes how to manage VTEX native gift cards from the VTEX gift card provider through the GiftCard API. With this API, you can perform the following actions:

You can also manage VTEX gift cards using your store Admin. For more information, see Setting up Gift Cards.

Creating a VTEX gift card

To create a VTEX gift card, you can use the Create GiftCard endpoint. In this request, you must send the information of the gift card you want to create.

POST

https://{accountName}.{environment}.com.br/api/giftcards

Request body


_10
{
_10
"relationName": "loyalty-program-test",
_10
"expiringDate": "2024-01-01T00:00:00",
_10
"caption": "Vtex Loyalty Test",
_10
"profileId": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff",
_10
"restrictedToOwner": false,
_10
"currencyCode": "BRL",
_10
"multipleCredits": true,
_10
"multipleRedemptions": false
_10
}

The endpoint will return some of the previously sent detailsand new information about the created gift card, such as:

  • "id": gift card identification.
  • "redemptionToken": gift card redemption token.
  • "redemptionCode": gift card redemption code.
  • "balance": gift card balance.
  • "emissionDate": gift card issue date.
  • "transaction": transaction code for the create gift card operation.

Response body


_15
{
_15
"id": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74",
_15
"redemptionToken": "COCW-OZYZ-BEXN-TIMU",
_15
"redemptionCode": "COCW-OZYZ-BEXN-TIMU",
_15
"balance": 0.0,
_15
"relationName": "loyalty-program-test",
_15
"emissionDate": "2023-08-23T16:20:01.0479856Z",
_15
"expiringDate": "2024-01-01T00:00:00",
_15
"caption": "Vtex Loyal Test",
_15
"currencyCode": "BRL",
_15
"discount": false,
_15
"transaction": {
_15
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions"
_15
}
_15
}

You can also access your store Admin (Promotions > Gift Cards) to confirm that the new gift card was created.

{"base64":"  ","img":{"width":1816,"height":203,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":71810,"url":"https://raw.githubusercontent.com/vtexdocs/dev-portal-content/main/docs/guides/Integration-Guides/gift-card-integration-guide/managing-vtex-gift-cards_1.png"}}

All gift cards created via API have no balance (value 0). You can add balance amounts to new gift cards through the Create GiftCard Transaction endpoint or the VTEX Admin.

Checking VTEX gift card details

When you want to check details about a specific gift card, you can use the Get GiftCard by ID endpoint. In this request, you must send the gift card identification (giftCardId) as a path parameter.

See an example below using gift card 92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74:

GET

https://{accountName}.{environment}.com.br/api/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74

Response body


_15
{
_15
"id": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74",
_15
"redemptionToken": "COCW-OZYZ-BEXN-TIMU",
_15
"redemptionCode": "COCW-OZYZ-BEXN-TIMU",
_15
"balance": 0.0,
_15
"relationName": "loyalty-program-test",
_15
"emissionDate": "2023-08-23T16:20:01.047",
_15
"expiringDate": "2024-01-01T00:00:00",
_15
"caption": "Vtex Loyal Test",
_15
"currencyCode": "BRL",
_15
"discount": false,
_15
"transaction": {
_15
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions"
_15
}
_15
}

You can also check the information of a VTEX gift card using the VTEX Admin. For more information, go to Promotions > Gift Cards > Search or Filter Results.

Creating VTEX gift card transactions

A gift card transaction is a record of an operation that changes the gift card balance, such as a purchase or a refund. To change balance values, you can use the Create GiftCard Transaction endpoint.

The sections below show a simulation of how to make the following changes to a gift card balance:

  • Add 500 USD
  • Spend 120 USD

Adding balance to a gift card

You can use the Create GiftCard Transaction endpoint to add balance to a gift card. In this request, you must send the gift card identification (giftCardId) as a path parameter.

See an example below using gift card 92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74.

POST

https://{accountName}.{environment}.com.br/api/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions

To indicate that you wish to add 500 USD to your balance, send "Credit" in the "operation" field and 500 in the "value" field.

Request body


_10
{
_10
"operation": "Credit",
_10
"value": 500,
_10
"description": "Opening balance",
_10
"redemptionToken": "COCW-OZYZ-BEXN-TIMU",
_10
"redemptionCode": "COCW-OZYZ-BEXN-TIMU",
_10
"requestId": "1"
_10
}

Response body


_10
{
_10
"cardId": "74",
_10
"id": "465f2d7370f349879f4c194ac81d8e98",
_10
"_self": {
_10
"href": "cosmetics2/giftcards/74/transactions/465f2d7370f349879f4c194ac81d8e98"
_10
}
_10
}

To confirm the new gift card balance, use the Get GiftCard by ID endpoint or the Admin dashboard.

Response body


_15
{
_15
"id": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74",
_15
"redemptionToken": "COCW-OZYZ-BEXN-TIMU",
_15
"redemptionCode": "COCW-OZYZ-BEXN-TIMU",
_15
"balance": 500.0000,
_15
"relationName": "loyalty-program-test",
_15
"emissionDate": "2023-08-23T16:20:01.047",
_15
"expiringDate": "2024-01-01T00:00:00",
_15
"caption": "Vtex Loyal Test",
_15
"currencyCode": "BRL",
_15
"discount": false,
_15
"transaction": {
_15
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions"
_15
}
_15
}

Admin

{"base64":"  ","img":{"width":1817,"height":199,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":73771,"url":"https://raw.githubusercontent.com/vtexdocs/dev-portal-content/main/docs/guides/Integration-Guides/gift-card-integration-guide/managing-vtex-gift-cards_2.png"}}

Removing balance from a gift card

To remove balance from a gift card, you must also use the Create GiftCard Transaction endpoint and send the gift card identification (giftCardId) as a path parameter.

See an example below using gift card 92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74.

POST

https://{accountName}.{environment}.com.br/api/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions

To indicate that you wish to remove 120 USD from your balance, send the information "Debit" in the "operation" field and 120 in the "value" field.

Request body


_10
{
_10
"operation": "Debit",
_10
"value": 120,
_10
"description": "Payment of order 5555",
_10
"redemptionToken": "COCW-OZYZ-BEXN-TIMU",
_10
"redemptionCode": "COCW-OZYZ-BEXN-TIMU",
_10
"requestId": "2"
_10
}

Response body


_10
{
_10
"cardId": "74",
_10
"id": "c2b69a5990404a11b26888964bed3868",
_10
"_self": {
_10
"href": "cosmetics2/giftcards/74/transactions/c2b69a5990404a11b26888964bed3868"
_10
}
_10
}

Whenever you create a new transaction, you must send a requestId different from the ones previously used for that gift card. Transactions that have a requestId value previously used on the same gift card will not be completed. Example: After creating the first credit transaction, in which you used the value "1" for requestId, you create a debit transaction with requestId equal to "2". Any other transaction for this gift card must be created with values different from "1" and "2" in the requestId.

To confirm the new gift card balance, use the Get GiftCard by ID endpoint or Admin dashboard.

Response body


_15
{
_15
"id": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74",
_15
"redemptionToken": "COCW-OZYZ-BEXN-TIMU",
_15
"redemptionCode": "COCW-OZYZ-BEXN-TIMU",
_15
"balance": 380.0000,
_15
"relationName": "loyalty-program-test",
_15
"emissionDate": "2023-08-23T16:20:01.047",
_15
"expiringDate": "2024-01-01T00:00:00",
_15
"caption": "Vtex Loyal Test",
_15
"currencyCode": "BRL",
_15
"discount": false,
_15
"transaction": {
_15
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions"
_15
}
_15
}

Admin

{"base64":"  ","img":{"width":1819,"height":200,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":73925,"url":"https://raw.githubusercontent.com/vtexdocs/dev-portal-content/main/docs/guides/Integration-Guides/gift-card-integration-guide/managing-vtex-gift-cards_3.png"}}

Checking VTEX gift card transactions

You can use the List All GiftCard Transactions endpoint to check all transactions performed on a gift card. In this request, you must send the gift card identification (giftCardId) as a path parameter.

See an example below using gift card 92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74.

GET

https://{accountName}.{environment}.com.br/api/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions

Response body showing information from two transactions:


_16
[
_16
{
_16
"cardId": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74",
_16
"id": "c2b69a5990404a11b26888964bed3868",
_16
"_self": {
_16
"href": "cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions/c2b69a5990404a11b26888964bed3868"
_16
}
_16
},
_16
{
_16
"cardId": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74",
_16
"id": "465f2d7370f349879f4c194ac81d8e98",
_16
"_self": {
_16
"href": "cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions/465f2d7370f349879f4c194ac81d8e98"
_16
}
_16
}
_16
]

If you use this endpoint to request details for a new gift card (which does not yet contain transactions), the response body will be empty.

Accessing information from a gift card transaction

To get information about a specific gift card transaction, you can use the Get GiftCard Transaction by ID endpoint. In this request, you must send the gift card identification (giftCardId) and transaction operation (transactionId) identification as path parameters.

The transactionID value used in this request is the same id value obtained from the response body of the List All GiftCard Transactions endpoint. For more information, see the Checking VTEX gift card transactions section.

See an example below using gift card 92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74 and transaction operation 18f71495d720497cb77dfc521f75087.

GET

https://{accountName}.{environment}.com.br/api/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_73/transactions/18f71495d720497cb77dfc521f750877

Response body


_16
{
_16
"value": 58.0,
_16
"description": "Add 58 BRL",
_16
"date": "2023-08-22T22:16:23.2974622Z",
_16
"requestId": "10",
_16
"settlement": {
_16
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_73/transactions/18f71495d720497cb77dfc521f750877/settlements"
_16
},
_16
"cancellation": {
_16
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_73/transactions/18f71495d720497cb77dfc521f750877/cancellations"
_16
},
_16
"authorization": {
_16
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_73/transactions/18f71495d720497cb77dfc521f750877/authorization"
_16
},
_16
"operation": "Credit"
_16
}

Cancelling a VTEX gift card transaction

To partially or completely cancel a value assigned in a transaction (credit or debit), you can use the Cancel GiftCard Transaction endpoint. In this request, you must send the gift card identification (giftCardId) and transaction operation (transactionId) identification as path parameters.

The transactionId value used in this request is the same id value obtained from the response body of the List All GiftCard Transactions endpoint. For more information, see the Checking VTEX gift card transactions section.

The example below shows how to partially cancel a debit transaction (c2b69a5990404a11b26888964bed3868). The transaction value is 120 USD and the canceled amount will be 20 USD. The gift card used is 92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74 (current balance of 380 USD).

POST

https://{accountName}.{environment}.com.br/api/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions/c2b69a5990404a11b26888964bed3868/cancellations

To indicate that you want to cancel the amount of 20 USD in the debit transaction, send 20 in the "value" field.

Request body


_10
{
_10
"value": 20,
_10
"requestId": "4"
_10
}

Response body


_10
{
_10
"oid": "a1e7edfb72d74bfa960cdbc2eb9471ce",
_10
"value": 20.0,
_10
"date": "2023-08-23T17:28:39.7212872Z"
_10
}

To confirm the new gift card balance, use the Get GiftCard by ID endpoint or the Admin dashboard.

Response body


_15
{
_15
"id": "92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74",
_15
"redemptionToken": "COCW-OZYZ-BEXN-TIMU",
_15
"redemptionCode": "COCW-OZYZ-BEXN-TIMU",
_15
"balance": 400.0000,
_15
"relationName": "loyalty-program-test",
_15
"emissionDate": "2023-08-23T16:20:01.047",
_15
"expiringDate": "2024-01-01T00:00:00",
_15
"caption": "Vtex Loyal Test",
_15
"currencyCode": "BRL",
_15
"discount": false,
_15
"transaction": {
_15
"href": "/cosmetics2/giftcards/92de2449-0e02-4ca9-a4aa-a09cc9d8f7ff_74/transactions"
_15
}
_15
}

Admin

{"base64":"  ","img":{"width":1817,"height":195,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":72401,"url":"https://raw.githubusercontent.com/vtexdocs/dev-portal-content/main/docs/guides/Integration-Guides/gift-card-integration-guide/managing-vtex-gift-cards_4.png"}}

When a debit transaction is canceled, the canceled amount is credited to the total gift card balance. Likewise, when a credit transaction is canceled, the canceled amount is debited from the total gift card balance.

Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page