Solved

getting all events correlating with a single distinct id

  • 28 January 2020
  • 4 replies
  • 387 views

  • New Participant
  • 2 replies

Hello! I’m wondering if anyone can advice me on how to use the mixpanel api to get all events coorelating with a single event id. I have figured out how to get all distinct ids in a date range, butI’m having a hard time querying all events associated with an id. 
I’m wondering also, if that might provide me with any data that is not included already in the explore user tab. 

icon

Best answer by scotthavard92 4 February 2020, 19:01

Hi @rwr!

 I want to share an easier and more efficient way of exporting the event data of a user than going the JQL route. You should use  Mixpanel's export API (https://developer.mixpanel.com/docs/exporting-raw-data#section-export-api-reference).

You can export all events connected to a user by passing their distinct_id as part of the “where” parameter. The following snippit is an example curl request that achieves this. 

 

You need to update your API secret, date range, and distinct id of user. 

curl https://data.mixpanel.com/api/2.0/export/ \
-u <API_SECRET_HERE>: \
-d from_date="2019-05-01" \
-d to_date="2020-02-04" \
-d where='properties["$distinct_id"]=="<DISTINCT_ID_OF_USER>"'

 

Stephanie isn’t incorrect when she says “export API was built it was largely built with the scope to generate large dumps of raw event data and unfortunately not query”. Depending on what you mean by query the data (i.e. if you want to run queries in the actual HTTP request), then I would suggest you use the Query API: https://developer.mixpanel.com/docs/data-export-api (not the Raw Export API). 

 

Hope this helps!

View original

4 replies

Userlevel 5
Badge +4

Hi @rwr,

Unfortunately, there's no way to selectively export events from a particular distinct_id through the export API. This is largely due to the fact that distinct_id is not exposed to the API, just the custom properties + default Mixpanel properties on your events.

To give you a bit of background, when the export API was built it was largely built with the scope to generate large dumps of raw event data and unfortunately not query specific distinct_ids. As such, distinct_id isn't exposed through the export API :(

The GOOD news is this can be easily done via JQL with a query like so:

function main() {
return Events({
from_date: '2019-06-01',
to_date: '2020-01-04'
})
.filter(function(event) {return event.distinct_id === 'yourDistinct_idHere'})
}

And, just like our other API's the query can be executed outside of Mixpanel via CURL or any HTTP request generating library as per the documentation here: https://mixpanel.com/help/reference/jql/api-reference#api/access
 

This will provide the event data, which is different from user data that is shown in the explore report. Hope this helps! 

Thank you! That’s so helpful! 

Badge

Hi @rwr!

 I want to share an easier and more efficient way of exporting the event data of a user than going the JQL route. You should use  Mixpanel's export API (https://developer.mixpanel.com/docs/exporting-raw-data#section-export-api-reference).

You can export all events connected to a user by passing their distinct_id as part of the “where” parameter. The following snippit is an example curl request that achieves this. 

 

You need to update your API secret, date range, and distinct id of user. 

curl https://data.mixpanel.com/api/2.0/export/ \
-u <API_SECRET_HERE>: \
-d from_date="2019-05-01" \
-d to_date="2020-02-04" \
-d where='properties["$distinct_id"]=="<DISTINCT_ID_OF_USER>"'

 

Stephanie isn’t incorrect when she says “export API was built it was largely built with the scope to generate large dumps of raw event data and unfortunately not query”. Depending on what you mean by query the data (i.e. if you want to run queries in the actual HTTP request), then I would suggest you use the Query API: https://developer.mixpanel.com/docs/data-export-api (not the Raw Export API). 

 

Hope this helps!

Thank you, Scott! That is fantastic. I appreciate it! 

Reply