Set the tenant's active environment
const url = 'https://api.emite.cr/v1/tenants/example/credentials/active-environment';const options = { method: 'PATCH', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"environment":"sandbox"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request PATCH \ --url https://api.emite.cr/v1/tenants/example/credentials/active-environment \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "environment": "sandbox" }'Switches the environment the company works in: documents created from then on in a member's session are issued there, with that environment's credentials. A document keeps the environment it was created in, and an API key stays bound to its own. Rejects with 422 TARGET_ENVIRONMENT_NOT_CONFIGURED if the target environment has no uploaded credentials.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”Request Bodyrequired
Section titled “Request Bodyrequired”object
Where the company works from now on: sandbox (Hacienda's test environment, no fiscal value) or production (real documents). Its credentials must already be uploaded (422 TARGET_ENVIRONMENT_NOT_CONFIGURED). It applies to the members' sessions — an API key stays bound to its own environment — and a document keeps the environment it was created in.
Example
sandboxResponses
Section titled “Responses”object
The company's active environment, as it now is.
Example
{ "activeEnvironment": "sandbox"}Missing or invalid JWT / API key
:tenantId is not the caller's company, or insufficient scope — credentials:* is never granted to an API key.
Target environment has no credentials configured.