- Getting Started
- API Home
- API Postbacks
- API Response Errors
- API Technical Details
- Client API Libraries
- HTTP Response Codes
- Email & User Profiles
- blast
- blast_repeat
- list
- send
- template
- user
- Reporting
- job
- stats
- Horizon
- content
- purchase
- Advanced & Beta Features
- ad/plan
- alert
- event
- preview
- settings
- trigger
user
Overview
Get or set information about one of your users. Users are referenced by multiple keys.
Base URL
https://api.sailthru.com/userGET Mode
Get information about one of your users.
Required Parameters
| Parameter | Description | Example |
|---|---|---|
id |
the key value to look up the user |
example@example.com |
Optional Parameters
| Parameter | Description | Example |
|---|---|---|
key |
the key type of id (see keys) |
email |
fields |
the fields to return (see fields) |
{"keys":1,"vars":1} |
Return Value
Will return a data structure consisting of the fields you have elected to return. If you do not pass a fields parameter, the default behavior is to return keys, vars, lists, engagement, and optout.
Keys
The following are valid values to use for the key parameter for GET mode.
| Value | Description | Example id format |
|---|---|---|
sid |
the unique Sailthru identifier for the user profile |
4e2879472d7acd6d97144f9e |
cookie |
the Horizon cookie value – stored in sailthru_hid |
e31b80a7bcfc1d474cf1a37d3bfbdb774e20ca22cde1ca64352c307cf2d4d22ece9b14f8e79ae57517130af6 |
email |
the user's email address |
example@example.com |
sms |
the user's SMS number (only if you have SMS enabled) |
+15551234567 |
fb |
the user's Facebook ID (only if you have Facebook lookup enabled) |
279352494051 |
twitter |
the user's Twitter name (only if you have Twitter lookup enabled) |
sailthru |
extid |
the user's user ID (only if you have extid lookup enabled) |
94234 |
POST Mode
Required Parameters
| Parameter | Description | Example |
|---|---|---|
id |
the key value to look up the user |
example@example.com |
Optional Parameters
| Parameter | Description | Example |
|---|---|---|
key |
the key type of id (see keys) |
email |
fields |
the fields to return (see fields) |
{"keys":1,"vars":1} |
keys |
set some or all of the user keys (see keys) |
{"email":"example@example.com"} |
keysconflict |
define behavior if keys conflict with existing keys (See keysconflict below) |
merge |
vars |
set custom variables on the user |
{"gender":"m","dob":19800527} |
lists |
add or remove users to lists |
{"JoinList":1,"RemoveList":0} |
optout_email |
set email opt-out status to none, all, basic or |
all |
login |
mark the user as logged in. Pass siteto represent a site login, appto represent an app login, and optionally user_agentand ip. Please see examples below. |
|
Return Value
By default, POST mode will return {"ok":true}.
If you pass in the fields parameter you can return data from the updated user record. This can prevent you from having to make a POST followed by a GET.
Keys
The following are valid values to use for the key parameter for POST mode. They can be changed using the keys parameter in POST mode.
| Value | Description | Example id format |
|---|---|---|
email |
the user's email address |
example@example.com |
sid |
the unique Sailthru identifier for the user profile | 4e2879472d7acd6d97144f9e |
sms |
the user's SMS number (only if you have SMS enabled) |
+15551234567 |
fb |
the user's Facebook ID (only if you have Facebook lookup enabled) |
279352494051 |
twitter |
the user's Twitter name (only if you have Twitter lookup enabled) |
sailthru |
extid |
the user's user ID (only if you have extid lookup enabled) |
94234 |
keysconflict
If you attempt to change keys to values that match existing keys already in the database, you create a conflict. You can specify the resolved behavior of the conflict with the keysconflict parameter.
-
error(default) – if there are two profiles in the database that match the keys, a duplicate error will be returned -
merge– if multiple profiles are found in the database that match the keys, the profiles are merged together. The user profile that you are referencing withidandkeywill be favored in the event of a conflict.
Please see examples below.
fields
The following fields can be returned using the fields parameter:
| Field | Description |
|---|---|
| activity | The user's most recent signup, open, click, onsite, and login times |
| engagement | The user's current engagement level |
keys |
A list of currently set keys on the user |
lists |
The normal lists the user is signed up for, with signup dates |
optout_email |
The current email opt-out status: none, blast, basic or all |
| smart_lists | The smart lists the user is currently a part of |
| vars | The custom vars set on the user |
Examples
Add user example@example.com to a list called All Users
POST
{"id":"example@example.com",
"key":"email",
"lists":{"All Users":1}
}
Get current keys, engagement, activity information for a user whose SMS number is +15551234567
GET
{"id":"+15551234567",
"key":"sms",
"fields":{"keys":1,"engagement":1,"activity":1}
}
Set the email address of the user with Sailthru ID 4e2879472d7acd6d97144f9eto example@example.com
POST
{"id":"4e2879472d7acd6d97144f9e",
"key":"sid",
"keys":{"email":"example@example.com"}
}
Change an email address of a user by referencing a Sailthru ID (sid), using the 'keysconflict' parameter
POST
{"id":"4e2879472d7acd6d97144f9e",
"key":"sid",
"keys":{"email":"example@example.com"},
"keysconflict":"merge"
}
Change an email address using the 'keysconflict' parameter
POST
{"id":"emailtobeoverwritten@domain.com","key":"email","keysconflict":"merge","keys":{"email":"newemail@domain.com"}}
To set the Horizon cookie on a subscriber when they sign in to your site.
a) Record that your user id ABC123 has just logged in on your main site b) and return the keys, which includes the cookie you can set on the user. This is included in the code below.
JSON
POST
{"id":"joe@example.com",
"login":{"site":"main","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"},
"fields":{"keys":1}
}
PHP
$result = $sailthru->apiPost('user', array(
'id' => 'joe@example.com',
'fields' => array('keys' => 1),
'login' => array(
'site' => 'example.com',
'ip' => $_SERVER['REMOTE_ADDR'],
'user_agent' => $_SERVER['HTTP_USER_AGENT'])
));
setcookie('sailthru_hid', $result['keys']['cookie']);
Ruby
{:id => 'joe@example.com',
:login => {
:site => 'main',
:ip => '127.0.0.1',
:user_agent => 'Mozilla/5.0 (Iphone; U; CPU like Mac OS x; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3'},
:fields => {'keys' => 1}
}
response = sailthru.api_post('user', {
:id => 'joe@example.com',
:fields => {:keys => 1},
:login => {
:site => 'example.com',
:ip => '127.0.0.1',
:user_agent => 'place user agent here'
}
})
cookies['sailthru_hid'] = {
:domain => ".example.com",
:value => response['keys']['cookie'],
:expires => 3.months.from_now
}
# cookies[:key] is specific to Ruby on Rails