Exporting Gift Cards
Exporting gift cards allows downloading a list of gift card codes to a CSV or an XLSX file. You can export all gift cards, filtered gift cards, or gift cards with specific IDs, but only unused cards will be exported. The link to download the file is sent by email to the requestor. An email with information about the problems is sent if any error occurs.
Export File Structure
The exported file contains one column with a code
header in the first row and gift card codes in the following rows, as shown below.
code |
---|
ABCD-EFGH-IJKL |
IJKL-ABCD-EFGH |
EFGH-ABCD-IJKL |
IJKL-EFGH-ABCD |
Exporting Gift Cards
Gift cards can be exported only by logged users with MANAGE_GIFT_CARD
permission.
Only unused gift card codes are exported.
To export gift cards, use exportGiftCards
mutation.
This mutation takes the following input:
scope
: determine which gift cards should be exported. You can choose between exporting all unused gift cards (ALL
), filtered gift cards (FILTER
) or selected IDs (IDS
). You can find more details in the next sections.filter
: defines filtering option. This field is optional but must be specified if your chooseFILTER
scope option.ids
: a list of products IDs to export. This field is optional but must be specified ifIDS
inscope
is chosen.fileType
: defines exported file type. You can choose betweenCSV
andXLSX
file.
As a result, this mutation returns ExportFile
object which is a Job
instance.
For details, look at export mutations descriptions.
Exporting All Gift Cards
The following example shows how to export all gift cards with all available fields to a CSV file.
mutation {
exportGiftCards(input: { scope: ALL, fileType: CSV }) {
exportFile {
id
status
createdAt
updatedAt
url
}
errors {
field
code
message
}
}
}
In the response, we get the workers information:
{
"data": {
"exportGiftCards": {
"exportFile": {
"id": "RXhwb3J0RmlsZTox",
"status": "PENDING",
"createdAt": "2020-06-05T09:15:42.924676+00:00",
"updatedAt": "2020-06-05T09:16:27.691838+00:00",
"url": ""
},
"errors": []
}
}
}
Once the task is finished, the url
field will contain the URL address of the exported file. If the User
triggers export, the link to the file will be sent by email to the requestor.
To check if the URL is ready, you can fetch ExportFile.
Applying Filters
To export only filtered gift cards you need to set the scope
to FILTER
and include the filter
parameter.
The following example only includes gift cards that have a birthday
tag.
mutation {
exportGiftCards(
input: { scope: FILTER, fileType: XLSX, filter: { tags: ["birthday"] } }
) {
exportFile {
id
status
createdAt
updatedAt
url
}
errors {
field
code
message
}
}
}
Exporting Gift Cards With Specified IDs
To export only gift cards with provided IDs, you need to set the scope
to IDS
and include the ids
parameter. Lets see an example:
mutation {
exportGiftCards(
input: {
scope: IDS
fileType: CSV
ids: ["R2lmdENhcmQ6MjU=", "R2lmdENhcmQ6MjY=", "R2lmdENhcmQ6Mjc="]
}
) {
exportFile {
id
status
createdAt
updatedAt
url
}
errors {
field
code
message
}
}
}