API keys
All API requests are authenticated using a secret key passed in the x-api-key header. There are three kinds, depending on how much one key should reach:
| Key | Prefix | Reaches | Where to create it |
|---|---|---|---|
| Organization key | sk_org_ | Every account in the organization, including accounts added later | Organization → API keys |
| Account key | sk_acct_ | Every product in one account | Organization → API keys, or Settings → API keys in the account |
| Product key | sk_ | One product | The product's Integration tab |
Organization and account keys are meant for your own integrations, for example an affiliate dashboard inside your product (see Affiliate dashboards). You can create several, name them, and revoke one without affecting the others.
All /api/v1/* endpointsKey format
| Key type | Prefix | Usage |
|---|---|---|
| Organization key | sk_org_ | Live server-side API calls for any product in the organization |
| Account key | sk_acct_ | Live server-side API calls for any product in the account |
| Product Secret Key | sk_ | Live server-side API calls for one product |
| Test Secret Key | sk_test_ | Selects sandbox mode on tracking endpoints only |
sk_test_ keys do not authenticate /api/v1 requests. Use your product's live secret key for the management API. Test keys only select sandbox on the tracking endpoints, including POST /events.
Security
A secret key reads, and unless it is read-only changes, your affiliate program. Never expose it in client-side code, Git repositories, or logs. Call the API from your server and send the browser only the data it should show.
Using your API key
Include the key in the x-api-key header with every request:
curl -X POST https://anderro.com/api/v1/affiliates \
-H "Content-Type: application/json" \
-H "x-api-key: sk_your_secret_key" \
-d '{"email": "[email protected]"}'
Organization and account keys
Owners and admins create these keys. An admin who is limited to some accounts can create keys for those accounts only.
- Open Organization → API keys (or Settings → API keys inside an account)
- Click Create key, name it, and choose what it works for, its access and an optional expiry
- Copy the key. It is shown once; Anderro stores only a hash of it
Access
| Access | Allows |
|---|---|
| Read-only | GET requests: affiliates, commissions, payouts, stats |
| Full access | Everything, including registering and removing affiliates, refunds, customer erasure and payout approval |
A read-only key that sends anything other than GET receives 403 This API key is read-only.
Choosing the product
Most endpoints act on one product. A product key already is its product. An organization or account key says which one with the X-Anderro-Product header (or the product_id query parameter):
curl https://anderro.com/api/v1/affiliates \
-H "x-api-key: sk_acct_your_key" \
-H "X-Anderro-Product: your_product_id"
GET /api/v1/products lists the product ids the key can reach. A key that reaches exactly one product may leave the header out. The stats endpoints can also total several products at once; see Get Stats.
Revoking
Click Revoke next to a key. Requests with it fail with 401 straight away. Keys also stop working when they expire, when their account is deactivated, or when the organization is deleted.
Finding your product key
- Log in to anderro.com
- Go to Products and select your SaaS product
- Open the Integration tab
- Your Secret Key is shown there - click to copy
Regenerating a product key
If your product key is compromised, you can regenerate it from the Integration tab. This immediately invalidates the old key - all requests using the old key will return 401.
Error responses
| Status | Error | Meaning |
|---|---|---|
401 | Missing x-api-key header | No API key was provided |
401 | Invalid API key format | Key doesn't start with sk_ |
401 | Invalid or revoked API key | Key doesn't match any active product, account or organization, or it was revoked or has expired |
403 | This API key is read-only | A read-only key sent a request that changes data |
400 | This API key reaches several products… | An organization or account key did not say which product to use |
404 | Product not found for this API key | The chosen product is outside the key's reach |