# Snowflake

The **Snowflake Node** allows you to interact with a Snowflake database—either by querying data or inserting new records.

***

### Connecting to Snowflake — API Key

Click the node to open its settings, then select **New connection**.

![](https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2Fu2gH4mUA2IKV46iUiBI3%2Fimage.png?alt=media\&token=b6e5e2f0-dc86-4f5f-8da9-ca9306a6630b)

Enter the required connection details into the form according to the table and notes below:

| Field                      | Value                                            |
| -------------------------- | ------------------------------------------------ |
| **Connection Name**        | This is whatever you want to name the connection |
| **User**                   | Your chosen Snowflake account username           |
| **Password (Optional)**    | Your chosen Snowflake account password           |
| **Private Key (Optional)** | Only if using key-pair authentication            |
| **Account**                | `nqxzcwd-ab12345` (see where to find below)      |
| **Warehouse**              | `DUMMY_WAREHOUSE` (see where to find below)      |
| **Role**                   | `ACCOUNTADMIN` (see where to find below)         |
| **Database**               | `DUMMY_DB` (see where to find below)             |
| **Schema**                 | `DUMMY_SCHEMA` (see where to find below)         |

{% hint style="info" %}
**Note**: You need to enter at least one of the two optional fields
{% endhint %}

### Account

This is your account identifier. Find it here:

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2Fw84Udsixeo3Pi4fl5qFx%2Fimage.png?alt=media&#x26;token=23ca4fbd-f9f0-45d2-939b-8f1cc18318c3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2FOQX5VRsrHkdozKAGKMVn%2Fimage.png?alt=media&#x26;token=84fdceac-c22c-4ae2-89a6-24bb3a398ba4" alt=""><figcaption></figcaption></figure>

### Warehouse

Find it here:

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2FlElrA7OejuZUSscEs78u%2Fimage.png?alt=media&#x26;token=fd082911-3d0d-4236-9397-2b7973af5370" alt=""><figcaption></figcaption></figure>

### Role

Find it here:

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2F1DbRnlZ6WvNdU8XkOEFR%2Fimage.png?alt=media&#x26;token=bc09f5ca-bbf6-4dac-82be-bb3ca962250d" alt=""><figcaption></figcaption></figure>

### Database

Find it here:

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2F0s6TM772Wc5Cg3HdJGFl%2Fimage.png?alt=media&#x26;token=4f2b378b-e277-4995-a812-4a4174319490" alt=""><figcaption></figcaption></figure>

### Schema

Find it here:

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2Fc0l0g2dlIi4zUBYKXo0k%2Fimage.png?alt=media&#x26;token=fc2404f0-90f4-4150-89d5-84a9f9256556" alt=""><figcaption></figcaption></figure>

### Connecting to Snowflake — OAuth2

For your organization's users to connect to Snowflake using OAuth2, you must first create an OAuth2 App inside Snowflake. Once this app is created, users can use it to sign-into Snowflake via OAuth2 in third-party applications.&#x20;

To create the OAuth2 App, first have someone with the ACCOUNTADMIN role run the following script in Snowflake:

```sql
CREATE OR REPLACE SECURITY INTEGRATION STACKAI_OAUTH_APP
  TYPE = OAUTH
  ENABLED = TRUE
  OAUTH_CLIENT = CUSTOM
  OAUTH_CLIENT_TYPE = 'CONFIDENTIAL'
  OAUTH_REDIRECT_URI = 'https://www.stackai.com/auth'
  OAUTH_ISSUE_REFRESH_TOKENS = TRUE
  OAUTH_REFRESH_TOKEN_VALIDITY = 7776000  -- ~90 days
  BLOCKED_ROLES_LIST = ('SYSADMIN');      -- optional: prevent high-privilege roles
;
```

Once the integration has been created, run the following to get a `client_id` and `client_secret`:

```sql
SELECT SYSTEM$SHOW_OAUTH_CLIENT_SECRETS('STACKAI_OAUTH_APP');
```

Store this information as you will need it to make an OAuth2 connection.

#### Creating a custom OAuth connector

To use your personal Snowflake OAuth client in StackAI, you need to first create a custom connector in **Settings -> Connectors**. Here, select **+ New Connector.**

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2FURid3xjirEmGDWs1zhli%2FScreenshot%202026-02-03%20at%202.16.23%E2%80%AFPM.png?alt=media&#x26;token=34d5eb87-2302-4ac7-9602-96ad6b204be6" alt=""><figcaption></figcaption></figure>

Select **Snowflake (OAuth2)** and **Create Connector**.

Once you've created a new connector, it will be in draft until you add the required fields. Edit the Connector and add the client ID and client secret from Snowflake.

You have the option of setting custom scopes for your connector. If you'd like the connections your users make to always use a specific Snowflake role, replace the placeholder `session:role:PUBLIC` scope with `session:role:{YOUR_ROLE}`. If you'd like your connection to inherit the user's default role, you can just delete this placeholder scope.

Make sure the required fields are filled in, then hit **Save**.

#### Creating a connection with your Connector

When entering the new connection dialog, select Snowflake, then select the Connector you created. You should be redirected to sign in to Snowflake.

<figure><img src="https://3697023207-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFSlso1Kjob5CLDrh0dVn%2Fuploads%2FqpJGfnqRvzIcf5NzzmDO%2Fsnowflake_sign_on.gif?alt=media&#x26;token=b06a0b5c-8ade-4e68-b17d-775b3d488ce4" alt=""><figcaption></figcaption></figure>

### Available Actions

#### 1. Query a Snowflake Database (`database_query_snowflake`)

* **Description:**\
  Run queries against your Snowflake database and retrieve results.
* **Inputs:**
  * `sql_schema` (array of strings, required):\
    The schema of your database (tables, columns, types, etc.).\
    Example:

    ```
    TABLE MyTable (Name TEXT, Email TEXT, Weight REAL, Height REAL);
    ```
  * `query` (string, required):\
    The query you want to run. This can be in plain English or SQL.\
    Example:
    * "What is the total revenue for the year 2024?"
    * "Show me the top 10 customers by revenue"
    * "SELECT \* FROM MyTable WHERE Name = 'John'"
* **Outputs:**
  * `sql_query` (string): The SQL query that was executed.
  * `results` (array of objects): The results of the query.

#### 2. Insert Data into Snowflake (`database_insert_snowflake`)

* **Description:**\
  Insert new records into a table in your Snowflake database.
* **Inputs:**
  * `table_name` (string, required):\
    The name of the table where you want to insert data.
  * `data` (object/dictionary, required):\
    The data to insert, as key-value pairs where keys are column names and values are the data.\
    Example:

    ```
    {
      "name": "John Doe",
      "email": "john@example.com",
      "age": 30,
      "is_active": true
    }
    ```
* **Outputs:**
  * `sql_query` (string): The INSERT SQL query that was executed.
  * `rows_affected` (integer): Number of rows affected by the insert.
  * `success` (boolean): Whether the insert was successful.

***

### Summary Table

| Action Name                | Description                     | Key Inputs         | Key Outputs                         |
| -------------------------- | ------------------------------- | ------------------ | ----------------------------------- |
| Query Snowflake Database   | Run queries and get results     | sql\_schema, query | sql\_query, results                 |
| Insert Data into Snowflake | Insert new records into a table | table\_name, data  | sql\_query, rows\_affected, success |
