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

# Snowflake SQL API

> Client-mode REST API connector for the Snowflake SQL API: submit a statement and poll its handle

Technical Preview

# Snowflake

Client-mode REST API connector for the Snowflake SQL API: submit a statement and poll its handle.

* Hub category: **Analytics**.
* Base: `https://ACCOUNT.snowflakecomputing.com`

## Template reference

Generated from the shipped broker template `snowflake-sql-api` (`-routeCode SNOWFLAKE_SQL_API`). It lists every event the template defines.

### Auth

Auth headers used by the template: `Authorization: Bearer {value.json.api_token}`, `X-Snowflake-Authorization-Token-Type: {value.json.token_type}`.

### Template parameters

| Placeholder | Type | Description | Required |
| - | - | - | - |
| `RouteName` | string | Name of the Snowflake SQL API connector | no |
| `BaseUrl` | string | Snowflake SQL API base URL without trailing slash (e.g. [https://ACCOUNT.snowflakecomputing.com](https://ACCOUNT.snowflakecomputing.com)) | yes |

`BASE_ADDRESS` default: `https://ACCOUNT.snowflakecomputing.com`.

### Events

| Event | Method | Endpoint | Request topic | Response topic | Payload fields |
| - | - | - | - | - | - |
| `Submitstatement` | POST | `/api/v2/statements` | `analytics/snowflake/statements/submit` | `analytics/snowflake/statements/submit/response` | `api_token`, `body`, `token_type` |
| `Getstatement` | GET | `/api/v2/statements/{value.json.statement_handle}` | `analytics/snowflake/statements/get` | `analytics/snowflake/statements/get/response` | `api_token`, `statement_handle`, `token_type` |

### Deploy

Get the template card (JSON with `template` and `metadata`) from the broker, then deploy the connector:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_pub -t '$SYS/Coreflux/Command' -m "-routeCode SNOWFLAKE_SQL_API"
```

The deployable connector from the REST API app, with `BASE_ADDRESS` already filled in:

```lot theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
DEFINE ROUTE SnowflakeRestApi WITH TYPE REST_API
    ADD REST_API_CONFIG
        WITH BASE_ADDRESS "https://ACCOUNT.snowflakecomputing.com"
        WITH ENABLE_CLIENT "true"
        WITH USE_SSL "true"
        WITH REQUEST_TIMEOUT '60'
        WITH DEFAULT_CONTENT_TYPE "application/json"
    ADD EVENT Submitstatement
        WITH SOURCE_TOPIC "analytics/snowflake/statements/submit"
        WITH DESTINATION_TOPIC "analytics/snowflake/statements/submit/response"
        WITH METHOD "POST"
        WITH ENDPOINT "/api/v2/statements"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Content-Type" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
            ADD "X-Snowflake-Authorization-Token-Type" "{value.json.token_type}"
        WITH BODY "{value.json.body}"
    ADD EVENT Getstatement
        WITH SOURCE_TOPIC "analytics/snowflake/statements/get"
        WITH DESTINATION_TOPIC "analytics/snowflake/statements/get/response"
        WITH METHOD "GET"
        WITH ENDPOINT "/api/v2/statements/{value.json.statement_handle}"
        WITH HEADERS
            ADD "Accept" "application/json"
            ADD "Authorization" "Bearer {value.json.api_token}"
            ADD "X-Snowflake-Authorization-Token-Type" "{value.json.token_type}"
```

Deploy it with `-addRoute` (do not include `ADD METADATA`).

### Usage example

Call `Submitstatement` by publishing a JSON payload to its request topic, and read the reply on the response topic:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/lot.json"]}}
mosquitto_sub -t 'analytics/snowflake/statements/submit/response' &
mosquitto_pub -t 'analytics/snowflake/statements/submit' -m '{"api_token": "<api_token>", "body": {}, "token_type": "<token_type>"}'
```


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