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

# Snowflake integration

> Create a read-only Snowflake user for End Close so warehouse data can feed data streams you reconcile.

The Snowflake integration lets End Close read tables in your Snowflake account, so warehouse data can feed End Close [data streams](https://endclose.com/docs/concepts/data-streams.md) and be reconciled. You create a read-only user in your account, attach a public key that we send you, and send us the connection details. You never send us a password or private key.

## At a glance

| | |
| - | - |
| **Connects as** | A read-only Snowflake service user that signs in with a key pair |
| **Data synced** | Warehouse rows, as records in Snowflake data streams |
| **Who can set it up** | A Snowflake admin in your account; End Close sets up the streams with you |
| **Per environment** | Yes. Each End Close environment has its own Snowflake connection. |

## Prerequisites

* A Snowflake role that can create roles, users and warehouses, such as `SECURITYADMIN` and `SYSADMIN`.
* Ownership of the tables End Close should read, or the help of whoever owns them, to turn on change tracking.
* The public key End Close sends you for your account. Email [founders@endclose.com](mailto:founders@endclose.com) to get one.

## Create a role, warehouse and user

The following creates a role, a small warehouse that suspends itself when idle, and a service user with both as defaults. `SECURITYADMIN` creates the role and user, and `SYSADMIN` creates the warehouse. Replace the key with the public key we sent you.

```sql theme={"dark"}
USE ROLE SECURITYADMIN;

CREATE ROLE IF NOT EXISTS ENDCLOSE_ROLE;
GRANT ROLE ENDCLOSE_ROLE TO ROLE SYSADMIN;

USE ROLE SYSADMIN;

CREATE WAREHOUSE IF NOT EXISTS ENDCLOSE_WAREHOUSE
  WAREHOUSE_SIZE = XSMALL
  AUTO_SUSPEND = 60
  AUTO_RESUME = TRUE
  INITIALLY_SUSPENDED = TRUE;
GRANT USAGE, OPERATE, MONITOR ON WAREHOUSE ENDCLOSE_WAREHOUSE TO ROLE ENDCLOSE_ROLE;

USE ROLE SECURITYADMIN;

CREATE USER IF NOT EXISTS ENDCLOSE_USER
  TYPE = SERVICE
  DEFAULT_ROLE = ENDCLOSE_ROLE
  DEFAULT_WAREHOUSE = ENDCLOSE_WAREHOUSE
  RSA_PUBLIC_KEY = 'MIIBIjANBgkqh...';
GRANT ROLE ENDCLOSE_ROLE TO USER ENDCLOSE_USER;
```

Paste the public key without its `BEGIN` and `END` lines. A service user can only sign in with its key, so there is no password to manage.

Each sync runs queries on this warehouse, and Snowflake bills you for the credits. An X-Small warehouse that auto-suspends keeps that cost low.

## Grant read access

Grant the role read access to each schema End Close should read. Replace `FINANCE` and `FINANCE.PAYMENTS` with your own database and schema.

```sql theme={"dark"}
USE ROLE SECURITYADMIN;

GRANT USAGE ON DATABASE FINANCE TO ROLE ENDCLOSE_ROLE;
GRANT USAGE ON SCHEMA FINANCE.PAYMENTS TO ROLE ENDCLOSE_ROLE;

GRANT SELECT ON ALL TABLES IN SCHEMA FINANCE.PAYMENTS TO ROLE ENDCLOSE_ROLE;
GRANT SELECT ON FUTURE TABLES IN SCHEMA FINANCE.PAYMENTS TO ROLE ENDCLOSE_ROLE;
GRANT SELECT ON ALL VIEWS IN SCHEMA FINANCE.PAYMENTS TO ROLE ENDCLOSE_ROLE;
GRANT SELECT ON FUTURE VIEWS IN SCHEMA FINANCE.PAYMENTS TO ROLE ENDCLOSE_ROLE;
```

To limit access to particular tables, grant `SELECT` on each table instead of the schema-wide grants.

## Turn on change tracking

Change tracking lets End Close read only the rows that changed since the last sync instead of the whole table. The table owner runs this for each table:

```sql theme={"dark"}
ALTER TABLE FINANCE.PAYMENTS.TRANSACTIONS SET CHANGE_TRACKING = TRUE;
```

Snowflake records changes only from the moment tracking is on. End Close copies each table in full once, then reads changes from there.

Changes are kept for as long as the table's Time Travel retention. Keep `DATA_RETENTION_TIME_IN_DAYS` at 1 or more; 1 is Snowflake's default. If you're on Enterprise edition, 7 days gives more room to catch up after an interruption without copying the table again:

```sql theme={"dark"}
ALTER TABLE FINANCE.PAYMENTS.TRANSACTIONS SET DATA_RETENTION_TIME_IN_DAYS = 7;
```

To check a table, run `SHOW TABLES LIKE 'TRANSACTIONS' IN SCHEMA FINANCE.PAYMENTS` and look at the `change_tracking` column.

> [!WARNING]
>
> If dbt builds a table with the `table` materialization, each run replaces the table and turns change tracking off. Use incremental models for tables End Close reads.

## Send us the details

Email [founders@endclose.com](mailto:founders@endclose.com) with:

| Detail | Example |
| - | - |
| Account identifier | `myorg-myaccount` |
| User | `ENDCLOSE_USER` |
| Role | `ENDCLOSE_ROLE` |
| Warehouse | `ENDCLOSE_WAREHOUSE` |
| Tables, with the unique identifier for each | `FINANCE.PAYMENTS.TRANSACTIONS` (`ID`) |
| Whether you use a network policy | Yes or no |

None of these are secret. Your account identifier is the part of your Snowflake URL before `.snowflakecomputing.com`.

Snowflake doesn't enforce primary keys, so name the unique identifier for each table even if one is declared. A row with an empty identifier can't be synced. Each row also needs an amount, a date and a direction (credit or debit). End Close sets up your Snowflake streams from these tables with you.

If you'd rather send the data yourself, push it to an API data stream. See the [API overview](https://endclose.com/docs/api-reference/overview.md).

## Revoke access

To disconnect End Close, disable the user. Syncs stop at once.

```sql theme={"dark"}
USE ROLE SECURITYADMIN;

ALTER USER ENDCLOSE_USER SET DISABLED = TRUE;
```

## FAQ

> [accordion] Do I send End Close a password or private key?
>
> No. End Close generates a key pair for your account, keeps the private key and sends you the public key. You attach the public key to the user, and you can revoke access at any time by disabling the user.

> [accordion] My account uses a network policy. What do I allow?
>
> Tell us when you send the details. We'll send you the IP addresses to add to the policy's allowed list.

> [accordion] Can I connect Snowflake in more than one environment?
>
> Yes. Each environment has its own connection. Records synced into one environment don't appear in another.

## Related

> [card] [Data streams](https://endclose.com/docs/concepts/data-streams.md)
>
> How streams hold records and feed reconciliations.

> [card] [How connections work](https://endclose.com/docs/integrations/how-connections-work.md)
>
> Streams, environments and who can connect.


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