> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nekt.com/llms.txt
> Use this file to discover all available pages before exploring further.

# TMB as a data source

> Bring orders, order details, products and offers from TMB Educação to Nekt.

TMB Educação is a platform that lets producers of digital products (courses, mentorships, infoproducts) sell them in installments paid by boleto, with TMB financing the purchase. Its TMB API gives read-only access to the producer's effective orders, including each order's financial status, and to the producer's products and their offers. The Nekt connector extracts that data into your Catalog, so you can follow sales, financing and customer payment status together with the rest of your data.

## Before you start

You need a **TMB API token**. In the TMB Producer Portal, open **Produtos > TMB API** and copy the token (you can also revoke it or generate a new one there). The token is available once your product is registered and the contract with TMB is signed. If you generate a new token, the previous one stops working: update it in the source configuration.

> [!WARNING]
>
> Orders carry personal data of your customers: name, CPF or CNPJ, email, phone, birth date and address. Consider which layer and which permissions the orders table gets in your Catalog.

## Configuring TMB as a Source

In the [Sources](https://app.nekt.ai/sources) tab, click on the "Add source" button located on the top right of your screen. Then, select the TMB option from the list of connectors.

Click **Next** and you'll be prompted to add your access.

### 1. Add account access

The following configurations are available:

* **API token**: the token copied from **Produtos > TMB API** in the TMB Producer Portal.

* **Start date**: orders from this date on are extracted. TMB filters orders by date without saying which date it uses (creation or effectiveness), so orders around the start date may follow either one.

* **Lookback days**: (Default: 30) on each incremental extraction, the orders of this many days before the last order already extracted are read again, to catch late changes.

* **Full refresh interval (days)**: (Default: 7) every this many days, the whole order history since the start date is read again, so the **financial status** of older orders stays up to date. TMB does not report when an order changes, so this is the only way to refresh it. Set `0` to turn it off; then the financial status of an order is only refreshed while it is inside the lookback window, and an order that becomes effective long after it was created may only be read by a full sync.

* **Page size**: (Default: 100) how many records are asked for in each request. Lower it only if TMB refuses large pages.

Once you're done, click **Next**.

### 2. Select streams

Choose which data streams you want to sync. For faster extractions, select only the streams that are relevant to your analysis.

> Tip: The stream can be found more easily by typing its name.

The **Order details** stream is not selected by default: it makes one request per order (see [API limits and performance](#api-limits-and-performance)).

Select the streams and click **Next**.

### 3. Configure data streams

Customize how you want your data to appear in your catalog. Select the desired layer where the data will be placed, a folder to organize it inside the layer, a name for each table (which will effectively contain the fetched data) and the type of sync.

* **Layer**: choose between the existing layers on your catalog. This is where you will find your new extracted tables as the extraction runs successfully.
* **Folder**: a folder can be created inside the selected layer to group all tables being created from this new data source.
* **Table name**: we suggest a name, but feel free to customize it. You have the option to add a **prefix** to all tables at once and make this process faster!
* **Sync Type**: you can choose between INCREMENTAL and FULL\_TABLE.
  * Incremental: every time the extraction happens, we'll get only the new data, which is good if, for example, you want to keep every record ever fetched.
  * Full table: every time the extraction happens, we'll get the current state of the data, which is good if, for example, you don't want to have deleted data in your catalog.

We recommend INCREMENTAL for **Orders** and **Order details**. **Products** and **Offers** are small lists that are always read in full.

Once you are done configuring, click **Next**.

### 4. Configure data source

Describe your data source for easy identification within your organization, not exceeding 140 characters.

To define your [Trigger](https://docs.nekt.com/runs/scheduling-and-triggers.md), consider how often you want data to be extracted from this source. This decision usually depends on how frequently you need the new table data updated (every day, once a week, or only at specific times).

Optionally, you can define some additional settings:

* Configure Delta Log Retention and determine for how long we should store old states of this table as it gets updated. Read more about this resource [here](https://docs.nekt.com/get-started/core-concepts/resource-control).
* Determine when to execute an **Additional [Full Sync](https://docs.nekt.com/get-started/core-concepts/types-of-sync#additional-full-sync)**. This will complement the incremental data extractions, ensuring that your data is completely synchronized with your source every once in a while. The connector already re-reads all orders every **Full refresh interval (days)**; an Additional Full Sync also removes orders that TMB no longer lists.

Once you are ready, click **Next** to finalize the setup.

### 5. Check your new source

You can view your new source on the [Sources](https://app.nekt.ai/sources) page. If needed, manually trigger the source extraction by clicking on the arrow button. Once executed, your data will appear in your Catalog.

> [!WARNING]
>
> For you to be able to see it on your [Catalog](https://app.nekt.ai/catalog), you need at least one successful source run.

# Streams and Fields

## Available streams

The table below lists every stream, its **slug** (the exact identifier to pass when creating the source via API) and a short description.

| Stream | Slug | Description |
| - | - | - |
| Orders | `pedidos` | Effective orders, with customer, amounts, installments, financial status and UTM data. Incremental on `criado_em`. |
| Order details | `pedidos_detalhe` | *Not selected by default.* The full detail TMB returns for each order, as JSON. One request per order. |
| Products | `produtos` | The producer's products. Always read in full. |
| Offers | `ofertas` | The offers (checkout links) of each product. Always read in full. |

Every table has a `raw_data` column (`detalhe` in Order details) with the record exactly as TMB returned it, including any field not listed as a column.

## Fields by stream

> [accordion] Orders (pedidos)
>
> One row per effective order.
>
> **Identification:**
>
> * `pedido_id` - Unique identifier of the order (primary key)
> * `produto_id` - Product ordered
> * `produtor`, `produtor_id` - Producer who sells the product
> * `lancamento` - Launch (campaign) the order belongs to
> * `status_pedido` - Status of the order (e.g. Efetivado)
> * `status_financeiro` - Financial status of the customer's installments (e.g. Adimplente). It changes over time: see [How orders stay up to date](#how-orders-stay-up-to-date)
>
> **Amounts (BRL):**
>
> * `valor_total` - Total amount of the order
> * `valor_entrada` - Down payment
> * `parcelas` - Number of installments
> * `valor_parcela` - Amount of each installment
> * `taxa_administracao` - Administration fee charged by TMB, as returned by the API
> * `melhor_dia_pagamento` - Day of the month the customer chose to pay
>
> **Dates:**
>
> * `criado_em` - When the order was created (incremental replication key)
> * `data_efetivado` - When the order became effective. TMB sends it without a timezone; it is read as São Paulo time
>
> **Customer (personal data):**
>
> * `cliente`, `documento` (CPF/CNPJ), `email`, `telefone`, `nascimento`
> * `pais`, `cep`, `endereco_estado`, `endereco_cidade`, `endereco_bairro`, `endereco_logradouro`, `endereco_numero`, `endereco_complemento`, `endereco_completo`
>
> **Marketing:**
>
> * `utm_source`, `utm_medium`, `utm_campaign`, `utm_content` - UTM parameters of the customer's first visit
> * `utm_last_source`, `utm_last_medium`, `utm_last_campaign`, `utm_last_content` - UTM parameters of the last visit before ordering
>
> **Raw:**
>
> * `raw_data` - The order as TMB returned it (JSON)

> [accordion] Order details (pedidos\_detalhe)
>
> One row per order whose detail was read. TMB does not document the format of the detail, so it is kept whole as JSON.
>
> * `pedido_id` - Order the detail belongs to (primary key)
> * `criado_em` - When the order was created (incremental replication key)
> * `detalhe` - The full detail returned by TMB (JSON)

> [accordion] Products (produtos)
>
> One row per product of the producer.
>
> * `produto_id` - Unique identifier of the product (primary key)
> * `produto_nome` - Name of the product
> * `descricao` - Description of the product
> * `valor_total` - Average ticket as TMB formats it for display (e.g. "R\$ 1.000,00")
> * `valor_total_numerico` - The same average ticket as a number
> * `ativo` - Whether the product is active
> * `raw_data` - The product as TMB returned it (JSON)

> [accordion] Offers (ofertas)
>
> One row per offer of each product.
>
> * `produto_id` - Product the offer belongs to
> * `oferta_key` - What identifies the offer within its product: its id when TMB sends one, else its URL (primary key, with `produto_id`)
> * `oferta_id` - Identifier of the offer, when TMB sends one
> * `titulo` - Title of the offer
> * `url` - URL of the offer's checkout page
> * `raw_data` - The offer as TMB returned it (JSON)

## Implementation Notes

### How orders stay up to date

TMB exposes no "last updated" date on orders, and an order's **financial status** keeps changing while the customer pays the installments. The connector therefore:

* On the first extraction (and on a full sync), reads every order since the **Start date**.
* On each incremental extraction, reads the orders of the last **Lookback days** before the most recent order already extracted.
* Every **Full refresh interval (days)**, reads all orders since the **Start date** again, updating the financial status of older orders. That extraction takes longer than the others.

Orders are merged by `pedido_id`, so re-reading an order updates its row. An order that TMB stops listing is not removed by incremental extractions; a full sync rebuilds the table from what TMB lists.

### API limits and performance

* TMB allows only a few requests per minute (about 10 per minute when listing orders, about 20 on the other endpoints). When the limit is reached, the extraction waits for the next minute instead of failing, so long histories take longer.
* **Order details** needs one request per order, about 1,200 orders per hour. On the first extraction (and on a full sync) it reads every order since the start date, so with a long history that first extraction can take hours. After that, each extraction only reads the details of orders created or made effective since the previous one, plus the ones that failed before.
* If you select **Order details** on a source whose orders were already extracted, only the details of new orders are read from then on. Run a full sync of the source to read the details of the older orders.
* An order whose detail could not be read is reported as a failure of the **Order details** table at the end of the run. The orders and the other details are still loaded, and the detail is asked again on the next extractions. A detail that TMB answers as "not found" three times is no longer asked, with a warning.
* The details of an order are read once. If you need them refreshed (for example, after changes in the installments), run a full sync of the source.

### Data Quality Considerations

* Amounts are stored as numbers in BRL; the product's `valor_total` also keeps TMB's display format.
* Dates are stored in UTC. `data_efetivado`, which TMB sends without a timezone, is read as São Paulo time.
* If a value comes in a format the column cannot hold, the column is left empty and the original value stays in `raw_data`.

## Troubleshooting

| Error or symptom | What it means | What to do |
| :- | :- | :- |
| "TMB refused the API token" | The token is wrong, revoked or was replaced by a new one (HTTP 401). Nothing was extracted. | Copy the current token from **Produtos > TMB API** in the TMB Producer Portal and update it in the source configuration. |
| "TMB did not allow this API token to read the ... table" | The token cannot read that data (HTTP 403). The other tables continue. | Check in the TMB Producer Portal that the TMB API is enabled for your account, or unselect the stream. |
| "TMB's firewall blocked the request from Nekt's servers" | TMB's firewall (Cloudflare) refused the request. It is not a problem with your token. | Contact support; nothing already in your tables was removed. |
| The extraction is slower than usual and mentions requests per minute | TMB's per-minute request limit was reached; the extraction waits and continues. | Nothing to do. Avoid running other integrations with the same token at the same time. |
| "TMB returned no offers for any product" | No product returned offers. The Offers table kept its previous content. | If your products have no offers, unselect the Offers stream. Otherwise, contact support. |
| "Order details: the details of N order(s) could not be read" | TMB failed for some orders. The other details and all orders were loaded; the missing details are asked again on the next extraction. | Nothing to do if it is occasional. If it repeats, contact support with the source slug and the run time. |
| "TMB answered 'not found' or nothing at all for every period of the orders" | TMB answered every date window of the orders with "not found" or an empty response. The Orders table kept its content. | Check that the **Start date** is right. If it repeats, contact support. |
| "TMB's API answered with an error (400)" | TMB refused the request. | Lower **Page size** in the source's advanced settings. If it repeats, contact support. |
| "TMB's API refused a page deep into the ... list" | TMB refused a page far into a list, and splitting the period into smaller ones did not help. The table kept its content. | Change **Page size** in the advanced settings (for example to 50 or 200) and run again. If it repeats, contact support. |
| "TMB returned no products for this token" | The product list came back empty. The Products and Offers tables kept their content. | Check the token in the TMB Producer Portal (the TMB API is available once a product is registered). If it repeats, contact support. |
| "TMB answered with no data where the first page of ... was expected" | TMB answered with an empty response where a list was expected, even after retries. The table kept its content. | Run the extraction again later. If it repeats, contact support. |
| "returned the same page twice", "reported more records than its pages returned" or "answered 'not found' in the middle of the ... list" | TMB's pages did not add up, so the table was not completed. Nothing already in it was removed. | Run the extraction again later. If it repeats, contact support. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.