Update user
Simple HTTP PUT request to Users API and you can update standard attributes for a user within few seconds!
To update a user with JSON type content set header 'content-type: application/json'
. And the
data used to update is simply the view (attributes) of user model.
Allowed attributes: assigned_to, city, company_id, country, email, facebook_url, first_name, gender, google_url, gravatar_url, last_name, linkedin_url, notifications, phone_number, region, score, status, timezone, twitter_url, unsubscribed, user_id.
If you want to set custom attributes use Set attribute or Set multiple attributes.
PUT
/users/:id/
Parameters
Type
Description
id
integer
Unique ID provided in user model
Attributes
Type
Description
email
string
Email address of a user
first_name
string
First name for a user
last_name
string
Last name for a user
company_id
string
Add user as employee to company with given company_id
curl -X PUT -H "Authorization: Token <your_64_char_api_key>" -H "Content-Type: application/json" -d '{
"email": "john@example.org",
"gravatar_url": "https://randomuser.me/api/portraits/men/51.jpg",
}' "https://<your_app_subdomain>.user.com/api/public/users/:id/"
Response
{
"chat_id": "Chat ID is deprecated and will be removed in future",
"twitter_url": null,
"last_contacted": null,
"timezone": null,
"updated_at": "2017-06-14T07:29:06.976662Z",
"companies": [
{
"id": 14,
"name": "Company name",
"member_since": "2018-06-14T08:49:56.515083Z"
}
],
"google_url": null,
"lists": [],
"status": "visitor",
"resolution": null,
"phone_number": null,
"gravatar_url": "https://randomuser.me/api/portraits/men/51.jpg",
"os_type": null,
"facebook_url": null,
"name": "Jane Doe",
"page_views": 0,
"tags": [
{
"name": "tag",
"id": 1441
}
],
"linkedin_url": null,
"browser": null,
"last_seen": "2017-06-14T11:06:08.182761Z",
"id": 19678376,
"first_seen": null,
"last_ip": null,
"score": 0,
"unsubscribed": false,
"region": null,
"attributes": [
{
"value": true,
"name": "Example attr",
"name_std": "example_attr",
"id": 1109
},
{
"value": "attribute value",
"name": "My string attr",
"name_std": "my_string_attr",
"id": 2429
}
],
"created_at": "2017-06-07T09:41:13.466897Z",
"gender": "unknown",
"key": "g3FaYocCy0U6",
"notifications": true,
"country": null,
"email": "updated@email.com",
"browser_language": null,
"city": null
}
var settings = {
"async": true,
"crossDomain": true,
"url": "https://<your_app_subdomain>.user.com/api/public/users/:id/",
"method": "PUT",
"headers": {
"authorization": "Token <your_64_char_api_key>",
"content-type": "application/json"
},
"processData": false,
"data": "{\n \"first_name\": \"John\",\n \"last_name\": \"Doe\",\n \"gender\": 2,\n \"status\": 2,\n \"phone_number\": \"+48123456789\",\n \"first_seen\": null,\n \"last_seen\": null,\n \"page_views\": 8,\n \"last_ip\": \"84.23.84.23\",\n \"timezone\": null,\n \"city\": \"Warsaw\",\n \"country\": \"Poland\",\n \"unsubscribed\": false,\n \"browser_language\": null,\n \"browser\": \"Chrome\",\n \"os_type\": null,\n \"resolution\": null,\n \"created_at\": \"2016-08-08T09:22:25.795373Z\",\n \"updated_at\": \"2016-08-08T09:22:32.823346Z\",\n \"attributes\": [],\n \"gravatar_url\": null,\n \"lists\": [],\n \"tags\": [\n {\n \"id\": 372,\n \"name\": \"john123\"\n }\n ],\n \"notifications\": true\n}"
}
$.ajax(settings).done(function (response) {
console.log(response);
});
var data = JSON.stringify({
"first_name": "John",
"last_name": "Doe",
"gender": 2,
"status": 2,
"phone_number": "+48123456789",
"first_seen": null,
"last_seen": null,
"page_views": 8,
"last_ip": "84.23.84.23",
"timezone": null,
"city": "Warsaw",
"country": "Poland",
"unsubscribed": false,
"browser_language": null,
"browser": "Chrome",
"os_type": null,
"resolution": null,
"created_at": "2016-08-08T09:22:25.795373Z",
"updated_at": "2016-08-08T09:22:32.823346Z",
"attributes": [],
"gravatar_url": null,
"lists": [],
"tags": [
{
"id": 372,
"name": "john123"
}
],
"notifications": true
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("PUT", "https://<your_app_subdomain>.user.com/api/public/users/:id/");
xhr.setRequestHeader("authorization", "Token <your_64_char_api_key>");
xhr.setRequestHeader("content-type", "application/json");
xhr.send(data);
var request = require("request");
var options = { method: 'PUT',
url: 'https://<your_app_subdomain>.user.com/api/public/users/:id/',
headers:
{ 'content-type': 'application/json',
authorization: 'Token <your_64_char_api_key>' },
body:
{ first_name: 'John',
last_name: 'Doe',
gender: 2,
status: 2,
phone_number: '+48123456789',
first_seen: null,
last_seen: null,
page_views: 8,
last_ip: '84.23.84.23',
timezone: null,
city: 'Warsaw',
country: 'Poland',
unsubscribed: false,
browser_language: null,
browser: 'Chrome',
os_type: null,
resolution: null,
created_at: '2016-08-08T09:22:25.795373Z',
updated_at: '2016-08-08T09:22:32.823346Z',
attributes: [],
gravatar_url: null,
lists: [],
tags: [ { id: 372, name: 'john123' } ],
notifications: true },
json: true };
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(body);
});
<?php
$request = new HttpRequest();
$request->setUrl('https://<your_app_subdomain>.user.com/api/public/users/:id/');
$request->setMethod(HTTP_METH_PUT);
$request->setHeaders(array(
'content-type' => 'application/json',
'authorization' => 'Token <your_64_char_api_key>'
));
$request->setBody('{
"first_name": "John",
"last_name": "Doe",
"gender": 2,
"status": 2,
"phone_number": "+48123456789",
"first_seen": null,
"last_seen": null,
"page_views": 8,
"last_ip": "84.23.84.23",
"timezone": null,
"city": "Warsaw",
"country": "Poland",
"unsubscribed": false,
"browser_language": null,
"browser": "Chrome",
"os_type": null,
"resolution": null,
"created_at": "2016-08-08T09:22:25.795373Z",
"updated_at": "2016-08-08T09:22:32.823346Z",
"attributes": [],
"gravatar_url": null,
"lists": [],
"tags": [
{
"id": 372,
"name": "john123"
}
],
"notifications": true
}');
try {
$response = $request->send();
echo $response->getBody();
} catch (HttpException $ex) {
echo $ex;
}
import requests
url = "https://<your_app_subdomain>.user.com/api/public/users/:id/"
payload = "{\n \"first_name\": \"John\",\n \"last_name\": \"Doe\",\n \"gender\": 2,\n \"status\": 2,\n \"phone_number\": \"+48123456789\",\n \"first_seen\": null,\n \"last_seen\": null,\n \"page_views\": 8,\n \"last_ip\": \"84.23.84.23\",\n \"timezone\": null,\n \"city\": \"Warsaw\",\n \"country\": \"Poland\",\n \"unsubscribed\": false,\n \"browser_language\": null,\n \"browser\": \"Chrome\",\n \"os_type\": null,\n \"resolution\": null,\n \"created_at\": \"2016-08-08T09:22:25.795373Z\",\n \"updated_at\": \"2016-08-08T09:22:32.823346Z\",\n \"attributes\": [],\n \"gravatar_url\": null,\n \"lists\": [],\n \"tags\": [\n {\n \"id\": 372,\n \"name\": \"john123\"\n }\n ],\n \"notifications\": true\n}"
headers = {
'authorization': "Token <your_64_char_api_key>",
'content-type': "application/json"
}
response = requests.request("PUT", url, data=payload, headers=headers)
print(response.text)