Skip to content

Instantly share code, notes, and snippets.

@sperand-io
Last active August 28, 2020 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sperand-io/8f61ccb515ba075218a239154540684f to your computer and use it in GitHub Desktop.
Save sperand-io/8f61ccb515ba075218a239154540684f to your computer and use it in GitHub Desktop.
segment events -> rockset
// 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)
})
}
@veeve
Copy link

veeve commented Aug 26, 2020

❤️

@sperand-io
Copy link
Author

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