> ## 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.

# Sankhya as a data source

> Bring the data of your Sankhya Om ERP to Nekt: accounts payable and receivable, invoices and their items, partners, products, stock, costs, bank movements, production orders and more.

Sankhya Om is the ERP of Sankhya, used by Brazilian companies to run finance, sales, purchases, stock and production. This connector reads your Sankhya Om tables through the official Sankhya API Gateway (`api.sankhya.com.br`), so you can analyze your financial titles, invoices, products, stock and costs together with the rest of your data.

> [!NOTE]
>
> The connector only reads data. It never creates, changes or deletes anything in Sankhya.

## Before you start

The connector uses Sankhya's official integration model: an integration registered in the Sankhya **Portal do Desenvolvedor** (Developer Area) plus a token generated in your Sankhya Om. You will need:

1. **A Sankhya Om version that has the Configurações Gateway screen.** Sankhya generates integration tokens on this screen from Sankhya Om version 4.16 onwards ([Sankhya FAQ](https://developer.sankhya.com.br/reference/faq-1)).
2. **Access to the Sankhya Portal do Desenvolvedor** ([areadev.sankhya.com.br](https://areadev.sankhya.com.br/)) with a user that can create solutions. If no one in your company has access yet, the manager of your company's Sankhya ID account grants it at [account.sankhya.com.br](https://account.sankhya.com.br) ([how to get access](https://developer.sankhya.com.br/docs/cliente-sankhya-como-obter-acesso-ao-portal-do-desenvolvedor)). Sankhya customers building an integration for their own use do **not** need to join the "Sankhya Developer" partner program.
3. **Access to the Database Explorer.** The connector reads your tables with Sankhya's Database Explorer service (`DbExplorerSP.executeQuery`). The Sankhya Om user behind the integration needs access to the **DbExplorer** screen; without it, the sync fails with the message `O uso do executeQuery requer acesso a tela DbExplorer`. Sankhya lets you restrict which screens and services an integration can use ([Camada de autorização para API](https://developer.sankhya.com.br/reference/camada-de-autoriza%C3%A7%C3%A3o-para-api)), so ask your Sankhya administrator to allow it.

> [!NOTE]
>
> Nekt only talks to the Sankhya API Gateway, never directly to your Sankhya Om server, so you do not need to open your firewall to Nekt. If your Sankhya Om runs on your own servers (on premise), it must already be reachable by the Sankhya Gateway, as Sankhya requires for any integration. See [Gerando Tokens de Integração no SankhyaOm](https://developer.sankhya.com.br/reference/gerando-tokens-de-integra%C3%A7%C3%A3o-no-sankhyaom) for the Gateway addresses to allow.

## Getting your Sankhya credentials

The connector needs three values: a **Client ID** and a **Client Secret**, created in the Portal do Desenvolvedor, and a **Gateway Token (X-Token)**, generated in your Sankhya Om. These steps follow Sankhya's official documentation: [Portal do Desenvolvedor Sankhya](https://developer.sankhya.com.br/docs/portal-do-desenvolvedor), [Novo Fluxo de Autenticação com OAuth 2.0](https://developer.sankhya.com.br/changelog/novo-fluxo-de-autenticacao-com-oauth-20) and [Autenticação com OAuth 2.0 (Client Credentials)](https://developer.sankhya.com.br/reference/post_authenticate).

**1. Create a solution in the Portal do Desenvolvedor**

Sign in to the [Portal do Desenvolvedor](https://areadev.sankhya.com.br/), open **Minhas soluções** and click **Criar solução**. Give it a name you will recognize (for example, "Nekt") and a short description. When asked whether the solution will be offered to other customers in the Marketplace, choose **Não, é para uso exclusivo da minha empresa**. Select the groups that can manage the solution and click **Criar nova solução**.

**2. Add an integration component and copy the Client ID and Client Secret**

In the solution details, click **Adicionar componente** and create a component of the integration type (*componente de integração*). Sankhya generates a `client_id` and a `client_secret` for each new integration component, for the production and sandbox (homologação) environments. Copy the **production** Client ID and Client Secret: these are the **Client ID** and **Client Secret** fields in Nekt.

**3. Generate the Gateway Token in Sankhya Om**

In your Sankhya Om, open the **Configurações Gateway** screen and generate the token for the solution you created. Sankhya shows this step in a video in [Gerando Tokens de Integração no SankhyaOm](https://developer.sankhya.com.br/reference/gerando-tokens-de-integra%C3%A7%C3%A3o-no-sankhyaom). This token is the **Gateway Token (X-Token)** field in Nekt: it tells the Sankhya Gateway which Sankhya Om environment to read.

> [!WARNING]
>
> Treat the Client Secret and the Gateway Token like passwords: anyone who has them, together with the Client ID, can access your Sankhya through the API. Enter them only in the Nekt source form.

If your solution was created before Sankhya's OAuth 2.0 model and only shows an **AppKey**, Sankhya explains how to generate a Client ID and Client Secret for it in the [Guia de Conversão do Componente de Integração (AppKey → OAuth2)](https://developer.sankhya.com.br/reference/guia-de-conversao-do-componente-de-integracao-appkey-oauth2). The token you already use stays valid as the Gateway Token.

## Configuring Sankhya 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 Sankhya 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:

* **Client ID**: The Client ID of your integration component in the Sankhya Portal do Desenvolvedor.
* **Client Secret**: The Client Secret of the same integration component.
* **Gateway Token (X-Token)**: The token generated on the **Configurações Gateway** screen of your Sankhya Om.

Advanced settings:

* **Base URL**: The address of the Sankhya API Gateway. Leave it empty to use `https://api.sankhya.com.br`. This is **not** the address of your Sankhya Om system: entering your own server's address makes the login fail. To test against Sankhya's sandbox, enter `https://api.sandbox.sankhya.com.br` and use the sandbox Client ID and Client Secret.
* **Initial sync date** (recommended): Earliest date to read, in the format `YYYY-MM-DD` (for example `2024-01-01`) or `DD/MM/YYYY` (for example `01/01/2024`). On the first sync, the `financeiros`, `notas`, `itens_nota` and `movimentos_bancarios` tables only read rows created or changed since this date; later syncs only read what changed since the previous one. It is also the first due date read by `agenda_financeira`. These tables can hold millions of rows, so setting a date (for example, the start of the period you want to analyze) makes the first sync much faster. Leave it empty to read their whole history.
* **End Date**: Optional. Latest date to read, in the same formats. It filters `financeiros` and `notas` by negotiation date (`dtneg`) and `movimentos_bancarios` by posting date (`dtlanc`), on every sync. Leave it empty for a source that keeps your data up to date: rows dated after it are never read.

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. The available streams are listed in [Available streams](#available-streams) below.

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

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 and changed rows. We recommend it for `financeiros`, `notas`, `itens_nota`, `movimentos_bancarios`, `parceiros` and `produtos`.
  * Full table: every time the extraction happens, we'll get the current state of the data. All the other streams are always full table.

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)**. Rows deleted in Sankhya stay in the incremental tables until a full sync, so if deletions matter to your analysis, schedule a periodic full sync (for example, weekly).

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 tables below list every stream, its **slug** (the exact identifier to pass when creating the source via API), the Sankhya table it reads, its primary key and how it is synced.

### Finance

| Slug | Sankhya table | Description | Primary key | Sync |
| :- | :- | :- | :- | :- |
| `financeiros` | TGFFIN | Financial titles: accounts receivable and payable, open and settled. `recdesp` is 1 for receivables, -1 for payables and 0 for titles without financial effect; `dhbaixa` is filled once a title is settled. | `nufin` | Incremental (`dtalter`) |
| `impostos_financeiros` | TGFIMF | Taxes of each financial title (base, rate and amount), with the tax name, DARF revenue description and income nature description. | `nufin`, `codimp` | Full table |
| `agenda_financeira` | Financial agenda service | Open (not yet settled) payables by due date, from the **Initial sync date** (or 1 January 2020 when it is empty) to 12 months from the day of the sync. Each row is stored as JSON in a single `raw_data` column. For the complete set of payables and receivables, use `financeiros`. | None | Full table |
| `movimentos_bancarios` | TGFMBC | Bank account movements. | `nubco` | Incremental (`dtalter`) |
| `contas_bancarias` | TSICTA | Bank accounts. | `codctabcoint` | Full table |
| `bancos` | TSIBCO | Banks. | `codbco` | Full table |
| `tipos_titulo` | TGFTIT | Title types: the payment types used on financial titles. | `codtiptit` | Full table |
| `naturezas` | TGFNAT | Natures (naturezas): the financial categories of revenues and expenses. | `codnat` | Full table |
| `centros_resultado` | TSICUS | Cost centers (centros de resultado). | `codcencus` | Full table |

### Sales and purchase documents

| Slug | Sankhya table | Description | Primary key | Sync |
| :- | :- | :- | :- | :- |
| `notas` | TGFCAB | Header of every product document: orders, invoices, purchases, returns, transfers and so on. `codtipoper` tells which kind of document it is (see `tipos_operacao`). | `nunota` | Incremental (`dtalter`) |
| `itens_nota` | TGFITE | The products of each document, one row per item. | `nunota`, `sequencia` | Incremental (`dtalter`) |
| `vinculos_nota` | TGFVAR | Links between documents: which items of which origin documents (for example, orders) each document item came from. | `nunota`, `sequencia`, `nunotaorig`, `sequenciaorig` | Full table |
| `tipos_operacao` | TGFTOP | Operation types (TOPs). Sankhya keeps every change to an operation type as a new version, so there is one row per version. | `codtipoper`, `dhalter` | Full table |
| `vendedores` | TGFVEN | Sellers and sales representatives. | `codvend` | Full table |

### Companies and partners

| Slug | Sankhya table | Description | Primary key | Sync |
| :- | :- | :- | :- | :- |
| `empresas` | TSIEMP | Your companies (empresas) registered in Sankhya. | `codemp` | Full table |
| `parceiros` | TGFPAR | Partners: customers, suppliers and the other people and companies you do business with, with CPF/CNPJ, e-mail and bank details. | `codparc` | Incremental (`dtalter`), whole table on the first sync |

### Products, stock and costs

| Slug | Sankhya table | Description | Primary key | Sync |
| :- | :- | :- | :- | :- |
| `produtos` | TGFPRO | Products. | `codprod` | Incremental (`dtalter`), whole table on the first sync |
| `grupos_produto` | TGFGRU | Product groups. | `codgrupoprod` | Full table |
| `volumes` | TGFVOL | Units of measure. | `codvol` | Full table |
| `volumes_alternativos` | TGFVOA | Alternative units of measure of each product. | `codprod`, `codvol`, `controle` | Full table |
| `estoque` | TGFEST | Current stock per company, product, location and batch, including third-party stock. | `codemp`, `codprod`, `codlocal`, `controle`, `codparc`, `tipo` | Full table |
| `movimentos_estoque` | TGFESE | Stock movements summarized by day. | `dtreferencia`, `tipmov`, `codprod`, `codtipoper`, `codemp`, `codlocalorig`, `controle`, `codempcontpart`, `atualestoque`, `atualestterc` | Full table |
| `custos` | TGFCUS | Product cost history: each cost update per product, company, location and batch, with the document that caused it. | `codprod`, `codemp`, `dtatual`, `codlocal`, `controle`, `nunota`, `sequencia` | Full table |
| `custos_itens` | TGFCUSITE | Cost of each document item. | `nunota`, `sequencia`, `codprod` | Full table |

### Cities, states, countries and currencies

| Slug | Sankhya table | Description | Primary key | Sync |
| :- | :- | :- | :- | :- |
| `cidades` | TSICID | Cities. | `codcid` | Full table |
| `unidades_federativas` | TSIUFS | Brazilian states (UFs). | `coduf` | Full table |
| `paises` | TSIPAI | Countries. | `codpais` | Full table |
| `moedas` | TSIMOE | Currencies. | `codmoeda` | Full table |

### Production

These tables exist only when your company uses the Sankhya production module. If they do not exist in your Sankhya, the streams are skipped with a warning in the run log and the other streams keep syncing.

| Slug | Sankhya table | Description | Primary key | Sync |
| :- | :- | :- | :- | :- |
| `processos_producao` | TPRPRC | Production processes (process definitions). | `idproc` | Full table |
| `ordens_producao` | TPRIPROC | Production orders (OPs). | `idiproc` | Full table |
| `ordens_producao_produtos` | TPRIPA | Finished products to make in each production order. | `idiproc`, `codprodpa`, `controlepa` | Full table |
| `ordens_producao_atividades` | TPRIATV | Activities run in each production order. | `idiatv` | Full table |
| `apontamentos` | TPRAPO | Production reports (apontamentos). | `nuapo` | Full table |
| `apontamentos_produtos` | TPRAPA | Finished products reported in each production report. | `nuapo`, `seqapa` | Full table |

## Fields

Every Sankhya installation has its own columns, so the connector does not use a fixed list of fields. When it discovers the streams, it reads every column of each table in **your** Sankhya, including your company's custom fields (the `AD_*` fields), and creates a column for each one:

* Column names are the Sankhya field names in lowercase, for example `nufin`, `codparc`, `vlrdesdob` or `ad_meucampo`.
* Each column's description is the field label from your Sankhya data dictionary, so you can recognize the field as it appears on Sankhya's screens.
* Binary columns, such as images and attached files, are not synced.
* `vlrliquido` (net amount) in `financeiros` is a calculated field of the Sankhya data dictionary, not a stored column: the connector calculates it with its Sankhya formula.
* `impostos_financeiros` also has `imposto_nomeimp` (tax name), `receitadarf_descrreceita` (DARF revenue description), `cadastronaturezarendimentos_descnatrend` (income nature description) and `imposto_calcbasemensal`, read from the related Sankhya tax tables.

## Implementation notes

### How incremental streams sync

* `financeiros`, `notas`, `itens_nota`, `movimentos_bancarios`, `parceiros` and `produtos` are synced by their last change date in Sankhya (`dtalter`).
* On the first sync, `financeiros`, `notas`, `itens_nota` and `movimentos_bancarios` read the rows changed since the **Initial sync date** (or the whole table when it is empty). `parceiros` and `produtos` always read the whole table on the first sync, because documents of any date refer to them.
* Later syncs read only the rows changed since the previous sync, plus the 10 minutes before it, so changes saved while a sync was running are not missed.
* A financial title's change date is also updated when it is settled, so settlements reach `financeiros` on the next sync.
* Rows deleted in Sankhya are not detected by incremental syncs. They stay in your tables until the next full sync.
* Full table streams read the whole table on every sync, so deletions are reflected right away.

### Dates and times

Sankhya stores dates and times in the local time of your Sankhya server, without a time zone. Nekt does not convert them: read date and time columns (such as `dtalter` or `dhbaixa`) as your Sankhya server's local time.

### Custom fields and missing tables

* Some streams include a few custom fields that exist only in some Sankhya installations (for example `ad_dtdecompetencia` in `financeiros`). If a field does not exist in your Sankhya, its column stays empty and the run log lists it; the rest of the stream syncs normally.
* A stream whose table does not exist in your Sankhya (usually because the module is not in use, as with the production tables) is skipped with a warning, and its table is not updated.

### Performance

* The Sankhya Database Explorer returns at most 5,000 rows per request, and fewer for tables with many columns (such as `notas`). The first sync of large tables, with years of financial titles or invoices, can take a while. Setting the **Initial sync date** shortens it.
* **End Date** does not filter `itens_nota`: when you set it, `itens_nota` can include items of documents that are not in `notas`.

## Troubleshooting

| Error or symptom | What it means | What to do |
| :- | :- | :- |
| "O uso do executeQuery requer acesso a tela DbExplorer" | The Sankhya Om user behind the integration cannot use the Database Explorer. | Give that user access to the **DbExplorer** screen, as described in [Before you start](#before-you-start). |
| "Could not log in to Sankhya: the configured Base URL did not answer like the Sankhya Gateway API" | The **Base URL** setting points to something other than the Sankhya API Gateway, often your own Sankhya Om address. | Leave **Base URL** empty to use `https://api.sankhya.com.br`. |
| The run fails at login with an authentication error | Sankhya rejected the Client ID, Client Secret or Gateway Token. | Check that the three values belong to the same solution, that you used the production Client ID and Client Secret, and that the token was generated for that solution in **Configurações Gateway**. |
| "The 'start\_date' setting has an invalid date" (or `end_date`) | The **Initial sync date** or **End Date** is not a valid date. | Use `YYYY-MM-DD` (for example `2024-01-31`) or `DD/MM/YYYY` (for example `31/01/2024`). |
| "The '...' stream was skipped: its table (...) does not exist in your Sankhya" | Your Sankhya does not have that table, usually because the module is not in use. | Nothing to fix. Deselect the stream to stop the warning. |
| "The '...' stream has fields that do not exist in your Sankhya" | Some fields the connector reads by default do not exist in your installation. | Nothing to fix: those columns stay empty and the rest of the stream syncs. |


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