GiftWeb Voucher API
Buy gift vouchers automatically from your own website, app or billing system. Each API call delivers exactly one voucher and deducts its price from your prepaid wallet.
| Base URL | |
|---|---|
| Format | JSON request and response, UTF-8 |
| Currency | INR. Prices and balances are strings with 2 decimals, e.g. "490.00" |
| Time | sold_at is UTC (YYYY-MM-DD HH:MM:SS) |
Authentication
Create an API key in your dashboard under API Keys. The key is shown only once — store it safely. Send it in the X-API-Key header on every request:
X-API-Key: gv_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Integration flow
- Your customer pays you on your website/app.
- After payment succeeds, your server calls
POST /v1/purchasewith the productskuand your own unique order id. - You receive the voucher
code(andpinif any) in the response. The price is deducted from your wallet. - Deliver the code to your customer (screen / email / SMS / WhatsApp).
- If the call times out or fails with a network error, retry with the same
order_id— you'll get the same voucher, never charged twice.
List products
Products you can buy, your price and current stock.
{
"success": true,
"products": [
{ "sku": "AMAZON-500", "name": "Amazon Pay Gift Card 500", "brand": "Amazon",
"denomination": 500, "currency": "INR", "price": "490.00", "in_stock": 132 }
]
}
Wallet balance
{ "success": true, "wallet_balance": "12450.00", "currency": "INR" }
Buy a voucher
| Field | Type | Description | |
|---|---|---|---|
sku | string | required | Product SKU from /v1/products |
order_id | string | required | Your unique order/transaction id (max 100 chars). Used for safe retries. |
customer_ref | string | optional | Your customer's email / phone / user id, for your records (max 200 chars) |
Request
POST /v1/purchase
Content-Type: application/json
X-API-Key: gv_live_xxx
{ "sku": "AMAZON-500", "order_id": "ORD-10045", "customer_ref": "rahul@example.com" }
Response — 201 Created (new purchase) / 200 OK (repeat of same order_id)
{
"success": true,
"order_id": "ORD-10045",
"replayed": false,
"voucher": {
"voucher_id": 1841,
"sku": "AMAZON-500",
"product_name": "Amazon Pay Gift Card 500",
"brand": "Amazon",
"denomination": 500,
"currency": "INR",
"code": "AMZ5-QWER-TYUI-0003",
"pin": "345678",
"expiry_date": "2027-03-31"
},
"price": "490.00",
"wallet_balance": "11960.00",
"customer_ref": "rahul@example.com",
"sold_at": "2026-11-21 06:31:22"
}
pin and expiry_date may be null when the voucher has none. replayed: true means this order_id was already fulfilled and you are seeing the same voucher again (no new charge).
Get an order
Fetch a voucher you already bought, using the same order_id. Returns the same body as a purchase with replayed: true, or 404 ORDER_NOT_FOUND.
Retries & idempotency
- Each
order_idcan deliver only one voucher, per API key. - Calling again with the same
order_idandskureturns the same voucher and does not charge again — even if two requests arrive at the same moment. - Using the same
order_idwith a differentskureturns409 ORDER_ID_REUSED. - Recommended: on timeout / 5xx, retry up to 3 times with the same order_id (wait 1s, 3s, 10s).
Errors
Errors return "success": false with a machine-readable code:
{ "success": false, "error": { "code": "OUT_OF_STOCK", "message": "No vouchers available for AMAZON-500" } }
| HTTP | code | Meaning / what to do |
|---|---|---|
| 400 | BAD_SKU, BAD_ORDER_ID, BAD_JSON | Fix the request |
| 401 | UNAUTHORIZED | Missing, wrong or disabled API key |
| 402 | INSUFFICIENT_BALANCE | Wallet balance is lower than the price. Recharge, then retry with the same order_id |
| 403 | ACCOUNT_DISABLED | Your account is disabled — contact admin |
| 404 | SKU_NOT_FOUND | Unknown or inactive product |
| 404 | ORDER_NOT_FOUND | No voucher for this order_id |
| 409 | OUT_OF_STOCK | No voucher available now. Nothing was charged — refund your customer or try later |
| 409 | PRICE_NOT_SET | Product is not on sale yet |
| 409 | ORDER_ID_REUSED | This order_id was already used for another SKU |
| 500 | INTERNAL | Server error — retry with the same order_id |
Code examples
curl -X POST "/v1/purchase" \
-H "X-API-Key: $VOUCHER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"sku":"AMAZON-500","order_id":"ORD-10045","customer_ref":"rahul@example.com"}'
// Node.js 18+
async function buyVoucher(sku, orderId, customerRef) {
for (let attempt = 0; attempt < 3; attempt++) {
try {
const res = await fetch('/v1/purchase', {
method: 'POST',
headers: { 'content-type': 'application/json', 'x-api-key': process.env.VOUCHER_API_KEY },
body: JSON.stringify({ sku, order_id: orderId, customer_ref: customerRef }),
});
const data = await res.json();
if (data.success) return data.voucher; // { code, pin, expiry_date, ... }
if (res.status < 500) throw new Error(data.error.code); // OUT_OF_STOCK, INSUFFICIENT_BALANCE, ...
} catch (e) {
if (!/fetch failed|network/i.test(e.message)) throw e;
}
await new Promise((r) => setTimeout(r, [1000, 3000, 10000][attempt]));
}
throw new Error('Voucher API not reachable');
}
<?php
$ch = curl_init('/v1/purchase');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 20,
CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'X-API-Key: ' . getenv('VOUCHER_API_KEY')],
CURLOPT_POSTFIELDS => json_encode(['sku' => 'AMAZON-500', 'order_id' => $orderId, 'customer_ref' => $email]),
]);
$data = json_decode(curl_exec($ch), true);
if (!empty($data['success'])) {
$code = $data['voucher']['code'];
$pin = $data['voucher']['pin'];
} else {
$err = $data['error']['code'] ?? 'NETWORK'; // retry same $orderId on NETWORK / INTERNAL
}
import os, requests
r = requests.post(
"/v1/purchase",
headers={"X-API-Key": os.environ["VOUCHER_API_KEY"]},
json={"sku": "AMAZON-500", "order_id": order_id, "customer_ref": email},
timeout=20,
)
data = r.json()
if data["success"]:
code, pin = data["voucher"]["code"], data["voucher"]["pin"]
else:
print(data["error"]["code"], data["error"]["message"])
Security checklist
- Keep the API key in a server environment variable, never in source code, browser or app.
- Call
/v1/purchaseonly after your payment is confirmed (verify the payment gateway signature/webhook). - Use your payment/order id as
order_idso a retry can never double-buy. - Use a separate key per website/app so you can disable one without affecting others.
- Check
/v1/balanceregularly and keep enough balance to avoidINSUFFICIENT_BALANCE.
Need help? Contact your Rivvo account manager.
© Rivvo Digital Services Private Limited. All rights reserved.