jqllib-fetch

Lightweight client for making requests to the Mixpanel JQL API

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
jqllib-fetch
000.2.17 years ago7 years agoMinified + gzip package size for jqllib-fetch in KB

Readme

jqllib-fetch
You have a string containing a Mixpanel JQL query. You want to execute it programatically in Node.
This is a TINY wrapper around request-promises that sets auth headers and request format.
Just do
import * as jqlFetch from 'jqllib-fetch'

jqlFetch.setApiKey("MIXPANEL_SECRET_KEY")

jqlFetch
    .fetch(`return Events(...)...`)    // Returns a Bluebird promise
    .then(events => {
        // Do stuff with your list of events, or whatever your query was
    })

If your JQL is not already wrapped in a "main" function as required by Mixpanel, jqlFetch.fetch will wrap it for you.
jqllib-fetch also plays nicely with jqllib, if you are using TypeScript and want typesafe queries:
import {JQL, MPEvent} from 'jqllib'

const query: JQL<{distinctId: string, events: MPEvent[]}[]> = jqllib.groupedJql(
    ['2016-01-01', '2016-03-01'],
    ['Fantastic Event', 'Fun Event', 'Lil event']
)

jqlFetch
    .fetch(query)
    .then(groups => {
        // do stuff...
    })