Back to Piggy in Excel
SheetXAI logo
Piggy logo
Piggy · Excel Guide

Generate a Batch of Discount Vouchers From a Excel

2026-05-14
5 min read

The Scenario

It's the week before Black Friday and the loyalty program manager needs 500 single-use voucher codes ready to attach to outgoing customer emails. The promotion is set up in Piggy — the promo ID is confirmed. What's missing is the batch creation and the resulting code list, which needs to land in an Excel workbook before the email team can build their campaign.

The bad version:

  • Try to generate vouchers one at a time in the Piggy UI — that interface is not built for 500.
  • Go to the API documentation, find the batch creation endpoint, write a script, test it, get the auth working, parse the response, and export the codes into Excel-compatible format.
  • By the time the codes are ready, the window for the campaign setup has shrunk by a day.

The email send window is fixed. The codes need to exist before Thursday. Nobody budgeted a script-writing sprint for this.

The Easy Way: One Prompt in SheetXAI

SheetXAI is an AI agent that lives inside your Excel workbook. It connects to Piggy, submits the voucher batch creation, and writes the result — batch ID, status, and individual codes — directly back into the workbook.

Generate a batch of 250 Piggy vouchers for promotion 'summer_sale' and write each voucher code one per row into column A of the Excel sheet 'VoucherCodes', starting at row 2

What You Get

  • Row 1 of the 'VoucherCodes' worksheet gets the batch ID for reference.
  • Column A from row 2 onward fills with individual voucher codes, one per row, ready for mail merge.
  • If the batch is asynchronous, you get the batch ID and a PENDING status so you can poll for completion with a follow-up prompt.
  • Any codes that returned an error status are flagged inline so nothing is silently missing from the list.

What If the Data Is Not Quite Ready

You need individual codes written out row by row for mail merge

Create a batch of 500 Piggy vouchers for promotion 'promo_blackfriday_2025', then fetch each individual voucher code and write them one per row into column A of the 'VoucherCodes' sheet starting at row 2. Write the batch ID into cell B1

You're running multiple promotions and need codes separated by type

Create a batch of 300 vouchers for promotion 'promo_vip_nov' and a batch of 200 for 'promo_general_nov'. Write each batch's codes into separate worksheets named 'VIP Codes' and 'General Codes', one code per row starting at row 2

The promotion ID needs to be pulled from the workbook itself

Read the promotion ID from cell B2 and the quantity from cell C2 of the 'Config' sheet, create a Piggy voucher batch with those values, and write the returned batch ID into cell D2 and the status into cell E2

Create the batch, poll for codes, format for mail merge, and flag any that failed

Create a batch of 500 Piggy vouchers for promotion 'promo_blackfriday_2025', wait for the batch to complete, fetch all 500 individual codes, and write each code into column A of the 'VoucherCodes' sheet alongside the promotion name in column B. Flag any codes that returned an error status in column C. Write the total success and error count into cells E1 and F1

Combining the batch creation with the code retrieval and error flagging means you hand off a workbook the email team can import immediately.

Try It

Open an Excel workbook and Get the 7-day free trial of SheetXAI. Ask it to create your next Piggy voucher batch and write the codes directly into the worksheet. For related workflows, see how to validate existing voucher codes before a send or the full Piggy integration overview.

Stop memorizing formulas.
Tell your spreadsheet what to do.

Join 4,000+ professionals saving hours every week with SheetXAI.

Learn more