Import user data with a CSV file upload

For a one-off import of users or user data, such as adding historic push tokens or user email addresses, you can use a CSV file upload. Once uploaded and processed, this information will be stored in Leanplum and available in our platform for targeting and segmenting users.

You can upload various types of data into Leanplum using the multi (dev) API call, including user attributes, device attributes, events, and email unsubscribes. Depending on what kind of data is being uploaded, you will need to pass different values to the defaultAction parameter in the API, and format the CSV in a specific way for the upload to succeed.

Step 1: Prepare the CSV file
Make sure to save the file in regular CSV format without any encoding.

User Attributes
Note: If you need to send emails to the users you upload, make sure email is included as an attribute in the upload. Otherwise, Leanplum will not be able to send emails to these users.

Field

Data Type

Required

Description

userId

String

YES

The user id. It must be the first column of the CSV file.

userAttributes.<Attribute Name>

String

NO

The name of the user attribute.

Example: userAttributes.facebook_id

We highly recommend validating the data here, for example, if it's an email.

created

Unix timestamp

NO

Use this to set the date and time the user was created. The value has to be in Unix time.

This will allow you to target users based on "time of first run," etc.

lastActive

Unix timestamp

NO

Use this to set the date and time the user was last active. The value has to be in Unix time.

This will allow you to target users based on "last active," etc.

Sample file:

userId

created

lastActive

userAttributes.age

userAttributes.gender

userAttributes.friends

sample_user

1483228800

1496275200

24

female

[Jimmy, Sara, Amy]

This sample file creates a profile like this

Screen_Shot_2017-11-01_at_3.09.19_PM.png

 

Device Attributes

Field

Data Type

Required

Description

userId

String

YES

The user id. It must be the first column of the CSV file.

deviceId

String

YES

The device id. A single user may have multiple device ids.

iosPushToken

String

NO

Use this to set the iOS push token of the device. Push tokens are device specific, so in the CSV file, you must specify which deviceId this token belongs to. This is done by having the device id and the push token on the same row.

systemName

String

No

The value should be either iOS or Android OS. This must match the push token type you are uploading.

background

String

NO

When set to TRUE, the call will not create a new session for the user in Leanplum.

gcmRegistrationId

String

NO

Use this to set the Android push token of the device. Push tokens are device specific, so in the CSV file you must specify which deviceId this token belongs to. This is done by having the deviceId and the push token on the same row.

Sample file:

userId

deviceId

systemName

iosPushToken

gcmRegistrationId

background

sample_user1

ABC-123

iOS

1234567

 

TRUE

sample_user2

ABC-456

Android OS

 

7654321

TRUE

Events

 

Field

Data Type

Required

Description

userId

String

YES

The user id. It must be the first column of the CSV file.

events.<eventName>.count

Integer

NO

New lifetime count of <eventName> for the current user.

events.<eventName>.firstTime

Unix Timestamp

NO

Time that the event first occurred, in seconds since midnight UTC on January 1, 1970.

events.<eventName>.lastTime

Unix Timestamp

NO

Time that the event last occurred, in seconds since midnight UTC on January 1, 1970.

events.<eventName>.countIncrement

Integer

NO

Amount to increment the lifetime count of eventName.

events.<eventName>.value

number(float)

NO

New lifetime value of <eventName> for the current user.

events.<eventName>.valueIncrement

number(float)

NO

Amount to increment the lifetime value of eventName.

Sample file:

userId

events.Purchase.firstTime

events.Purchase.lastTime

events.Purchase.count

events.Purchase.value

sample_user

1483228800

1496275200

3

20

This sample creates a profile like this

Screen_Shot_2017-11-01_at_3.35.17_PM.png

And you can segment users based on number of occurrences of the event in user page. For example

Screen_Shot_2017-11-01_at_3.36.59_PM.png

Screen_Shot_2017-11-01_at_3.38.33_PM.png

Email Unsubscribe/Resubscribe

Field

Data Type

Required?

Description

userId

String

YES

The user id. It must be the first column of the CSV file.

unsubscribeChannelsToAdd

String

NO

Set to "Email" to unsubscribe users from all marketing emails.

unsubscribeChannelsToRemove

String

NO

Set to "Email" to resubscribe users from all marketing emails.


Sample file:

userId

unsubscribeChannelsToAdd

unsubscribeChannelsToRemove

sample_user1

Email

 

sample_user2

 

Email

Step 2: Construct the API call

The API method for CSV upload is multi(dev). You will need to pass different values to the `defaultAction` parameter depending on what kind of data you are uploading.

https://www.leanplum.com/api?action=multi&apiVersion=1.0.6&appId={App_ID}&clientKey={Dev_Key}&defaultAction={leanplum_api_action}&gcsBucket={bucket_name}&file={path/file_name}&createJob=true

  • User Attributes: defaultAction=setUserAttributes
  • Device Attributes: defaultAction=setDeviceAttributes 
    Note: If you are uploading systemName for device-level information, you will need to make a start call for all users. Using the start API call will reset the Last Active and Last Session time/date. You may reset the Last Active time/date by re-using the setUserAttributes call.
  • Events: defaultAction=setUserAttributes
  • Email Unsubscribe: defaultAction=setUserAttributes

Step 3: Monitor the Uploading Status

You can use the getMultiResults API to check the status of the uploading job with the job id returned by the multi(dev) call.

 


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