setUserAttributes

Sets user attributes for the user given by userId and/or deviceId. If the user has an open session, the attributes for the current session will also be updated. Attributes will then propagate on data going forward. User properties not supplied in this method will not be affected. If the user/device does not exist, a new user will be created (see the createDisposition option below).

This method requires your production API clientKey.

Recent Requests
Log in to see full request history
TimeStatusUser Agent
Retrieving recent requests…
LoadingLoading…
Body Params
string
required
Defaults to YOUR_APP_ID

The application ID. To find yours, select your app in the navigation column, and click Manage Apps. Then click Keys & Settings.

string
required
Defaults to YOUR_PROD_KEY

The Production key for your Leanplum App.

string
enum
required
Defaults to 1.0.6

The version of the Leanplum API to use. The current version is 1.0.6.

Allowed:
string
required
Defaults to hfarnsworth

The current user ID. You can set this to whatever your company uses for user IDs. Leave it blank to use the device ID. For more info, see selecting a user.

string

A unique ID for the device targeted by the request. You must provide a deviceId and/or a userId. See selecting a user.

string
enum
Defaults to CreateIfNeeded

The policy that determines whether users are created by the API. Possible values:

  • CreateIfNeeded creates a user with the given IDs if one does not already exist.
  • CreateNever requires that the user already exists, otherwise the API action is skipped and a warning will be returned.

The default value for this method is CreateIfNeeded.

Allowed:
string

A map of user attributes as key-value pairs. Each key must be a string. Attributes are saved across sessions. Only supplied attributes will be updated (i.e., if you omit an existing attribute, it will be preserved). Example: {"gender":"F","age":21}.

string

A map of values to add to existing user attribute sets. For example, supply {"Interests":"Sports"} to add Sports to the existing set of Interests.

string

A map of values to remove from existing user attribute sets. For example, supply {"Interests":"Sports"} to remove Sports from the existing set of interests.

string

A map of values to increment onto existing user attributes. The existing attribute value and the increment must both be integers or the operation will be skipped. If the existing attribute is not set, its value will be inferred as 0.

For example, supply {"unreadMessages":1} to add 1 to the number of unread messages.

unsubscribeCategoriesToAdd
array of strings

A list of email categories to unsubscribe a user from. See Managing emails subscriptions via API for more info.

unsubscribeCategoriesToAdd
unsubscribeCategoriesToRemove
array of strings

A list of email categories to re-subscribe a user to.

unsubscribeCategoriesToRemove
string

A messaging channel (e.g. Email, Push Notification, Webhook, Newsfeed Message App inbox) to unsubscribe the user from. Use this to unsubscribe a user from all marketing email categories.

string

A messaging channel (e.g. Email, Push Notification, Webhook, Newsfeed Message App inbox) to re-subscribe the user to. Use this to re-subscribe a user to all marketing email categories (except any categories they have unsubscribed from).

string

If supplied, updates the user of the current session with newUserId. This can have certain effects:

  • Login: If the current user has no user ID and the user given by newUserId already exists, the current and existing user profiles will be merged, and the current profile will be deleted.
  • Register: If there is no current user ID and the user given by newUserId does not exist, the current user will be simply assigned newUserId as its user ID.
  • Switch user: If the current user has a user ID, the current session will be ended and a new session will be started with the user given by newUserId. A user with newUserId will be created if one does not already exist.
string

A map of event data to update for the current user. The keys are the event names, each should have a nested object with at least one of the following attributes:

  • count: New lifetime count of this event for the current user.
  • countIncrement: Amount to increment the lifetime count of this event.
  • value: New lifetime value of this event for the current user.
  • valueIncrement: Amount to increment the lifetime value of this event.
  • firstTime: Time that this event first occurred, in seconds since midnight UTC on January 1, 1970.
  • lastTime: Time that this event last occurred, in seconds since midnight UTC on January 1, 1970.

Example: Here's how to set the lifetime count for an event called "myEvent":

{ "myEvent": { count: 1 } }

string

A map of state data to update for the current user. The keys are the state names, and each should have a nested object with at least one of the following attributes:

  • count: New lifetime count of this state for the current user.
  • countIncrement: Amount to increment the lifetime count of this state.
  • firstTime: Time that this state first occurred, in seconds since midnight UTC on January 1, 1970.
  • lastTime: Time that this state last occurred, in seconds since midnight UTC on January 1, 1970.

Example: Here's how to set the lifetime count for a state called "splashPage":

{ "splashPage": { count: 23 } }

float

The time at which the user was created, in seconds since midnight UTC on January 1, 1970.

float

The time at which the user was last active, in seconds since midnight UTC on January 1, 1970.

number

The total number of sessions that a user has had in their lifetime.

float

The total number of seconds spent in the app in the user's lifetime.

string

The current locale the user is in. E.g. en_US.

string

The country the user is in, specified by ISO 2-letter code. E.g. US for United States. Set to (detect) to detect the country based on the IP address of the user.

string

The region (state) the user is in. E.g. ca for California. Set to (detect) to detect the region based on the IP address of the user.

string

The city the user is in. E.g. San Francisco. Set to (detect) to detect the city based on the IP address of the user.

string

The location (latitude/longitude) of the user. E.g. 37.775,-122.4183. Set to (detect) to detect the location based on the IP address of the user.

string

The type of location that is provided (IP, CELL, or GPS). Default: IP.

string

The timezone abbreviation for the user. See list of timezone abbreviations.

number

The timezone offset from GMT in seconds.

devices
array of objects

A list of device objects associated with this user.

devices
boolean
Defaults to false

Whether the user is in Development Mode, i.e. the user associated with the request is a developer and not a user. This is important for reporting purposes. Default: false.

Response

Language
Credentials
URL
LoadingLoading…
Response
Choose an example:
application/json