Snowflake

A data warehouse built for the cloud

Go to site
Explore
/
Apps
/
Snowflake

Snowflake API Integrations

Build and run workflows using the Snowflake API. Use 1000s of open source triggers and actions across 500+ apps. Or write custom code to integrate any app or API in seconds.

// Example query
const sqlText = `SELECT CURRENT_TIMESTAMP();`

const { promisify } = require('util')
const snowflake = require('snowflake-sdk')

const connection = snowflake.createConnection(auths.snowflake)

const connectAsync = promisify(connection.connect)

try {
  await connectAsync()
} catch (err) {
  console.error('Unable to connect: ' + err.message)
}

// util.promisify requires the last argument of the function you pass to 
// it be the callback function, according to Node convention — see the docs at
// https://nodejs.org/dist/latest-v8.x/docs/api/util.html#util_util_promisify_original .
// Since Snowflake's connection.execute function accepts a single argument — 
// options, an object — using promisify won't work. So we wrap the callback 
// with a Promise and await it below.
//
// Pass the same options object (e.g. sqlText, binds), _except_ for the callback
// parameter. Instead, you'll want to await the result, which contains the 
// stmt and rows object the callback version of the function passes, using 
// a catch block to catch any errors, e.g.
//
//   try {
//     const { stmt, rows } = await connExecuteAsync({
//       sqlText: `insert into your_table select parse_json('{"foo": "bar"}')`,
//     })
//   } catch (err) {
//     console.error(`Failed to execute statement due to the following error: ${err.message}`)
//   }
//
async function connExecuteAsync(options) {
  return new Promise((resolve, reject) => {
    const statement = connection.execute({
      ...options,
      complete: function(err, stmt, rows) {
        if (err) {
          reject(err)
        } else {
          resolve({stmt, rows})
        }
      }
    })
  })
}

try {
  const { stmt, rows } = await connExecuteAsync({
    sqlText,
    fetchAsString: ['Number', 'Date'],
  })
  console.log(JSON.stringify(rows, null, 2))
} catch (err) {
  console.error(`Failed to execute statement due to the following error: ${err.message}`)
}

Authentication

Snowflake uses API keys for authentication. When you connect your Snowflake account, Pipedream securely stores the keys so you can easily authenticate to Snowflake APIs in both code and no-code steps.

Enter the username, password, and other details for your Snowflake database below.

For the account field, enter your Snowflake account name.