Last active
August 28, 2020 05:36
-
-
Save sperand-io/8f61ccb515ba075218a239154540684f to your computer and use it in GitHub Desktop.
segment events -> rockset
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://segment.com/docs/connections/functions/destination-functions/ | |
export const track = insertEvent | |
export const identify = insertEvent | |
export const page = insertEvent | |
export const screen = insertEvent | |
export const group = insertEvent | |
// https://docs.rockset.com/rest-api/#patchdocuments | |
const insertEvent = async (msg, { collection, workspace, apiKey }) => { | |
const endpoint = `https://api.rs2.usw2.rockset.com/v1/orgs/self/ws/${workspace}/collections/${collection}/docs` | |
return await fetch(endpoint, { | |
method: 'post', | |
headers: { | |
Authorization: `ApiKey ${apiKey}`, | |
'content-type': 'application/json' | |
}, | |
body: JSON.stringify(msg) | |
}) | |
} |
Body attribute should be:
JSON.stringify({ data: [msg] })
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
❤️