Last modified December 17, 2015 by Shelly Wolfe

Set User Properties via API

The Swrve Events API enables you to send Swrve information that you know about your users, from outside the app, via the User API call. Use the User API call to set the value of custom user properties by making an API call to <app_id>.api.swrve.com (or <app_id>.eu-api.swrve.com for EU-configured apps).

This is useful if you want to send data when the user is not in the app, or to set a property that you know about your user from one of your other services. This method also enables you to manually put a user into a particular segment (the segment must already be set up) or set multiple user properties at the same time.

This article references Swrve’s URLs for all data and content stored in both our US and EU data centers. Click the relevant tab based on your app configuration. For more information, see How Do I Configure the Swrve SDK for EU Data Storage?

Prerequisites

This guide presents an area of advanced analysis, so ensure you have the following:

  • Fully instrumented Swrve into your app
  • The ID of the user(s)
  • The name and value of the user properties
  • Your app_id and api_key

An easy to way to set user properties for a group of users is with a simple script that reads a set of user IDs and properties from a CSV file and makes a series of API calls to Swrve. For example:

An example Python script is provided below. The User API call is made with a simple HTTP POST request. This script requires the name of the CSV file as a command line parameter and for that CSV file to have a column with the name ‘userID’.


Testing

To confirm that your user properties were set correctly, include a QA user in your user properties file and then check for the user properties in the QA log.

Because the user has not triggered this user update themselves and are not necessarily active, you don’t want the user property event to affect the DAU or MAU figures. To prevent this, include an additional flag called user_initiated that is set to false, as shown in the script above.

The Swrve User API call is part of the Swrve Events API. For more information, see the Swrve Events API Guide.