Authentication
EmiteCR accepts three credentials on the same endpoints. Send one per request.
| Credential | Header | Who uses it |
|---|---|---|
| API key | x-api-key: ec_live_… |
Your backend: a point of sale, an online store, an ERP |
| JWT | Authorization: Bearer <token> |
People signed in to an app (the EmiteCR web app uses it) |
| Partner key | x-partner-key: ecp_live_… |
Products that provision companies — see the Partner API |
Every authenticated request acts on one company (the tenant). An API key
belongs to exactly one company, so you never send a tenant id. If a request
carries both x-api-key and Authorization, the API key is used.
API keys
Section titled “API keys”A key belongs to one company and one environment, both fixed when it is created:
| Prefix | Environment | Its documents |
|---|---|---|
ec_test_… |
sandbox | Go to Hacienda’s test environment. No fiscal value; free |
ec_live_… |
production | Real fiscal documents |
The full key has the form <prefix>_<id>_<secret>. EmiteCR stores only a hash
of the secret, so the key is shown once, when it is created. If it is lost,
rotate it or create another one.
Create a key
Section titled “Create a key”In the EmiteCR web app, open Developers → API keys and press Create API key. Creating, rotating and revoking keys is reserved to people whose role includes API key management — the company’s owner and its admins. Choose:
- Descriptive name — up to 80 characters, to recognize it later. Two
active keys of the same environment cannot share a name
(
409 API_KEY_NAME_TAKEN); a revoked key frees its name. - Environment — “Sandbox” or “Production”. It cannot be changed later; to move an integration to production, create a production key.
- Expiry — “30 days”, “90 days”, “1 year” or “No expiry”. After it, the key
is rejected with
401. - Scopes — what the key may do (below). Start from the Issue documents preset.
A company can have as many keys as it needs. One per system — or per point of sale — lets you revoke one without stopping the others.
The same operation is available over the API to a signed-in owner or admin. A key can never create another key:
curl -X POST https://api.emite.cr/v1/auth/api-keys \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{ "name": "POS register 1", "environment": "sandbox", "scopes": ["invoices:read", "invoices:write", "invoices:sign", "invoices:submit", "invoices:export"], "expiresAt": "2027-10-21T00:00:00.000Z" }'201 returns the key’s metadata and rawKey — the only time the full key is
ever returned:
{ "id": "019a0c73-5c07-7bb5-8b9e-d20f16537e42", "name": "POS register 1", "prefix": "ec_test", "environment": "sandbox", "lastFour": "7e42", "scopes": ["invoices:read", "invoices:write", "invoices:sign", "invoices:submit", "invoices:export"], "status": "active", "createdAt": "2026-10-21T15:04:05.000Z", "lastUsedAt": null, "expiresAt": "2027-10-21T00:00:00.000Z", "revokedAt": null, "createdByUserId": "…", "createdByName": "Ana Rojas", "rawKey": "ec_test_019a0c73-5c07-7bb5-8b9e-d20f16537e42_aBcDeF…"}scopes is required and cannot be empty (400 API_KEY_SCOPES_REQUIRED).
Use a key
Section titled “Use a key”Send it on every request, in the x-api-key header:
curl "https://api.emite.cr/v1/invoices?pageSize=1" \ -H "x-api-key: $EMITECR_API_KEY"Sandbox and production keys use the same base URL (https://api.emite.cr/v1):
the key decides the environment.
Keep the key on your server — in an environment variable or a secret manager.
Never put it in a web page, a mobile app or a device in the store: anyone who
holds it can issue documents in the company’s name. A key that is malformed,
unknown or carries the wrong secret is rejected with 401 UNAUTHORIZED, always
the same. That a key was revoked (401 API_KEY_REVOKED) or expired
(401 API_KEY_EXPIRED) is told only to whoever sends its full secret: a key’s
id, which shows in the key list, does not reveal its status.
Scopes
Section titled “Scopes”Every key carries a list of scopes, and every endpoint requires some. A request
without them is refused with 403 INSUFFICIENT_SCOPE, naming the missing ones
in params.required. A scope never implies another one — invoices:write does
not include invoices:read.
Issuing documents takes four scopes, and one more to download their XML. The five are what the Issue documents preset selects:
| Scope | Allows |
|---|---|
invoices:write |
Create a draft (POST /v1/invoices); delete or schedule a draft |
invoices:sign + invoices:submit |
Sign it and send it to Hacienda (POST /v1/invoices/:id/sign, POST /v1/hacienda/submit/:id). The two are always required together: a signed document always reaches Hacienda |
invoices:read |
Read documents, their status and PDF (GET /v1/invoices…, GET /v1/hacienda/status/:clave) |
invoices:export |
Download a document’s XML (GET /v1/invoices/:id/xml), export the document lists (/v1/invoices/export, /v1/drafts/export), download the XML backup (/v1/archive/*), resend a document’s email |
The other scopes a key may hold:
| Scope | Allows |
|---|---|
invoices:void |
Credit notes, and any note that annuls a document (code 01) — see Notas de Crédito / Débito |
parties:read · parties:write |
Customers and suppliers |
items:read · items:write |
The item catalog |
proformas:read · proformas:write |
Proformas (quotes) |
recurring:read · recurring:write · recurring:run |
Recurring invoices |
documents:read |
Documents the company received (purchases) |
documents:accept |
Accept or reject a received document before Hacienda (MensajeReceptor) |
branches:read · terminals:read · sequences:read |
Branches, terminals and numbering |
tenant:read · settings:read · economic_activities:read |
The company’s profile, preferences and economic activities |
fx:read |
Exchange rates |
reports:read · reports:export |
Reports and the tax calendar, when the plan includes them |
fiscal:write |
The tax calendar: the fiscal profile and marking obligations as filed |
webhooks:manage |
Webhook endpoints |
audit:read |
The audit log, when the plan or an add-on includes it |
Full access ("scopes": ["*"]) grants every scope in these two tables,
including ones added later. Use it only for your own internal tools.
Some actions are never available to a key, whatever it is given: the subscription and its payments, the Hacienda certificate and ATV credentials, the company’s configuration (profile, branches, terminals, numbering, preferences), importing documents from XML, team members and roles, creating or revoking keys, transferring ownership, deleting the company, accepting legal documents and resetting the sandbox. A person does them, signed in to the web app.
Scopes are one of two checks. The other is the company’s plan: a request needs the scope and a plan that includes the feature.
Keys and the company’s plan
Section titled “Keys and the company’s plan”- Sandbox keys work on any account, with or without a plan.
- A production key needs the company to have a plan in force for anything
other than reading. Without one, every request except
GETandHEADis refused with402 SUBSCRIPTION_INACTIVE— reads keep working, so documents, PDFs and XML can still be downloaded. - Issuing in production counts against the plan’s documents. A company over
its limit is refused with
402(DOCUMENT_QUOTA_EXCEEDED, orPREPAID_BALANCE_EMPTYfor prepaid credit) before any number is allocated. See the error reference.
Rotate a key
Section titled “Rotate a key”Rotating creates a new key with the same name, environment, scopes and expiration, and retires the old one. By default the old key keeps working for 5 more minutes, so a deployed service can switch to the new one without a gap. In the web app, use the rotate button on the key’s row; over the API (JWT, owner or admin):
curl -X POST https://api.emite.cr/v1/auth/api-keys/$KEY_ID/rotate \ -H "Authorization: Bearer $JWT" \ -H "Content-Type: application/json" \ -d '{ "revokeImmediately": false }'The response has the same shape as a creation, with the new rawKey. If the
key may have leaked, send "revokeImmediately": true (in the web app, check
Revoke the current key immediately): the old key stops working at once.
Revoke a key
Section titled “Revoke a key”Revoking is immediate and has no grace period: the next request with the key
gets 401. In the web app, use the revoke button on the key’s row; over the
API, DELETE /v1/auth/api-keys/:id (JWT, owner or admin) returns 204 — also
for a key that was already revoked.
List keys
Section titled “List keys”GET /v1/auth/api-keys (JWT, owner or admin) lists the company’s keys of both
environments: name, prefix, lastFour, scopes, status (active, revoked
or expired), lastUsedAt, expiration and who created it. It never returns
the key itself. The web app shows the same list, including when each key was
last used — a key nobody uses is a key to revoke.
JWT sessions
Section titled “JWT sessions”Human clients (the dashboard, a mobile app) sign a user in and receive a JWT.
Its payload is { sub, tenantId?, sid, auth_time, iat, exp }:
tenantIdis optional — a freshly signed-up user has no company yet. Endpoints that need one return403 TENANT_REQUIREDwhen it’s missing.sidnames the session. Signing out, closing it from the session list, or a security event on the account (changing the password, turning on 2FA, signing in with a recovery code) ends it on the server: the token stops working on its next request, whatever itsexpsays.auth_timeis when the user signed in. A session never lasts more than 8 hours from it, however many times it is re-issued — or less, if the company sets a maximum session length or an inactivity timeout for its members.
For a backend integration, use an API key: a session belongs to a person and ends with their sign-in.
Adopting a re-issued token
Section titled “Adopting a re-issued token”Some calls re-issue the session: switching company, creating one, renewing
it, changing the password, closing the other sessions. The new token comes in
the X-Session-Token response header. A client that calls the API
directly (not through the web app) must replace its stored token whenever
that header appears. It is a credential: keep it out of logs.
Every JWT-authenticated response also carries
X-Session-State: <deadline>:<absolute|idle>:<window> — when the session
will be refused if nothing happens (Unix seconds), whether that is its maximum
(absolute) or an inactivity window (idle), and the window’s length in
seconds.
Inactivity timeouts
Section titled “Inactivity timeouts”When the company sets one, the session must be renewed while the user is
active: POST /v1/auth/sessions/renew returns { "renewed": true } and the
new token in X-Session-Token. Renew on real user activity only — never on a
timer, which would defeat the rule — and at most once per half window; a call
within 30 seconds of the current token answers { "renewed": false } and
changes nothing. Renewing never extends a session past its maximum.
Why a session was refused
Section titled “Why a session was refused”A 401 for a session that ended carries X-Session-Ended: <code>[:<cause>],
and the user has to sign in again:
| Code | Meaning |
|---|---|
SESSION_EXPIRED |
It reached its maximum. cause: platform, tenant_policy (the company’s maximum), or upgrade (a token from before session tracking) |
SESSION_IDLE_TIMEOUT |
It was not renewed within the company’s inactivity window |
SESSION_REVOKED |
It was signed out, closed from the session list, or ended by a security event |
SESSION_INVALID |
Not a token we signed, or the account is gone or deactivated |
Switching into a company whose rules no longer admit the sign-in — its
maximum ran out for it, or an admin closed the user’s sessions there — answers
403 TENANT_REQUIRES_REAUTH (params.reason: tenant_policy or
sessions_revoked). The current session is untouched; only a new sign-in
enters that company.
Errors
Section titled “Errors”| Code | Status | Meaning |
|---|---|---|
UNAUTHORIZED |
401 | No credential, or the API key is malformed, unknown or carries the wrong secret |
API_KEY_REVOKED · API_KEY_EXPIRED |
401 | The API key, with its correct secret, was revoked or expired |
INSUFFICIENT_SCOPE |
403 | The key or the user’s role lacks a scope the endpoint requires (params.required) |
SUBSCRIPTION_INACTIVE |
402 | A production key, no plan in force, and a request that is not a read |
API_KEY_SCOPES_REQUIRED |
400 | Creating a key with an empty scope list |
API_KEY_SCOPE_INVALID |
400 | Creating a key with a scope that does not exist or cannot be given to a key |
API_KEY_NAME_TAKEN |
409 | Another active key of that environment already has that name |
SESSION_EXPIRED · SESSION_IDLE_TIMEOUT · SESSION_REVOKED · SESSION_INVALID |
401 | The JWT session ended — see Why a session was refused |
TENANT_REQUIRED |
403 | JWT has no tenant scope yet |
TENANT_REQUIRES_REAUTH |
403 | That company’s session rules no longer admit this sign-in — sign in again |
The other codes, by area, are in the error reference.