Skip to main content
Skip to main content

AdminGiftCardsResource

This class is used to send requests to Admin Gift Card API Routes. All its method are available in the JS Client under the medusa.admin.giftCards property.

All methods in this class require authentication.

Admins can create gift cards and send them directly to customers, specifying options like their balance, region, and more. These gift cards are different than the saleable gift cards in a store, which are created and managed through AdminProductsResource.

Related Guide: How to manage gift cards.

Methods

create

Create a gift card that can redeemed by its unique code. The Gift Card is only valid within one region.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.giftCards.create({
region_id
})
.then(({ gift_card }) => {
console.log(gift_card.id);
})

Parameters

payloadAdminPostGiftCardsReqRequired
The gift card to be created.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminGiftCardsRes>Required
Resolves to the gift card's details.

update

Update a gift card's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.giftCards.update(giftCardId, {
region_id
})
.then(({ gift_card }) => {
console.log(gift_card.id);
})

Parameters

idstringRequired
The ID of the gift card.
The attributes to update in the gift card.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminGiftCardsRes>Required
Resolves to the gift card's details.

delete

Delete a gift card. Once deleted, it can't be used by customers.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.giftCards.delete(giftCardId)
.then(({ id, object, deleted }) => {
console.log(id);
})

Parameters

idstringRequired
The ID of the gift card.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<DeleteResponse>Required
Resolves to the deletion operation's details.

retrieve

Retrieve a gift card's details.

Example

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.giftCards.retrieve(giftCardId)
.then(({ gift_card }) => {
console.log(gift_card.id);
})

Parameters

idstringRequired
The ID of the gift card.
customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Returns

ResponsePromiseResponsePromise<AdminGiftCardsRes>Required
Resolves to the gift card's details.

list

Retrieve a list of gift cards. The gift cards can be filtered by fields such as q passed in the query parameter. The gift cards can also paginated.

Example

To list gift cards:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.giftCards.list()
.then(({ gift_cards, limit, offset, count }) => {
console.log(gift_cards.length);
})

By default, only the first 50 records are retrieved. You can control pagination by specifying the limit and offset properties:

import Medusa from "@medusajs/medusa-js"
const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 })
// must be previously logged in or use api token
medusa.admin.giftCards.list({
limit,
offset
})
.then(({ gift_cards, limit, offset, count }) => {
console.log(gift_cards.length);
})

Parameters

customHeadersRecord<string, any>Required
Custom headers to attach to the request.

Default: {}

Filters and pagination configurations to apply on the retrieved gift cards.

Returns

ResponsePromiseResponsePromise<AdminGiftCardsListRes>Required
Resolves to the list of gift cards with pagination fields.
Was this section helpful?