Skip to content

Environments

Every company operates in two environments: sandbox (Hacienda’s test ATV) and production (real fiscal documents). The environment sits next to the company as a second scope on transactional data.

An API key is created for one environment and cannot cross over — the prefix shows which (ec_test_… for sandbox, ec_live_… for production). This is deliberate: a key pasted into the wrong integration fails loudly instead of emitting real documents from a test flow, or the reverse.

Because keys are pre-bound, machine callers don’t signal which environment they mean — the key decides. Both environments use the same base URL (https://api.emite.cr/v1).

Each environment needs its own credentials

Section titled “Each environment needs its own credentials”

Signing and submitting use the company’s Hacienda credentials of the document’s environment: the sandbox .p12 and ATV user for sandbox, the production ones for production. Both are uploaded in the web app, under Company → Certificate. A key can’t upload or read them.

An invoice’s environment is stamped at creation from the key and is immutable. The entire sign/submit pipeline (ATV client, credentials, sequence, storage) keys off the invoice’s own environment, not any current company setting. A draft created in sandbox stays sandbox forever.

Scoped by environment Shared across environments
Invoices, submissions, sequences Parties (customers/suppliers)
Idempotency keys, externalReference Items / catalog
API keys, webhook endpoints, ATV tokens Branches, terminals, users
Hacienda credentials Branding, settings, subscription

Configuration is per company and environment-independent; transactional records carry the environment column. So a customer created while testing in sandbox is already there in production — but sandbox documents never appear in production lists, and their numbering is separate.

Sandbox is always free, with or without a plan. Only production document emissions count against the company’s plan. Sandbox is for building and testing the full flow — real XML build, real XAdES signing, real round trip to Hacienda’s test environment — without fiscal or billing consequences.

Production needs more: a plan in force and production credentials. The quickstart has the checklist.

The web app sends two headers so a stale browser tab can’t silently write where it shouldn’t.

  • X-Expected-Environment is the environment the tab shows: if it disagrees with the company’s active environment, the request returns 409 ENVIRONMENT_MISMATCH and the tab re-fetches.
  • X-Expected-Tenant is the company the tab shows. The session is one for every tab of the browser: if another tab moved it to another company, the request returns 409 TENANT_MISMATCH instead of landing in that other company.

Both are optional and only writes are checked: without them, the request goes through as always. API-key and partner-key callers skip these checks entirely — the key is already bound to a company and an environment, so there’s nothing to drift.