Overview
Codes are the stock inside a database: the keys, licenses, vouchers, or files Keysender delivers when an order is paid. The Code endpoints let your software top up a database in bulk, check what is available or already used, flag a code to go out first, and remove a code that should never be sent.
TL;DR
- Codes are the stock inside a database: text values or files, uploaded with
POST /code. - Send at most 1,000 codes per request; anything past that is silently dropped.
- List with
GET /codesand filters, flipstatus/sendfirstwithPUT /code, and remove an unused code withDELETE /code.
Before you start
Make sure you have:
- A bearer token from
POST /loginand the base URLhttps://panel.keysender.com/api/v1.0. - The
idof the database you are filling (see Managing inventory databases with the API).
A code has these fields: id, type (1 text, 2 file), value, status (0 available, 1 used), keyusage, sendfirst (1 to deliver before other codes), filename, and the optional unit_cost, currency, purchase_date, and expiration_date.
Steps
Upload text codes
- Send
POST /code?database_id=123with a JSON array of objects, one per code:
curl -X POST "https://panel.keysender.com/api/v1.0/code?database_id=123" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
-H "Content-Type: application/json" \
-d '[{"value": "AAAA-BBBB-CCCC"}, {"value": "DDDD-EEEE-FFFF", "unit_cost": 4.2, "currency": "EUR"}]'
- Send at most 1,000 codes per request. Codes beyond the first 1,000 in one request are not stored, and the response does not warn you, so batch larger uploads.
- The response is the array of stored codes with their new ids.
Upload a file as a code
- Send
POST /code?database_id=123&name=manual.pdfwith the raw file as the body and its real content type (for exampleContent-Type: application/pdf). Allowed types: PDF, JPG, PNG, GIF, TXT, CSV, TSV, XLS, MP3, EPUB. Maximum 80 MB. - The response is an array with one code of
type: 2andfilenameset.
List codes
- Send
GET /codes?database_id=123. Addpageandpagesize(maximum 1000), and filter withfilter=[{"status":0}]for available codes,[{"status":1}]for used ones, or[{"value":"AAAA"}]to find one.
Mark a code used, or send it first
- Send
PUT /codewith all three fields:{"id": 456, "status": 1, "sendfirst": 0}. Bothstatusandsendfirstmust be present even when only one changes.
Delete a code
- Send
DELETE /codewith{"id": 456}. Only an available code (status: 0) can be deleted; a used code stays for the order history.
Confirm it works
After an upload, GET /codes?database_id=123&filter=[{"status":0}] includes the new values, and the database's available count under Inventory in the panel has grown by the same number. With stock in place, record a sale against it with Creating transactions with the API.
Troubleshooting
| Symptom | Cause | Action |
|---|---|---|
| Fewer codes stored than sent | The request exceeded 1,000 codes | Send the remainder in a new request |
422 on the file upload |
The content type is not in the allowed list, or the file exceeds 80 MB | Use an allowed type and stay under 80 MB |
| A delete is refused | The code is already used | Used codes stay for order history and cannot be removed |
If it still is not working
Submit a ticket with the database id, the count you sent, and the response.
Quick answers
How many codes can I upload in one request?
1,000. Codes beyond the first 1,000 in a single request are not stored and the response does not warn you, so split larger uploads into batches and count the ids you get back.
How do I upload a file instead of text codes?
Send POST /code with database_id and name in the query and the raw file as the body, with its real content type such as application/pdf. The response is one code of type 2 with the filename set.
Can I delete a code that has already been delivered?
No. Only codes with status 0 (available) can be deleted. A used code stays so the order history remains complete.
Was this helpful?