> For the complete documentation index, see [llms.txt](https://docs.limio.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.limio.com/guides/feature-implementation-guides/guide-how-to-sell-subscription-gift-codes-in-limio-commerce/how-to-generate-gift-codes-in-bulk.md).

# Generate Gift Codes in Bulk

There are certain scenarios in which you may want to generate a lot of gift codes and purchasing individually isn't ideal.

We have a way for you to import a file with pre-generated gift codes to facilitate that task.

## To get started

* First you'll need to generate a CSV file with the list of gift codes and other attributes defined below
  * Check if there are maximum character and regular expression restrictions defined in your redemption flow before generating the codes
* Publish the offer that the gift codes use. The import finds only published offers. For an unpublished offer, each record fails with the error `didn't match any offer on the catalog`
* Request access from Limio to access the CSV ingestion bucket

## Prepping the file

1. **Check the file size to upload**\
   For reliability and performance we recommend that a file has *no more than 5,000 records*. Bigger files can cause data loss.
2. **Check the file structure**\
   Make sure the headers match as these are case sensitive. NB: the table below describes which fields are mandatory
3. **Name the file correctly**\
   Files to be uploaded for the general migration process need to have the following prefix: `Limio_gift_code_`. Do not put spaces in the file name. The file name must end with `.csv`.
4. **Make sure that each gift code is new**\
   The import does not check if a gift code already exists. If you upload the same file two times, Limio creates each gift code two times. Upload each file one time only.

## Processing the file

* Upload the file into the right CSV bucket (ie: SHARD.csv-ingestion.limio.com)
  * You can get this information from your Limio contact.
* Limio splits the file into batches of 1,000 and if your original file had 5,000 records for example, you'll see multiple files in the bucket being processed.
* Once the process is finished they'll be moved to the *processed* folder.

## Checking the outcome

* You can check progress by going into your Subscriptions page in the Limio Commerce app (<https://yourdomain.prod.limio.com/objects/subscriptions/limio>) which will show the orders that have been processed.
* Once the files have finished processing you'll see events for the associated events in the *Events* section in the Limio Commerce app.
  * Any errors will also appear in the *Events* section.
* Limio also writes an error file to the `errors` folder of the bucket. The file has one row for each record that failed, with the reason. If the file has only the header row, all the records were imported.
* A record with a missing mandatory field or an unknown offer creates nothing. After you correct the cause, you can upload the failed records again in a new file.

### CSV file structure

The headers are case sensitive.

| Header                                        | Type             | Mandatory | Description                                                                                                                                                                                                                                                                                       |
| --------------------------------------------- | ---------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Subscription_subscriptionExternalCorrelator` | string           | yes       | Subscription unique identifier - can be the source (legacy) value. It will also be used as Order Number to prevent duplicates if importing again same record. **IMPORTANT**: it needs to be the subscriptionNumber field exported to **Zuora** since is going to work as link for the integration |
| `Identity_zuoraAccountId`                     | string           | yes       | **Zuora** account id, used to link to an existing customer uploaded (it could be in Limio or uploaded via other migration file). If Limio finds no customer for the account id, it creates a placeholder customer for the record                                                                  |
| `Voucher_code`                                | string           | yes       | It's the code that the redeemer will use to get the subscription                                                                                                                                                                                                                                  |
| `Voucher_offerPath`                           | string           | yes       | Defines the path of the Limio offer to be mapped into the subscription. The path starts with `/`. Example: "/offers2/digital/annual". The offer must be published                                                                                                                                 |
| `Voucher_originalQuantity`                    | string (int)     |           | The original quantity for the gift code. If not specified 1 is assumed                                                                                                                                                                                                                            |
| `Voucher_usedQuantity`                        | string (int)     |           | The already used quantity for the gift code. If not specified 0 is assumed                                                                                                                                                                                                                        |
| `Voucher_expiryDate`                          | string (isodate) |           | Expiry date for the gift code/voucher, format: YYYYMMDD. If not specified the gift code expires 10 years after the import                                                                                                                                                                         |

Example:

```csv
Subscription_subscriptionExternalCorrelator,Identity_zuoraAccountId,Voucher_code,Voucher_offerPath,Voucher_originalQuantity,Voucher_usedQuantity,Voucher_expiryDate
GIFT000001,8a28b2f1900000000000000000000001,k3TgR8mWq2Z,/offers2/digital/annual,1,0,20271231
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.limio.com/guides/feature-implementation-guides/guide-how-to-sell-subscription-gift-codes-in-limio-commerce/how-to-generate-gift-codes-in-bulk.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
