Authentication
The Automatic Billing API uses a Kobana Account access token to authenticate every request.
The tokenβ
The token is an RS256 JWT issued by the Kobana Authorization Server (account.kobana.com.br). This API only verifies it, against the public key that server publishes β it holds no signing key and cannot issue any token. The org claim identifies your organization: all returned data is automatically scoped to it.
Requirements checked on every request:
| Claim | Requirement |
|---|---|
iss | The Authorization Server identifier, as a URL: https://account[.{env}].kobana.com.br |
aud | The URL of this API: https://api.billing[.{env}].kobana.com.br. It may be a list β the rule is contains, not equality |
exp | Required. A token with no expiration is rejected |
org | The Kobana account on whose behalf the token acts β it is what resolves the organization here, and it is required |
sub | The person (users.public_id). It goes to auditing and attribution; it scopes nothing |
jti | Unique token id β the basis of auditing |
:::caution Change from the API key
Until September 2026 the credential was a key created in the dashboard (kb_β¦), with a public prefix and a secret shown only once. The key was both the credential and what verified it β whoever read the key store could act as any organization, and every rotation was a conversation with a customer. Now the Authorization Server issues the token and the platform only verifies it. A key created under Settings β API no longer authenticates this API.
:::
The token is different between Sandbox and Production β the aud of one is not valid in the other. Do not reuse a token across environments.
How to send the tokenβ
Include the Authorization: Bearer <token> header in every request.
export KOBANA_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxx
curl -i \
-H "Authorization: Bearer $KOBANA_TOKEN" \
-H 'Content-Type: application/json' \
-H 'User-Agent: Meu Nome (meunome@example.com)' \
-X GET 'https://api.billing.sandbox.kobana.com.br/v1/organization'
Valid requestβ
With a valid token, the response carries the authenticated Organization's data.
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Request-Id: req_01HABCDEF
{
"id": "org_01HORG",
"name": "Minha Empresa",
"email": "contato@minhaempresa.com.br",
"document_type": "cnpj",
"document_number": "12345678000190",
"environment": "sandbox",
"created_at": "2026-01-01T00:00:00.000Z"
}
Invalid requestβ
A missing, malformed or expired token returns 401 Unauthorized.
curl -i \
-H "Authorization: Bearer tokeninvalido" \
-H 'Content-Type: application/json' \
-H 'User-Agent: Meu Nome (meunome@example.com)' \
-X GET 'https://api.billing.sandbox.kobana.com.br/v1/organization'
HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=utf-8
{
"error": {
"code": "invalid_token",
"message": "Token de acesso invΓ‘lido ou expirado."
}
}
Fine-grained codes help you find the error right away: invalid_token (missing, malformed or invalid signature), invalid_audience (token from another Kobana app) and unknown_organization β the latter is a 403: the token is valid, it is the organization that is not here.
If our Authorization Server is down, the response is 5xx, not 401. This is deliberate: a 401 would send you debugging a perfectly good credential during our outage. Try again in a moment.
:::note sub is not the tenant
sub is the person and org is the customer β they are uuids from different tables, so swapping them does not cause a format error. A token without org is rejected instead of falling back to sub: that fallback would match no organization and answer 403 on everything, with the symptom pointing at permissions rather than at the claim that was read.
:::
Scopesβ
Scopes are enforced on every request, and each request requires a single access level: what the method asks for (GET reads, DELETE deletes, POST/PUT/PATCH write), or what the endpoint declares when no method says it (bulk import and export). Every token needs a billing resource scope (billing/β¦) or all: it defines the reach, and the levels apply only within it.
The access levelsβ
| Level | Grants |
|---|---|
read | Read (GET, HEAD) β which the resource scope already grants on its own |
write | Read and write (POST, PUT, PATCH) |
delete | Deletion (DELETE), single or batch |
import | Bulk import |
export | Bulk export |
all | No level: it is the resource wildcard, same as billing/all (see below) |
One level never stands in for another. write does not delete, import or export; delete, import and export neither read nor write. Combine the levels your integration needs β read delete lists and deletes, read write delete does all three.
The level each endpoint requiresβ
| Endpoint | Level |
|---|---|
GET / HEAD | read |
POST / PUT / PATCH | write |
DELETE β every deletion is a DELETE, including the batch one (DELETE /v1/{resource}/bulk) and the one that only marks the record as deleted | delete |
POST /v1/nfes/import-barueri | import |
Bulk export β this API has none yet; the PDF or XML of one document (/invoices/{id}/pdf, /nfes/{id}/xml) is a read | export |
GET /v1/me | Any valid token |
Every DELETE is a deletion, and nothing but a deletion is a DELETE: archiving (POST β¦/archive), unarchiving (POST β¦/unarchive), deactivating (POST β¦/deactivate), closing (POST β¦/close) and canceling (POST β¦/cancel) are writes. A deletion is a soft delete whenever the record has history to preserve: it gets deleted_at and disappears from every read (lists, GET by id, filters), while the invoices, payments and NFS-e that reference it keep the reference.
:::caution October 2026 change
DELETErequiresdelete. Before, aDELETEalso acceptedwrite; a token with onlywritenow receives403 insufficient_scopewhen deleting. Request thedeletelevel in the Kobana Account for the integrations that delete.POST /v1/nfes/import-baruerirequiresimport;writeis not enough.DELETEnow deletes (soft delete,deleted_at) where it used to only change a status. Anyone who usedDELETEto archive, deactivate or close must call the dedicated route:
| Endpoint | Before | Now | For the old effect |
|---|---|---|---|
DELETE /v1/products/{id} | archived | deletes | POST /v1/products/{id}/archive |
DELETE /v1/plans/{id} | archived; ?hard=true deleted a draft | deletes (the hard parameter no longer exists) | POST /v1/plans/{id}/archive (new) |
DELETE /v1/companies/{id} | deactivated | deletes | POST /v1/companies/{id}/deactivate |
DELETE /v1/billing_accounts/{id} | closed (?reason=) and returned the account | deletes, along with payment methods, cards, portal users and files, and returns { "deleted": true } | POST /v1/billing_accounts/{id}/close |
DELETE /v1/customers/{id}/users/{user_id} | deleted the pending invitation; suspended the active user | deletes both | β |
DELETE /v1/service_items/{id} | deleted, or only deactivated if a tax rule used it | deletes | PATCH with is_active=false |
DELETE /v1/payment_methods/{id} | marked it removed | deletes (and stays removed where it appears through a relation) | β |
DELETE /v1/{products,plans}/bulk | deleted permanently | deletes (soft delete), same rules as the single DELETE | β |
A deleted record no longer appears in any GET β not even with a status filter. To keep querying it, archive instead of deleting.
- Endpoints that changed method β same JSON body, same response; the old endpoint no longer exists:
| Before | Now |
|---|---|
POST /v1/nfes/bulk-delete | DELETE /v1/nfes/bulk |
POST /v1/plans/bulk-delete | DELETE /v1/plans/bulk |
POST /v1/products/bulk-delete | DELETE /v1/products/bulk |
POST /v1/proposals/bulk-delete | DELETE /v1/proposals/bulk |
DELETE /v1/product_groups/{id}/archive (unarchive) | POST /v1/product_groups/{id}/unarchive |
DELETE /v1/subscription_item_changes/{id} (cancel scheduled change) | POST /v1/subscription_item_changes/{id}/cancel |
| ::: |
Token without a resource scopeβ
A token with no billing/β¦ scope and no all β only levels (read write) or only another app's resources (dunning/x write) β reaches no resource: every request receives 403 insufficient_scope, except GET /v1/me. Until November 2026 a levels-only token applied to every resource; request from the Kobana Account a token with the integration's resources, or with all.
all is not an access level. It works exactly like billing/all: it reaches every resource and grants no level. all alone reads everything and writes nothing; all write also writes, and deleting, importing or exporting still requires delete, import or export.
Token with resource scopesβ
A token that carries billing/β¦ scopes (the personal token created in the Kobana Account wizard, or that of an MCP client) has two orthogonal axes: the resource, always prefixed by the app (billing/subscriptions), and the level, an unprefixed global scope (write, delete, import, export). Resources define the reach, and levels only apply within it. Reading requires the resource; anything else requires the resource and the level.
| Group | Resource scopes |
|---|---|
| Customers and access | billing/customers, billing/companies, billing/portal_users, billing/dashboard_users, billing/team_roles |
| Catalog | billing/plans, billing/plan_groups, billing/products, billing/product_groups, billing/service_items |
| Subscriptions | billing/subscriptions, billing/subscription_changes, billing/subscription_item_changes, billing/plan_changes |
| Billing | billing/invoices, billing/payments, billing/payment_methods, billing/credits, billing/coupons |
| Tax | billing/nfes, billing/tax_rules, billing/tax_periods, billing/withholdings, billing/certificates |
| Proposals | billing/proposals, billing/proposal_templates |
| Account and usage | billing/organization, billing/billing_accounts, billing/usage |
| Resource wildcard | billing/all β reaches all resources, including those not on the list, and grants no level |
| Global levels | write (POST, PUT, PATCH), delete (DELETE), import (bulk import), export (bulk export) β apply to the resources the token reaches. all is not one of them: it counts as billing/all |
Three examples: billing/invoices reads invoices and does not write; billing/invoices write also creates, changes and cancels, and still neither deletes nor reaches subscriptions; billing/products write delete maintains the product catalog, batch deletion included.
Bank accounts, banks, Pix keys, holidays, late fee policies and credit purchases (/bank_accounts, /banks, /pix_keys, /holidays, /late_fee_policies, /credit_purchases) have no resource scope of their own: a token with resource scopes only reaches them with billing/all.
The granular form billing/invoices:write is an exception to the grammar, not the default format: it satisfies both axes for that one resource only, and exists for "reads one resource, writes another". billing/* is a registration wildcard and is never issued in a token β the comparison here is always literal.
A token with no billing/β¦ scope and no all reaches nothing beyond GET /v1/me, whatever levels it carries.
Insufficient scopeβ
A missing scope answers 403 insufficient_scope. details.granted carries the token's scopes, and details.required carries one minimal set of scopes that, added to the token's, would let the request through β not a list of alternatives: first the resource scope, if the token does not reach it (billing/{resource}, or billing/all off the catalogue), then the bare verb, if it is missing. It never carries all, and is never empty. A read write token deleting a customer:
HTTP/1.1 403 Forbidden
Content-Type: application/json; charset=utf-8
{
"error": {
"code": "insufficient_scope",
"message": "This token was not granted delete access. Authorize again with delete access to delete data.",
"details": { "required": ["billing/customers", "delete"], "granted": ["read", "write"] }
}
}
Other cases: billing/customers deleting a customer gets ["delete"]; billing/invoices write reading customers gets ["billing/customers"]; read reading /v1/bank_accounts, off the catalogue, gets ["billing/all"]. Reading your own approvals (GET /v1/operation_approvals) needs reach β any billing/β¦ or all β, and a token with none gets ["billing/all"].
GET /v1/me answers any valid token, whatever its scope β it is how you check the token you have.
Best practicesβ
- Never commit tokens to git. Use environment variables or vaults (AWS Secrets Manager, Vault, etc.).
- Use distinct tokens per integration (CRM, ERP, frontend, etc.) β it makes swapping one without taking down the others easier, and auditing by
jtistays readable. - Request the minimum scopes needed (principle of least privilege) β a resource with no verb when the integration only reads.
- Prefer short-lived tokens: this API does not consult a revocation list, so a leaked token is valid until its
exp. Replace the credential in the Kobana Account as soon as you learn of the leak. - HTTPS required β calls over HTTP are rejected.