setUserAttributes can now set device attributes and location profile

Overview

Our API now allows you to more easily set and get 1) device attributes and 2) the user location profile for your users. Previously, start was the only method to set deviceModel or locale. With these changes, you can now set device attributes with start, setUserAttributes, or (appropriately) setDeviceAttributes.

exportUser has also been updated to return a device array with a user's complete list of devices with their attributes.

The changes are detailed below, listed by API action.

setUserAttributes

  • adds a device argument (type: array) to set devices for a user (each item in the array has the same attribute options as setDeviceAttributes).
  • adds locale, country, city, location, locationAccuracyType, timezone, and timezoneOffsetSeconds params to set user’s location.

To set a user's location profile and add (or update) a single device, you can now make the following API call:

POST https://www.leanplum.com/api?action=setUserAttributes

{
  "appId": "YOUR_APP_ID",
  "clientKey": "YOUR_PROD_KEY",
  "apiVersion": "1.0.6",
  "userId": "hfarnsworth@example.com",
  "timeSpentInApp": 3255.809,
  "locale": "en_US",
  "country": "US",
  "region": "ca",
  "city": "san francisco",
  "location": "37.774929,-122.419418",
  "locationAccuracyType": "IP",
  "timezone": "America/Los_Angeles",
  "timezoneOffsetSeconds": -25200,
  "devices": [
    {
      "appVersion": "1",
      "systemName": "iOS",
      "systemVersion": "10.3",
      "browserName": "Safari",
      "browserVersion": "10.1",
      "deviceName": "Hubert's iPhone",
      "deviceModel": "iPhone",
      "iosPushToken": "tokenString",
      "gcmRegistrationId": "gcmString"
    }
  ]
}

setDeviceAttributes

  • adds systemName, systemVersion, browserName, browserVersion, deviceName, and deviceModel params to allow setting of more device attributes

If you only need to set the user's device attributes for a single device, you can make the folllowing call with a deviceId:

POST https://www.leanplum.com/api?action=setDeviceAttributes

{
  "appId": "YOUR_APP_ID",
  "clientKey": "YOUR_PROD_KEY",
  "apiVersion": "1.0.6",
  "deviceId": "HUBERTS-BLAH-555B-BBB9-9999999AB05",
  "appVersion": "4.5",
  "systemName": "iOS",
  "systemVersion": "10.3",
  "browserName": "Safari",
  "browserVersion": "10.1",
  "deviceName": "John's iPhone",
  "deviceModel": "iPhone",
  "iosPushToken": "tokenString",
  "gcmRegistrationId": "gcmString"
}

exportUser

  • will now return a devices array with the user’s devices.

If you need to get device information for a single user, you can make the following call:

GET https://www.leanplum.com/api?action=exportUser&appId=YOUR_APP_ID&clientKey=YOUR_EXPORT_KEY&userId=hfarnsworth@example.com

Response

{
  "response": [
    {
      "locationAccuracyType": "IP",
      "region": "ca",
      "location": "37.774929,-122.419418",
      "events": {},
      "locale": "en_US",
      "lastActive": 1493220922.904,
      "states": {
        "Splash": {
          "firstTime": 1493056142.05,
          "count": 4,
          "lastTime": 1493220922.904
        }
      },
      "timeSpentInApp": 3255.809,
      "country": "US",
      "city": "san francisco",
      "totalSessions": 24,
      "timezone": "America/Los_Angeles",
      "created": 1492450521.474,
      "userId": "hfarnsworth",
      "devices": [
        {
          "deviceName": "Hubert's iPhone",
          "appVersion": "1",
          "systemVersion": "10.3",
          "systemName": "iOS",
          "deviceModel": "iPhone",
          "deviceId": "HUBERTS-BLAH-555B-BBB9-9999999AB05"
        }
      ],
      "timezoneOffsetSeconds": -25200,
      "success": true,
      "userAttributes": {
        "lastName": "Farnsworth",
        "email": "hfarnsworth@example.com",
        "firstName": "Hubert"
      }
    }
  ]
}

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