Exporting raw data via the API

Exports raw data to downloadable files. Data is split into roughly 256 MB files, and is not necessarily ordered. Each file contains 1 line per session, with each session JSON-encoded. Export files are automatically deleted 24 hours after export occurs. Data becomes available to export every 2 hours, and only for complete sessions. You cannot export data that has become available more than 60 days ago. You may only export data 24 times per day. Exports with invalid arguments do not count towards this limit.

To construct an api call to export raw data, you will need, at least, the following:

  • APP_ID_KEY - Can be found in the keys & settings of your app. 
  • EXPORT_KEY - Can be found in the keys & settings of your app.
  • startDate - this is the date that you would want to export data from.

And your API call will be constructed to look like the following:

https://www.leanplum.com/api?appId=APP_ID_KEY&clientKey=EXPORT_KEY&action=exportData&apiVersion=1.0.6&startDate=YYYYMMDD

The following arguments are optional:

parameter type description
endDate String Last date in range to include in PDT/PST (format: YYYYmmdd). Defaults to startDate if not provided. Example: 20141118
startTime Number First time (when data became available) to include (seconds since midnight UTC on January 1, 1970). If not provided, accepts all times before endTime, or all times if endTime is also not provided. The main use is to set this to the last time you exported data to only get the new data since your last export.
endTime Number Last time (when data became available) to include (seconds since midnight UTC on January 1, 1970). If not provided, accepts all times after startTime, or all times if startTime is also not provided.
callbackUrl String URL to POST a response to when the export completes. The response is the response format of getExportResults.
s3BucketName String The name of an AWS S3 bucket to copy exported files to.
s3AccessId String The AWS Access ID used to authenticate to S3. Required if s3BucketName is set.
s3AccessKey String The AWS Secret Access Key used to authenticate to S3. Required if s3BucketName is set.
s3ObjectPrefix String An optional prefix of files to write to S3. Example: dirname/ to write files to a directory within the S3 bucket.
compressData Boolean An option to compress the data. Only works when uploading to S3. If set to true, the files will be compressed using gzip before being uploaded.

Response: 

parameter type description
jobId     String The job ID of the pending export job, if data matching supplied arguments is available.


To then get the files with the jobId, the call would be constructed in the following manner: 

http://www.leanplum.com/api?appId=APP_ID_KEY&clientKey=EXPORT_KEY&apiVersion=1.0.6&action=getExportResults&jobId=JOBID_HERE

To automate this process with a Python Script, please see more here

An example line within the data export would look like the following. It will give you data about a user's session such as their device, the events that they've triggered, userAttributes and etc.:


{
  "region":"OR",
  "priorStates":4,
  "systemName":"iOS",
  "deviceModel":"iPod Touch",
  "states":[
    {
      "time":1.459788695167E9,
      "duration":35.93,
      "name":"Main Menu"
    },
    {
      "events":[
        {
          "time":1.459788731097E9,
          "name":"Wheel clicked",
          "value":0,
          "parameters": {
            "item":"Handyman"
          }
        },
        {
          "timeUntilFirstForUser":166.3,
          "time":1.459788731097E9,
          "name":".m6704786382520320 View",
          "value":0
        },
        {
          "timeUntilFirstForUser":166.3,
          "time":1.459788731097E9,
          "name":".m6704786382520320 Accept",
          "value":0
        }
      ]
    },
    {
      "timeUntilFirstForUser":166.3,
      "time":1.459788731097E9,
      "duration":169.8,
      "name":"Handyman"
    },
    {
      "events":[
        {
          "timeUntilFirstForUser":336.1,
          "time":1.459788900897E9,
          "name":"Tap auto-pick",
          "value":0
        },
        {
          "timeUntilFirstForUser":336.1,
          "time":1.459788900897E9,
          "name":"Post handyman task",
          "value":0,
          "parameters": {
            "Auto-pick":"True"
          }
        }
      ]
    }
  ],
  "priorTimeSpentInApp":130.37,
  "country":"US",
  "time":1.459788695167E9,
  "duration":235.73,
  "priorSessions":1,
  "experiments":[
    {
      "id":3756002,
      "variantId":3757003
    },
    {
      "id":5077106989989888,
      "variantId":6681597115891712
    }
  ],
  "appVersion":"1.0",
  "systemVersion":"6.1",
  "userId":"dev164972174",
  "isSession":true,
  "firstRun":1.45978856366E9,
  "timezoneOffsetSeconds":-28800,
  "priorEvents":4,
  "deviceId":"dev164972174"
}

Was this article helpful?
Have more questions? Submit a request