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

# IUGU as a data source

> Bring data from IUGU to Nekt.

IUGU is a payment processing platform designed for Brazilian businesses. It provides tools for accepting online payments, managing subscriptions, and handling financial transactions securely, helping companies streamline their payment operations and improve cash flow.

<img height="80" src="https://mintcdn.com/nekt/0tn1_nwKYqAHn7jo/assets/logo/logo-iugu.png?fit=max&auto=format&n=0tn1_nwKYqAHn7jo&q=85&s=58894d6f064c94fd9b4e67f9630ade94" data-path="assets/logo/logo-iugu.png" />

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

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

### 1. Add account access

Connect using your IUGU API token. See [IUGU authentication](https://dev.iugu.com/reference/autentica%C3%A7%C3%A3o#criar-api_token) for where to create the token in your IUGU account.

The following configurations are available:

* **API Token**: Credential used to call the IUGU API on your behalf (stored securely).

* **Start Date**: The earliest point in time from which incremental streams sync records (based on each stream’s replication key).

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. You can select entire groups of streams or pick specific ones.

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

All IUGU streams use `updated_at` as the replication key where applicable, so incremental syncs advance based on last update time.

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/get-started/core-concepts/triggers), 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.

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.</Warning>

# Streams and Fields

Below you'll find all available data streams from IUGU and their corresponding fields:

<AccordionGroup>
  <Accordion title="Customers">
    Stream for customer profiles, contact data, addresses, and saved payment methods.

    **Key fields:**

    * `id` - Unique customer identifier
    * `email` - Primary email
    * `name` - Customer name
    * `cpf_cnpj` - Tax ID (CPF or CNPJ)
    * `notes` - Internal notes
    * `created_at`, `updated_at` - Timestamps (replication uses `updated_at`)

    **Contact & notifications:**

    * `cc_emails` - Additional emails copied on notifications
    * `phone`, `phone_prefix` - Phone number and prefix

    **Address:**

    * `zip_code`, `street`, `number`, `complement`, `district`, `city`, `state`

    **Payment methods:**

    * `payment_methods` - Array of saved methods (`id`, `description`, `item_type`, `customer_id`, `data` with card metadata such as `brand`, `holder_name`, `display_number`, `bin`, `last_digits`, `first_digits`, expiration, `fingerprint`, etc.)
    * `default_payment_method_id` - Default method id
    * `proxy_payments_from_customer_id` - Customer id when payments are proxied from another customer

    **Metadata:**

    * `custom_variables` - Array of `{ name, value }`
  </Accordion>

  <Accordion title="Invoices">
    Stream for invoices (charges), including payer data, line items, Pix/boleto context, splits, and financial return schedule.

    **Key fields:**

    * `id` - Unique invoice identifier
    * `status` - Invoice status
    * `currency` - Currency code
    * `due_date` - Due date
    * `updated_at` - Last update (replication key)
    * `subscription_id` - Related subscription when applicable
    * `customer_id`, `customer_name`, `customer_ref` - Customer link and display fields
    * `order_id`, `external_reference` - External system references

    **Amounts (cents and formatted strings):**

    * `total_cents`, `total_paid_cents`, `paid_cents`, `tax_cents`, `taxes_paid_cents`, `discount_cents`, `overpaid_cents`, `refunded_cents`, `remaining_captured_cents`, `commission_cents`, `advance_fee_cents`, and formatted counterparts such as `total`, `total_paid`, `paid`, `commission`, `discount`, `interest`, etc.

    **Payer:**

    * `payer_name`, `payer_email`, `payer_cpf_cnpj`, `payer_phone`, `payer_phone_prefix`
    * `payer_address_*` - Zip, street, district, city, state, number, complement, country

    **Payment & notifications:**

    * `payable_with` - Allowed payment methods
    * `payment_method` - Method used when paid
    * `notification_url`, `return_url`, `secure_id`, `secure_url` - Hosted pay link and callbacks
    * `ignore_due_email`, `ignore_canceled_email` - Email suppression flags
    * `email`, `cc_emails` - Invoice notification emails

    **Card / acquirer (when applicable):**

    * `credit_card_brand`, `credit_card_bin`, `credit_card_last_4`, `credit_card_tid`, `credit_card_captured_at`, `credit_card_transaction`, `transaction_number`

    **Bank slip & account:**

    * `bank_slip`, `bank_slip_extra_due`, `bank_account_branch`, `bank_account_number`, `account_name`, `account_id`

    **Pix:**

    * `pix` - Object with `qrcode`, `qrcode_text`, `status`, payer fields, `end_to_end_id`, `end_to_end_refund_id`, `account_number_last_digits`

    **Lifecycle timestamps:**

    * String and ISO variants: `created_at` / `created_at_iso`, `paid_at`, `authorized_at` / `authorized_at_iso`, `expired_at` / `expired_at_iso`, `refunded_at` / `refunded_at_iso`, `canceled_at` / `canceled_at_iso`, `protested_at` / `protested_at_iso`, `chargeback_at` / `chargeback_at_iso`, `financial_return_date`, `occurrence_date`

    **Fees, interest, installments:**

    * `late_payment_fine`, `late_payment_fine_cents`, `per_day_interest`, `per_day_interest_cents`, `max_installments_value`, `installments`, `early_payment_discount`, `split_id`, `external_payment_id`, `payment_booklet_id`, `user_id`

    **Nested collections:**

    * `variables` - Template variables (`variable`, `value`)
    * `custom_variables` - Custom metadata (`name`, `value`)
    * `items` - Line items (`id`, `description`, `price_cents`, `quantity`, `price`, timestamps)
    * `financial_return_dates` - Per-installment settlement rows (`installment`, `return_date`, `amount_cents`, `status`, fees, `advanced`, etc.)
    * `split_rules` - Split configuration per recipient and payment method, including cents/percent fields for credit card (1x–18x), bank slip, and Pix
    * `logs` - Event or status log entries (array)

    **Other:**

    * `refundable`, `duplicated_invoice_id`, `double_payment_id`, `original_payment_id`
  </Accordion>

  <Accordion title="Plans">
    Stream for subscription plan definitions, pricing per currency, features, and billing rules.

    **Key fields:**

    * `id` - Unique plan identifier
    * `name` - Plan display name
    * `identifier` - Stable plan string identifier (referenced by subscriptions)
    * `interval`, `interval_type` - Billing interval length and unit
    * `created_at`, `updated_at` - Timestamps (replication uses `updated_at`)

    **Pricing & features:**

    * `prices` - Array of `{ id, currency, value_cents, created_at, updated_at }`
    * `features` - Array of plan features (`id`, `name`, `identifier`, `value`, `important`, `position`, timestamps)

    **Billing configuration:**

    * `payable_with` - Allowed payment methods
    * `max_cycles` - Maximum billing cycles
    * `billing_days` - Day of month for due dates
    * `invoice_max_installments` - Max card installments on plan invoices
  </Accordion>

  <Accordion title="Subscriptions">
    Stream for active and historical subscriptions, including plan reference, customer, add-ons, recent invoices, and audit logs.

    **Key fields:**

    * `id` - Unique subscription identifier
    * `active` - Whether the subscription is active
    * `suspended` - Whether billing is suspended
    * `plan_identifier`, `plan_name`, `plan_ref` - Plan link and labels
    * `customer_id`, `customer_name`, `customer_email`, `customer_ref` - Customer link
    * `price_cents`, `currency` - Price and currency
    * `created_at`, `updated_at`, `cycled_at`, `expires_at` - Timestamps (replication uses `updated_at`)

    **Billing behavior:**

    * `payable_with` - Allowed payment methods
    * `max_cycles`, `cycles_count` - Cycle limits and count
    * `ignore_due_email` - Due email suppression
    * `suspend_on_invoice_expired`, `two_step`, `in_trial` - Workflow flags

    **Credits:**

    * `credits_based`, `credits`, `credits_min`, `credits_cycle`

    **Features & line items:**

    * `features` - Same shape as on plans (active on this subscription)
    * `subitems` - Add-on lines (`description`, `quantity`, `price_cents`, `recurrent`, `price`, `total`)

    **Related invoices & history:**

    * `recent_invoices` - Recent invoices (`id`, `due_date`, `status`, `total`, `secure_url`)
    * `logs` - Audit entries (`description`, `notes`, `subscription_changes`, `created_at`)

    **Metadata:**

    * `custom_variables` - Array of `{ name, value }`
  </Accordion>
</AccordionGroup>

# Data Model

The diagram below shows how the main IUGU streams relate. Join keys reflect typical analytics use; `plan_identifier` on subscriptions matches `identifier` on plans.

```mermaid theme={null}
graph TD;
    subgraph "Core entities"
        Customers("customers");
        Plans("plans");
        Subscriptions("subscriptions");
        Invoices("invoices");
    end

    Subscriptions -- "customer_id" --> Customers;
    Subscriptions -- "plan_identifier matches plans.identifier" --> Plans;
    Invoices -- "customer_id" --> Customers;
    Invoices -- "subscription_id" --> Subscriptions;
```

# Use Cases for Data Analysis

Examples below assume default table names in the raw layer (`iugu_customers`, `iugu_invoices`, `iugu_plans`, `iugu_subscriptions`). Adjust schema and table names to match your catalog. Run queries in [Explorer](https://app.nekt.ai/explorer).

### 1. Invoice volume and totals by status

Summarize how much was billed and collected, grouped by invoice status.

**Business value:**

* Monitor cash position and outstanding receivables
* Compare paid vs. open or canceled invoices over a period

<Accordion title="SQL query">
  <Tabs>
    <Tab title="AWS">
      ```sql theme={null}
      SELECT
         i.status,
         COUNT(*) AS invoice_count,
         SUM(i.total_cents) / 100.0 AS total_billed,
         SUM(i.total_paid_cents) / 100.0 AS total_paid
      FROM
         nekt_raw.iugu_invoices i
      WHERE
         CAST(i.updated_at AS TIMESTAMP) >= CURRENT_TIMESTAMP - INTERVAL '90' DAY
      GROUP BY
         i.status
      ORDER BY
         total_billed DESC
      ```
    </Tab>

    <Tab title="GCP">
      ```sql theme={null}
      SELECT
         i.status,
         COUNT(*) AS invoice_count,
         SUM(i.total_cents) / 100.0 AS total_billed,
         SUM(i.total_paid_cents) / 100.0 AS total_paid
      FROM
         `nekt_raw.iugu_invoices` i
      WHERE
         TIMESTAMP(i.updated_at) >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 90 DAY)
      GROUP BY
         i.status
      ORDER BY
         total_billed DESC
      ```
    </Tab>
  </Tabs>
</Accordion>

### 2. Active subscriptions with customer email

List active subscriptions joined to customers for outreach or churn analysis.

**Business value:**

* Segment subscribers by plan or contact
* Join subscription flags to customer master data

<Accordion title="SQL query">
  <Tabs>
    <Tab title="AWS">
      ```sql theme={null}
      SELECT
         s.id AS subscription_id,
         s.plan_name,
         s.customer_email,
         c.name AS customer_name,
         s.price_cents / 100.0 AS price,
         s.currency,
         s.cycles_count,
         s.updated_at
      FROM
         nekt_raw.iugu_subscriptions s
         LEFT JOIN nekt_raw.iugu_customers c ON s.customer_id = c.id
      WHERE
         s.active = true
      ORDER BY
         s.updated_at DESC
      ```
    </Tab>

    <Tab title="GCP">
      ```sql theme={null}
      SELECT
         s.id AS subscription_id,
         s.plan_name,
         s.customer_email,
         c.name AS customer_name,
         s.price_cents / 100.0 AS price,
         s.currency,
         s.cycles_count,
         s.updated_at
      FROM
         `nekt_raw.iugu_subscriptions` s
         LEFT JOIN `nekt_raw.iugu_customers` c ON s.customer_id = c.id
      WHERE
         s.active = TRUE
      ORDER BY
         s.updated_at DESC
      ```
    </Tab>
  </Tabs>
</Accordion>

## Implementation Notes

### Amounts and types

* Monetary amounts are often exposed both as integer **cents** fields and as **formatted strings** from the API; prefer `_cents` columns for aggregations when available.
* Some invoice timestamp fields exist as plain strings alongside `*_iso` datetime fields; use the ISO fields when you need reliable temporal filtering.

### Incremental sync

* Streams use `updated_at` as the replication key; set **Start Date** to bound the initial backfill.
* Use **Additional Full Sync** if you need periodic reconciliation with IUGU’s current state.

### API and performance

* Selecting only the streams you need reduces extraction time and API load.
* Large nested arrays (for example `split_rules`, `items`, `payment_methods`) can make rows wide; consider flattening in a downstream Query or Notebook if you model them as separate tables.

## Skills for agents

<Snippet file="agent-skills-intro.mdx" />

<Card title="Download IUGU skills file" icon="wand-magic-sparkles" href="/sources/iugu.md">
  IUGU connector documentation as plain markdown, for use in AI agent contexts.
</Card>
