- Getting started
- Authentication
Getting started
Authentication
How to generate the API Key and send it from your program.
Every API route uses your company’s API Key, in the x-api-key header. The URL does not change between sandbox and production. The environment is on the key.
https://api.treeunfe.com.br/api/v1
To check that the program is sending the key, read the company that owns it:
curl -X GET "https://api.treeunfe.com.br/api/v1/organizations/current" \
-H "x-api-key: $TREEUNFE_API_KEY" \
-H "Accept: application/json"
In code, read the key from an environment variable and set the header on every call:
const response = await fetch("https://api.treeunfe.com.br/api/v1/organizations/current", {
headers: {
"x-api-key": process.env.TREEUNFE_API_KEY,
Accept: "application/json",
},
});
Generating the API Key
In the Treeunfe issuer app, open Integrações in the sidebar, click Nova, and choose Api-Key.
When you generate the key, you set:
| Option | What it sets |
|---|---|
| Environment | HOMOLOGACAO or PRODUCAO. The key only issues in the environment you chose. |
| Scopes | nfe:read and nfse:read look invoices up. nfe:emit issues NF-e and registers events. nfse:emit issues, cancels, and substitutes NFS-e. |
| Validity | How long the key lasts, for example 3 months. |
The key only accesses your company’s data.
Integrate and test with a HOMOLOGACAO key. Generate the PRODUCAO key only when you go live.
Keep the key in the backend, in the environment variable. Do not put it in apps, in the browser, or in source repositories.
For an agent, use the MCP. Sign-in uses the issuer-app account, and that session operates in production.
If the company is inactive, requests receive 403 Organization is inactive.