- Getting started
- Quickstart
Getting started
Quickstart
Create an organization and issue your first NF-e in the sandbox.
This guide is for your Enterprise account’s system to call the API. The URL is always the same:
https://api.treeunfe.com.br/api/v1
Sandbox and production do not change the host. Each Enterprise key is created in one environment.
You need a sandbox Enterprise key with permission to upload the certificate and to issue and read NF-e. Store it in TREEUNFE_ENTERPRISE_KEY. See Authentication.
To issue by talking to an agent, use the Enterprise MCP. The address is https://mcp.enterprise.treeunfe.com.br/mcp, sign-in is OAuth, and the environment is chosen in that authorization.
Create the organization
Register the issuing company.
curl -X POST https://api.treeunfe.com.br/api/v1/enterprise/organizations \
-H "Content-Type: application/json" \
-H "x-enterprise-key: $TREEUNFE_ENTERPRISE_KEY" \
-d '{
"CNPJCPF": "12345678000195",
"xNome": "CLIENTE EXEMPLO LTDA",
"xFant": "CLIENTE EXEMPLO",
"email": "fiscal@cliente-exemplo.com.br",
"fone": "44999990000",
"IE": "9071311225",
"address": {
"xLgr": "Avenida Exemplo", "nro": "5145", "xBairro": "Zona 07",
"cMun": 4115200, "xMun": "MARINGA", "UF": "PR", "CEP": "87020035"
}
}'
Store the organization.id from the response in TREEUNFE_ORGANIZATION_ID. It goes in the x-organization-id header in the next steps.
Upload the digital certificate
The organization needs an A1 certificate to sign the invoices.
curl -X POST https://api.treeunfe.com.br/api/v1/certificates/upload \
-H "x-enterprise-key: $TREEUNFE_ENTERPRISE_KEY" \
-H "x-organization-id: $TREEUNFE_ORGANIZATION_ID" \
-F "file=@certificado.pfx" \
-F "password=CERTIFICATE_PASSWORD"
Ask the company to fill in the fiscal configuration
Generate a link and send it to the company. There, it fills in its NF-e settings. If it prefers, the company can use the default rules of the Treeunfe tax engine.
curl -X POST https://api.treeunfe.com.br/api/v1/bff/enterprise-group/organizations/$TREEUNFE_ORGANIZATION_ID/fiscal-config-invites \
-H "x-enterprise-key: $TREEUNFE_ENTERPRISE_KEY" \
-H "x-organization-id: $TREEUNFE_ORGANIZATION_ID"
Issue the NF-e
Send the invoice with the sandbox key and calculateTaxes: true (Payload Inteligente) so Treeunfe calculates the taxes. The full payload is in Issuing NF-e.
curl -X POST https://api.treeunfe.com.br/api/v1/nfe \
-H "Content-Type: application/json" \
-H "x-enterprise-key: $TREEUNFE_ENTERPRISE_KEY" \
-H "x-organization-id: $TREEUNFE_ORGANIZATION_ID" \
-d @nfe.json
If the invoice is authorized, the response has outcome: "SUCCESS", the chaveAcesso (access key), and the protocolo (protocol number). When you go live, generate another key in production and point TREEUNFE_ENTERPRISE_KEY at it. The URL stays the same.