# Snowflake (apify/snowflake) (`apify/snowflake-apify-snowflake`) Actor

Imports any Apify dataset into a Snowflake table with append or create modes. Supports custom column mapping, automatic table creation with schema inference, batching, resumable imports, and programmatic access token (PAT) authentication. Works standalone or as an Actor-to-Actor integration.

- **URL**: https://apify.com/apify/snowflake-apify-snowflake.md
- **Developed by:** [Apify](https://apify.com/apify) (Apify)
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 25.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-usage

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

Import any Apify dataset into a Snowflake table and query scraped web data with SQL, dbt, or your BI
tools. Start a run in Apify Console, or use the
[Snowflake integration](https://docs.apify.com/integrations/snowflake#schedule-recurring-imports) to
schedule recurring imports without code.

### Main features

- **Insert or create:** write into an existing table, or create the table on the first run and
  append to it on every run after. Neither mode replaces existing data.
- **Column mapping:** choose which dataset fields to import and rename them to match your Snowflake
  columns.
- **Exact names:** by default, column and table names keep their case and special characters.
- **Resumable imports:** rows go in batches of 5,000, with progress saved after each batch. Restarts
  resume after the last saved batch. An interruption before that save can repeat a batch. A new run
  imports every row again, including rows written before a failure.
- **Token authentication:** connect with a Snowflake programmatic access token (PAT), stored as a
  secret input.

### Use cases for Snowflake

- **Competitor pricing:** load prices from a scheduled e-commerce scraper and track them next to your
  sales data.
- **Lead enrichment:** add contact and company data from Apify Actors to your CRM tables.
- **Sentiment analysis:** import reviews and social posts for scoring models and brand monitoring.

### How much does it cost?

See the **Pricing** tab for Apify costs. Snowflake bills the warehouse compute for each import
separately.

### Getting started

1. In Snowflake, create a programmatic access token (PAT) and copy it. It's shown only once. By
   default, your Snowflake user also needs a network policy that allows Apify runs. A Snowflake
   admin may need to apply the [network policy fix](#token-rejected-by-network-policy) in
   Troubleshooting.
2. Run the [SQL snippet](#fill-in-the-input-with-sql) in Snowflake and copy the JSON it returns.
3. In Apify Console, open the **Input JSON** tab and paste the JSON.
4. Add the dataset, your login name, the PAT, and the table name, then choose an import mode.
5. Start the run. When it finishes, the rows are in your Snowflake table.

### Input

All fields below are required except `snowflakeWarehouse`, and `importMode` defaults to `append`.
See the **Input** tab for the rest, including **Column mapping** and **Exact names**.

| Field | Type | Description |
|---|---|---|
| `datasetId` | string | The dataset to import, usually the default one from an Actor or task run. |
| `snowflakeAccount` | string | Your account identifier in `orgname-accountname` format. |
| `snowflakeUsername` | string | Your Snowflake login name. To find it, run `DESCRIBE USER <user_name>;` with the name from `SELECT CURRENT_USER();` and copy `LOGIN_NAME`. |
| `snowflakePat` | string | Your programmatic access token. |
| `snowflakeWarehouse` | string | Leave empty to use your default warehouse. Required if you don't have one. |
| `importMode` | string | `append` (**Insert into existing table**, default) writes into an existing table. `create_new` (**Create new table**) creates the table if it doesn't exist. |
| `destination` | object | The target table as `{database, schema, table}`. |

#### Example input

This input creates a `PRODUCT_PRICES` table on the first run and imports two mapped fields:

```json
{
    "datasetId": "YOUR_DATASET_ID",
    "snowflakeAccount": "myorg-myaccount",
    "snowflakeUsername": "YOUR_LOGIN_NAME",
    "snowflakePat": "YOUR_PAT",
    "importMode": "create_new",
    "destination": {
        "database": "ANALYTICS",
        "schema": "SCRAPED",
        "table": "PRODUCT_PRICES"
    },
    "columnMapping": [
        { "source": "title", "destination": "PRODUCT_TITLE" },
        { "source": "price", "destination": "PRICE" }
    ]
}
```

### Output

Your data lands in the Snowflake table you chose, with nested objects and arrays stored as JSON
text. Each successful run also saves one item to its default dataset with the rows written, the run's
ID, and the full table name. For the example input above, it looks like this:

```json
{
    "rowsImported": 1250,
    "runId": "YOUR_RUN_ID",
    "destination": "ANALYTICS.SCRAPED.PRODUCT_PRICES"
}
```

With **Create new table**, column types come from the first batch of rows.

If a run fails, it saves nothing to its Apify dataset, but batches it already wrote stay in
Snowflake. The run's status message names the failed step. An input error names the field, a
connection error starts with `Failed to connect to Snowflake:`, and an import error starts with
`Import failed:`.

### Run it after another Actor

On the other Actor's **Integrations** tab, add Snowflake Data Import, set it to start when the run
succeeds (the `ACTOR.RUN.SUCCEEDED` event), and set **Dataset** to `{{resource.defaultDatasetId}}`.
Each successful run then imports its own dataset.

### Troubleshooting

#### Token rejected by network policy?

By default, Snowflake only accepts a PAT from a user covered by a network policy, and Apify
runs don't connect from fixed IP addresses. A Snowflake admin can:

- Allow connections from any IP address in the user's network policy.
- If no network policy applies, attach an authentication policy with
  `PAT_POLICY = (NETWORK_POLICY_EVALUATION = ENFORCED_NOT_REQUIRED)`.

This setting still enforces any existing network policy.

#### Can't connect to Snowflake?

Check these:

- The account identifier uses `orgname-accountname` format.
- The username is your login name, which can differ from your user name.
- The PAT hasn't expired.

If Snowflake rejects the PAT, see the [network policy fix](#token-rejected-by-network-policy).

#### Missing privileges?

The connecting user's role needs these grants:

- `USAGE` on the warehouse, database, and schema.
- `CREATE STAGE` on the schema, for the temporary stage each import uses.
- `INSERT` on the table.
- With **Create new table**, also `CREATE TABLE` and `CREATE FILE FORMAT` on the schema.

#### Table not found?

**Insert into existing table** needs a table that already exists. Create it in Snowflake first, or
switch to **Create new table**.

With **Exact names** on, database, schema, and table names are case-sensitive. A table created
without quotes is stored in uppercase. Enter `PRODUCT_PRICES`, not `product_prices`. Run
`SHOW TABLES IN SCHEMA <database>.<schema>;` to check.

#### Mapped column is empty?

Its source field isn't in the dataset. The run still succeeds but writes empty values. Names are
case-sensitive, and the run log lists the ones that didn't match.

#### Field missing from the table?

Without column mapping, the columns come from the first 5,000 rows. A field that first appears later
isn't imported. With mapping set, only mapped fields are imported. List it under **Column
mapping** with every other field you want.

#### Queries can't find your columns?

With **Exact names** on, names are case-sensitive. Lowercase and mixed-case fields, like `title` and
`productName`, need double quotes, like `SELECT "title", "productName" FROM ...`. To query a new
table without quotes, map fields to uppercase names in **Column mapping**, or turn the setting off.
Neither option renames existing columns.

#### Need support or a custom feature?

If none of these fixes helps, open an issue on the **Issues** tab with your input and the run's
status message. Remove the PAT first. For a different destination or behavior,
[ask Apify for a custom solution](https://apify.com/custom-solutions).

### Fill in the input with SQL

The snippet fills in the first-run fields except `datasetId`, `snowflakeUsername`, `snowflakePat`,
`importMode`, and `destination.table`. Select your warehouse, database, and schema in the worksheet
first, or the snippet leaves them out.

```sql
SELECT OBJECT_CONSTRUCT(
    'snowflakeAccount', CURRENT_ORGANIZATION_NAME() || '-' || CURRENT_ACCOUNT_NAME(),
    'snowflakeWarehouse', CURRENT_WAREHOUSE(),
    'destination', OBJECT_CONSTRUCT(
        'database', CURRENT_DATABASE(),
        'schema', CURRENT_SCHEMA(),
        'table', ''
    )
) AS actor_input;
```

# Actor input Schema

## `datasetId` (type: `string`):

Usually the default dataset of an Actor or task run. To import each run of another Actor, set it to `{{resource.defaultDatasetId}}` in that Actor's integration.

## `snowflakeAccount` (type: `string`):

Uses `orgname-accountname` format, like `myorg-myaccount`. Go to Snowflake -> Your Account -> Connect a tool to Snowflake -> Account identifier, or run `SELECT CURRENT_ORGANIZATION_NAME() || '-' || CURRENT_ACCOUNT_NAME();`.

## `snowflakeUsername` (type: `string`):

Go to Snowflake -> Your Account -> Connect a tool to Snowflake -> Login name, or run `DESCRIBE USER <user_name>;` with the name from `SELECT CURRENT_USER();` and copy `LOGIN_NAME`.

## `snowflakePat` (type: `string`):

Go to Snowflake -> Your Account -> Settings -> Authentication -> Programmatic access tokens and generate one, or run `ALTER USER ADD PROGRAMMATIC ACCESS TOKEN <token_name>;` in Snowflake. Snowflake shows the token only once.

## `snowflakeWarehouse` (type: `string`):

Leave empty to use your default warehouse. Required if you don't have one. To check, run `SELECT CURRENT_WAREHOUSE();` in Snowflake.

## `importMode` (type: `string`):

Both options add rows and never replace data. Create new table (`create_new`) also creates a missing table.

## `destination` (type: `object`):

Snowflake table to write into. With <b>Exact names</b> on, matching is case-sensitive. Names are uppercase by default. To check, run a `SHOW` command. Browse what you can access in Snowsight's Databases explorer, Snowflake's web interface.

## `columnMapping` (type: `array`):

Import only these fields, under these column names, in either mode. Leave empty to import every field in the first 5,000 rows. A source field missing from the dataset imports as an empty column.

## `quoteIdentifiers` (type: `boolean`):

When on, database, schema, table, and column names keep their case and special characters. Names must match exactly. Names with lowercase letters, spaces, or special characters need double quotes in queries. When off, names are uppercase and unquoted, and column names can only use letters, digits, and underscores, starting with a letter or underscore. Other names fail the run.

## Actor input object example

```json
{
  "importMode": "append",
  "columnMapping": [],
  "quoteIdentifiers": true
}
```

# Actor output Schema

## `importResult` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("apify/snowflake-apify-snowflake").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("apify/snowflake-apify-snowflake").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call apify/snowflake-apify-snowflake --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,apify/snowflake-apify-snowflake"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/YImkGPGGqOE4kPdqX/builds/uTGjzj67uG5je4V5Y/openapi.json
