TF Fiscal

Quick start

The six steps below, completed in order, lead from account activation to the first NF-e issued in the test environment

1. Obtain the integrator token

Integrator accounts are activated by TF. After signing in to the main platform, the "Key" shown under "My Account" is the integrator token; copying the full key requires the sign-in password. The integrator token is used to register and manage the issuing companies under the account. Invoices themselves are issued with the company token obtained in step 3; the difference between the two is described in "Authentication & signing".

The "Webhook URL" on the same page receives asynchronous issuance results and can be configured in step 6.

2. Verify the signature

Every request carries three headers, token, timestamp and sign, where sign = md5(token + path + body + timestamp). Calling a read-only endpoint with the integrator token confirms that the signature is correct:

TOKEN="integrator token"
TS=$(date +%s)
PATH_Q="/api/company/get_list?page=1&page_size=10"
SIGN=$(printf '%s' "$TOKEN$PATH_Q$TS" | md5sum | cut -d' ' -f1)

curl "https://api.tffiscal.com$PATH_Q" \
  -H "token: $TOKEN" -H "timestamp: $TS" -H "sign: $SIGN"

A response with "success": true indicates that the signature is correct. For GET requests the body is an empty string and the path must include the query string. When HTTP 401 is returned, the AUTH_* codes in "Error handling" identify the cause.

3. Register the issuing company

The company is registered by calling POST /api/company/v2/create with the integrator token. Only the company CNPJ and its A1 digital certificate are required: the platform obtains the company name, state registration and address from the certificate and from public registration data. The certificate file (.pfx / .p12) is sent in Base64.

{
  "cnpj": "12345678000199",
  "cert_content": "MIIOkAIBAzCC...(Base64)",
  "cert_pwd": "senha_do_certificado"
}

The token in the response is the company token of this company and is used for all subsequent issuance, queries and cancellations for it; company_id is the identifier of the company on the platform. When company data, or the series and starting number of each document type, must be specified manually, POST /api/company/create is used instead.

4. Prepare product taxes

The taxes of each product line are specified in one of two ways:

  • Tax category reference (category_id): a tax category is a set of tax rules (CFOP, CST, rates) stored on the platform and configured separately by buyer type and by intrastate or interstate operation. A default set of tax categories is created automatically when a Simples Nacional company is registered; their category_id values can be queried with GET /api/category/get_list (company token).
  • Inline (impostos): the four groups of tax information (ICMS, IPI, PIS and COFINS) are given directly in the product line at each issuance. This method suits cases in which product taxes are calculated by the integrator's own system.

The differences between the two methods and the way each tax code is filled in are described under "Fields by scenario" on the "Issue a new invoice" page.

5. Issue the first invoice in the test environment

The invoice is issued by calling POST /api/invoice/create with the company token and ambiente set to "2" (test environment). Invoices issued in the test environment have no legal effect, and the platform replaces the buyer name; the differences are described in "Environments and testing". The following is a minimal request for a Simples Nacional company selling to an individual:

{
  "id": "PED-0001",
  "nature_of_operation": "Venda de mercadoria",
  "transaction_type": "1",
  "model": "55",
  "issuance_type": "1",
  "ambiente": "2",
  "cliente": {
    "cpf": "88533234775", "name": "Cliente Demo",
    "endereco": "Rua Presidente Wilson", "numero": "911", "bairro": "Uberaba",
    "city": "Curitiba", "uf": "PR", "cep": "81570440"
  },
  "products": [
    {
      "codigo": "000068", "name": "Pendrive 16GB", "ncm": "85235190",
      "count": 2, "unit": "UN", "unit_price": 28.47, "total_price": 56.94,
      "origem": "0", "indicador_total": "1",
      "impostos": {
        "icms":   { "codigo_cfop": "6102", "situacao_tributaria": "102" },
        "ipi":    { "situacao_tributaria": "53", "codigo_enquadramento": "999" },
        "pis":    { "situacao_tributaria": "49" },
        "cofins": { "situacao_tributaria": "49" }
      }
    }
  ],
  "pag_info": [ { "payment_indicator": "0", "payment_method": "17", "payment_value": 56.94 } ]
}

6. Obtain the issuance result

/api/invoice/create returns the result synchronously once the tax authority has responded. When data.status is Success, data.chave is the access key and data.xml is the XML URL; the DANFE is obtained with /api/invoice/get_danfe. When the invoice is rejected, success is false, the reason is in data.motivo and the error code is in code.

For high issuance volumes, or when the connection should not remain open while waiting, the asynchronous endpoint /api/invoice/v2/create is used instead: it returns a task number immediately, and the result is delivered to the Webhook URL (webhook) or can be queried with /api/invoice/v2/task/get.

Pre-production checklist

  • ambiente is changed to "1" (production environment).
  • The id of each invoice is a unique order number from the integrator's own system: in the production environment, resubmitting the same id returns the invoice already issued and does not issue a duplicate.
  • Failures are handled according to code: TAX_AUTHORITY_UNAVAILABLE is retried later with the same id (a new id may result in two invoices); all other errors require the request to be corrected before resubmission.
  • When the asynchronous endpoint is used, the push receiver deduplicates by task_id.