Skip to main content

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:

ClaimRequirement
issThe Authorization Server identifier, as a URL: https://account[.{env}].kobana.com.br
audThe URL of this API: https://api.billing[.{env}].kobana.com.br. It may be a list β€” the rule is contains, not equality
expRequired. A token with no expiration is rejected
orgThe Kobana account on whose behalf the token acts β€” it is what resolves the organization here, and it is required
subThe person (users.public_id). It goes to auditing and attribution; it scopes nothing
jtiUnique 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. :::

Check the environment

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​

LevelGrants
readRead (GET, HEAD) β€” which the resource scope already grants on its own
writeRead and write (POST, PUT, PATCH)
deleteDeletion (DELETE), single or batch
importBulk import
exportBulk export
allNo 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​

EndpointLevel
GET / HEADread
POST / PUT / PATCHwrite
DELETE β€” every deletion is a DELETE, including the batch one (DELETE /v1/{resource}/bulk) and the one that only marks the record as deleteddelete
POST /v1/nfes/import-barueriimport
Bulk export β€” this API has none yet; the PDF or XML of one document (/invoices/{id}/pdf, /nfes/{id}/xml) is a readexport
GET /v1/meAny 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

  • DELETE requires delete. Before, a DELETE also accepted write; a token with only write now receives 403 insufficient_scope when deleting. Request the delete level in the Kobana Account for the integrations that delete.
  • POST /v1/nfes/import-barueri requires import; write is not enough.
  • DELETE now deletes (soft delete, deleted_at) where it used to only change a status. Anyone who used DELETE to archive, deactivate or close must call the dedicated route:
EndpointBeforeNowFor the old effect
DELETE /v1/products/{id}archiveddeletesPOST /v1/products/{id}/archive
DELETE /v1/plans/{id}archived; ?hard=true deleted a draftdeletes (the hard parameter no longer exists)POST /v1/plans/{id}/archive (new)
DELETE /v1/companies/{id}deactivateddeletesPOST /v1/companies/{id}/deactivate
DELETE /v1/billing_accounts/{id}closed (?reason=) and returned the accountdeletes, 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 userdeletes bothβ€”
DELETE /v1/service_items/{id}deleted, or only deactivated if a tax rule used itdeletesPATCH with is_active=false
DELETE /v1/payment_methods/{id}marked it removeddeletes (and stays removed where it appears through a relation)β€”
DELETE /v1/{products,plans}/bulkdeleted permanentlydeletes (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:
BeforeNow
POST /v1/nfes/bulk-deleteDELETE /v1/nfes/bulk
POST /v1/plans/bulk-deleteDELETE /v1/plans/bulk
POST /v1/products/bulk-deleteDELETE /v1/products/bulk
POST /v1/proposals/bulk-deleteDELETE /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.

GroupResource scopes
Customers and accessbilling/customers, billing/companies, billing/portal_users, billing/dashboard_users, billing/team_roles
Catalogbilling/plans, billing/plan_groups, billing/products, billing/product_groups, billing/service_items
Subscriptionsbilling/subscriptions, billing/subscription_changes, billing/subscription_item_changes, billing/plan_changes
Billingbilling/invoices, billing/payments, billing/payment_methods, billing/credits, billing/coupons
Taxbilling/nfes, billing/tax_rules, billing/tax_periods, billing/withholdings, billing/certificates
Proposalsbilling/proposals, billing/proposal_templates
Account and usagebilling/organization, billing/billing_accounts, billing/usage
Resource wildcardbilling/all β€” reaches all resources, including those not on the list, and grants no level
Global levelswrite (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 jti stays 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.