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

# SIEG as a data source

> Bring data from SIEG to your Lakehouse.

SIEG is a Brazilian fiscal document platform used by accounting firms and finance teams. It automatically captures every electronic fiscal document issued by or against a company and stores it in the *Cofre SIEG*. This source brings those documents — the original XML files — into your Lakehouse.

## Configuring SIEG 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 SIEG option from the list of connectors.

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

### 1. Add account access

You'll need a SIEG **API Key**. It must be created by an administrator user of your SIEG account:

<Steps>
  <Step title="Open the API settings">
    Sign in to [app.sieg.com](https://app.sieg.com) and go to **Minha Conta** > **Integrações API SIEG**.
  </Step>

  <Step title="Generate a new key">
    Click **Gerar nova chave API**, give it an identification name, choose an expiration date (minimum 3 months, maximum 5 years) and select the **read** access level.
  </Step>

  <Step title="Copy the key">
    Copy the value of the **Chave API** field and paste it into the API Key field in Nekt.
  </Step>
</Steps>

<Warning>
  SIEG shows the API key only once, at creation time. Store it safely — if it is lost, a new key has to be generated.
</Warning>

You also need to set an **Initial sync date**, the earliest date from which documents should be extracted.

**Advanced configurations**

* **Which date should the extraction follow?**: choose between the *upload date* (when the document arrived in the SIEG vault) and the *issue date* (the date printed on the document). Upload date is recommended, because documents are frequently captured days or weeks after being issued and only the upload date guarantees they are picked up.
* **Window Size (days)**: how many days are requested per API call. Increasing it makes a long historical load faster, but the incremental replication key becomes as coarse as the window.
* **Include document events**: also extracts the events attached to each document, such as cancellations, correction letters, and operation manifestations.

Add the account access and click **Next**.

### 2. Select streams

Choose which document types you want to sync. Each stream corresponds to one type of fiscal document.

> 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 a name for each table and the type of sync.

* **Table name**: we suggest a name, but feel free to customize it. You have the option to add a **prefix** and make this process faster.
* **Sync Type**: we recommend INCREMENTAL for all SIEG streams. Each run resumes from the last time window that returned documents, so only new documents are fetched. Read more about Sync Types [here](https://docs.nekt.com/get-started/core-concepts/types-of-sync).

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

### 4. Configure data source

Describe your data source for easy identification within your organization, and define a [Trigger](https://docs.nekt.com/get-started/core-concepts/triggers) to determine how often data is extracted.

### Check your new source!

Click **Next** to finalize the setup. You can view your new source on the [Sources](https://app.nekt.ai/sources) page. Once the pipeline runs, your new tables will appear in the [Catalog](https://app.nekt.ai/catalog).

## How the data is structured

Fiscal XML layouts change with every schema version, and NFS-e has no national standard — each municipality publishes its own. A fixed set of typed columns would break every time a layout changes, so SIEG documents follow the same model Nekt uses for NoSQL sources: the whole document lands in a single column, next to the metadata needed to identify it.

Every stream has the same schema:

| Field           | Description                                                                                                                                                                                                                                                    |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `id`            | Unique identifier of the record. For fiscal documents it is the 44-digit access key. Events append the event code and sequence number to the key of the document they refer to. Documents issued without an access key fall back to a hash of the XML content. |
| `access_key`    | The 44-digit access key (*chave de acesso*) of the document, or of the document an event refers to. Empty when the layout has no access key.                                                                                                                   |
| `document_type` | Type of the record: the document type of the stream, or `Evento` for an event attached to a document.                                                                                                                                                          |
| `emitted_at`    | Date and time the document was issued, read from the XML itself.                                                                                                                                                                                               |
| `updated_at`    | Start of the time window in which SIEG made the document available. Used as the incremental replication key.                                                                                                                                                   |
| `document`      | The complete original XML of the document, converted to a JSON string.                                                                                                                                                                                         |

To read a field out of the `document` column, parse it in a Query or Notebook. For example, in a Query:

```sql theme={null}
select
    id,
    emitted_at,
    get_json_object(document, '$.nfeProc.NFe.infNFe.total.ICMSTot.vNF') as valor_total
from raw.sieg_nfe
```

## Available streams

<AccordionGroup>
  <Accordion title="NF-e">
    Nota Fiscal Eletrônica (model 55) — the invoice used for goods transactions between companies.

    Delivered with `document_type` set to `NFe`.
  </Accordion>

  <Accordion title="NFC-e">
    Nota Fiscal de Consumidor Eletrônica (model 65) — the invoice used for retail sales to end consumers.

    Delivered with `document_type` set to `NFCe`.
  </Accordion>

  <Accordion title="CT-e">
    Conhecimento de Transporte Eletrônico — the document that covers freight and transport services.

    Delivered with `document_type` set to `CTe`.
  </Accordion>

  <Accordion title="NFS-e">
    Nota Fiscal de Serviço Eletrônica — the invoice used for services.

    <Note>
      NFS-e has no national standard: each municipality defines its own XML layout, and many of them carry no access key. For those documents the `id` field is a hash of the XML content, and `access_key` is empty.
    </Note>

    Delivered with `document_type` set to `NFSe`.
  </Accordion>

  <Accordion title="CF-e">
    Cupom Fiscal Eletrônico — the electronic sales receipt issued by SAT and MFE devices.

    Delivered with `document_type` set to `CFe`.
  </Accordion>
</AccordionGroup>

When **Include document events** is enabled, the events attached to a document are delivered in the same stream as the document they belong to, identified by `document_type` set to `Evento`. Events cover cancellations, correction letters (CC-e), and operation manifestations.

## Things to keep in mind

<Warning>
  The SIEG API allows **30 requests per minute per API key**, and returns at most 50 documents per request. The extraction respects this limit, which caps it at roughly 1,500 documents per minute. Loading several years of history can take hours, so set the Initial sync date to the oldest date you actually need.
</Warning>

* The API does not expose a per-document upload timestamp, so `updated_at` has the granularity of the configured window size (one day by default).
* Each run re-reads the last window that returned documents, so documents filed after the previous run are still picked up. Duplicates are resolved by `id`.
* Only the document types listed above are available. Fiscal reports, certificate management, and document manifestation are not part of this source.
