Back to Piggy in Google Sheets
SheetXAI logo
Piggy logo
Piggy · Google Sheets Guide

Generate a Batch of Discount Vouchers From a Google Sheet

2026-05-14
5 min read

The Scenario

It's the week before Black Friday and the loyalty program manager on your team needs 500 single-use voucher codes ready to attach to outgoing customer emails. The promotion is set up in Piggy — promo ID is ready. What's missing is the batch creation and the code list.

The bad version:

  • Try to generate vouchers one at a time in the Piggy UI — that interface isn't 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 save the batch ID somewhere useful.
  • By the time you have the codes, you've spent more time on the infrastructure than on the promotion itself.

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 Google Sheet. It connects to Piggy, submits the voucher batch creation, and writes the result — batch ID, status, and individual codes — directly back into the sheet.

Create a batch of 500 vouchers in Piggy for promotion ID 'promo_blackfriday_2025' and write the batch ID and PENDING status into cells A1 and B1 of this sheet

What You Get

  • Cell A1 receives the Piggy batch ID for tracking and reference.
  • Cell B1 shows the initial status returned by Piggy — typically PENDING or QUEUED.
  • If Piggy returns individual voucher codes synchronously, SheetXAI writes them one per row starting at row 2 so you have the full list immediately.
  • If the batch is asynchronous, you get the batch ID and can poll for completion with a follow-up prompt.

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 starting at row 2

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 vouchers for promotion 'promo_general_nov'. Write each batch ID and code count into columns A and B, rows 1 and 2 respectively. Write all codes into column C — VIP codes first, then general codes, with a header row labeling each group

The promotion ID needs to be pulled from the sheet itself

Read the promotion ID from cell B2 and the quantity from cell C2, 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 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 ready-to-import CSV instead of a half-finished batch ID.

Try It

Open a Google Sheet 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 sheet. 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