Overview
This is the end-to-end path for a store, marketplace, or back office that Keysender does not connect to natively: your software records each sale through the API and Keysender delivers the code. It takes four calls to go from a fresh API key to a buyer holding a working code, and the same calls run every day after that.
TL;DR
- Four calls take you from a fresh API key to a delivered code: log in, create a database, load codes, record the sale.
- Reuse one bearer token per integration, and keep the API secret server-side only.
- There is no deduplication on
addcustom, so store every transactionidyou receive before doing anything else.
Before you start
Make sure you have:
- Access to your Keysender vendor account, with your API key and secret from Account > Settings > API Information.
- A default email template in Templates, so deliveries have something to send.
- Credits on the account (one per dispatch).
If your platform is one Keysender already connects to, use that integration instead; see Connected channels. Guides for popular automation platforms are being published as those integrations are released.
Steps
Log in once
POST /loginwithapi_keyandapi_secret, store theaccess_token, and send it asAuthorization: Bearer ...on every call. Details: Getting started with the Keysender API.
Create the product's database
POST /databasewithname,sku, andtype: 0. Use your own product code as thesku; a repeat call with the same SKU returns the same database, so you can run it on every sync. Details: Managing inventory databases with the API.
Load stock
POST /code?database_id=...with an array of{"value": "..."}objects, 1,000 per request at most. Details: Uploading and managing codes with the API.
Record the sale
- When a buyer pays,
POST /transaction/addcustomwithpayer,quantity,database_id,amount,currency, andname. Keysender picks the codes, sends them with your template, and spends a credit. - Store the returned transaction
idagainst your order immediately. There is no deduplication: a retried call delivers again. Details: Creating transactions with the API.
Verify
GET /transaction/{id}/inventoryshows exactly which codes went out, and Transactions in the panel shows the same sale.
Keep it safe
- Keep the API secret on your server only. Never place it in a browser, a mobile app, or a public repository.
- Reuse one token per integration instead of logging in before each request, and call
GET /logoutwhen you retire a token. - Stay under 600 requests per minute; on
429, wait and retry with the same body only for reads, never foraddcustom. - Log every transaction
idyou receive. It is the only handle you have on a delivery.
Confirm it works
A test order placed in your own system ends with a delivery email in the buyer's inbox, a transaction under Transactions in the panel, and the database's available count one lower.
Troubleshooting
| Symptom | Cause | Action |
|---|---|---|
| The buyer got nothing | The database had no available codes, or the account had no credits | Check quantity_sent on the transaction, the database's available count, and the credit balance |
| The buyer got two emails | The same sale was sent twice | Use the stored id to make retries safe; never retry a call that already returned 200 |
401 mid-way |
The token expired or was logged out | Log in again and continue |
If it still is not working
Submit a ticket with the transaction id and the time of the calls.
Quick answers
When should I use the API instead of a connected channel?
When Keysender does not connect natively to the store or marketplace you sell on. For channels it does connect to, the built-in integration records the sale and delivers without any code on your side.
How many calls does a first delivery take?
Four: log in, create the product's database, upload codes, and record the sale with /transaction/addcustom. After that, only the sale call runs per order, plus code uploads as stock is replenished.
What must my integration never do?
Never place the API secret in a browser, mobile app, or public repository; never retry a transaction call that already returned 200; and never log in before every request when one token will do.
Was this helpful?