Update User
PATCH {{apiPath}}/environments/{{envID}}/users/{{userID}}
The sample shows the PATCH {{apiPath}}/environments/{{envID}}/users/{{userID}} operation to update existing attribute properties. For the PATCH operation, the update operation targets only those attribute values specified in the request body.
Attributes omitted from the request body are not updated or removed. If the user does not have update access to an attribute, a 403 Forbidden error is returned if an update is attempted for that attribute.
All values for attributes with multiValued set to true are replaced with the provided data. For example, if a user has the following data set for the locales attribute:
{
...,
"locales": ["London", "Sydney"],
...
}
and the PATCH operation is called with the following body:
{
"locales": ["Tel Aviv"]
}
then the result would be the user’s locales value set to a one-value array consisting of "Tel Aviv". Any user-initiated updates to the value will also replace the entire array. No merging is possible.
Users who are not authenticating with PingOne must be assigned an identity provider with the identityProvider.id attribute. If identityProvider.id is not provided, PingOne is set as the default identity provider. The identityProvider.type value is read-only, and its value is dependent on the value of identityProvider.id. If identityProvider.id is not provided, the default value of identityProvider.type is PING_ONE.
Users who authenticate with an authoritative identity provider cannot self-service modify their account. The scopes p1:update:user and p1:read:user:{suffix} are not granted for these users. For additional information on scopes, refer to Access services through scopes and roles.
|
|
For PATCH requests that modify custom JSON user attributes, the update operation replaces only those elements that are specified in the request body. This behavior follows standard JSON merge patch rules as specified by the Internet Engineering Task Force (IETF). For more information, refer to sections 2 and 3 of RFC 7396: JSON Merge Patch. |
|
You can enable multi-factor authentication by setting |
Prerequisites
-
Refer to Users and User Operations for important overview information.
Request Model
| Property | Type | Required? |
|---|---|---|
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
Array [String] |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Required |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
Refer to the User operations data model for full property descriptions.
Example Request
-
cURL
-
C#
-
Go
-
HTTP
-
Java
-
jQuery
-
NodeJS
-
Python
-
PHP
-
Ruby
-
Swift
curl --location --globoff --request PATCH '{{apiPath}}/environments/{{envID}}/users/{{userID}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{accessToken}}' \
--data '{
"title": "Manager"
}'
var options = new RestClientOptions("{{apiPath}}/environments/{{envID}}/users/{{userID}}")
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("", Method.Patch);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer {{accessToken}}");
var body = @"{" + "\n" +
@" ""title"": ""Manager""" + "\n" +
@"}";
request.AddStringBody(body, DataFormat.Json);
RestResponse response = await client.ExecuteAsync(request);
Console.WriteLine(response.Content);
package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "{{apiPath}}/environments/{{envID}}/users/{{userID}}"
method := "PATCH"
payload := strings.NewReader(`{
"title": "Manager"
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer {{accessToken}}")
res, err := client.Do(req)
if err != nil {
fmt.Println(err)
return
}
defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(body))
}
PATCH /environments/{{envID}}/users/{{userID}} HTTP/1.1
Host: {{apiPath}}
Content-Type: application/json
Authorization: Bearer {{accessToken}}
{
"title": "Manager"
}
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"title\": \"Manager\"\n}");
Request request = new Request.Builder()
.url("{{apiPath}}/environments/{{envID}}/users/{{userID}}")
.method("PATCH", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer {{accessToken}}")
.build();
Response response = client.newCall(request).execute();
var settings = {
"url": "{{apiPath}}/environments/{{envID}}/users/{{userID}}",
"method": "PATCH",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer {{accessToken}}"
},
"data": JSON.stringify({
"title": "Manager"
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
var request = require('request');
var options = {
'method': 'PATCH',
'url': '{{apiPath}}/environments/{{envID}}/users/{{userID}}',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{accessToken}}'
},
body: JSON.stringify({
"title": "Manager"
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "{{apiPath}}/environments/{{envID}}/users/{{userID}}"
payload = json.dumps({
"title": "Manager"
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{accessToken}}'
}
response = requests.request("PATCH", url, headers=headers, data=payload)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('{{apiPath}}/environments/{{envID}}/users/{{userID}}');
$request->setMethod('PATCH');
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer {{accessToken}}'
));
$request->setBody('{\n "title": "Manager"\n}');
try {
$response = $request->send();
if ($response->getStatus() == 200) {
echo $response->getBody();
}
else {
echo 'Unexpected HTTP status: ' . $response->getStatus() . ' ' .
$response->getReasonPhrase();
}
}
catch(HTTP_Request2_Exception $e) {
echo 'Error: ' . $e->getMessage();
}
require "uri"
require "json"
require "net/http"
url = URI("{{apiPath}}/environments/{{envID}}/users/{{userID}}")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Patch.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer {{accessToken}}"
request.body = JSON.dump({
"title": "Manager"
})
response = http.request(request)
puts response.read_body
let parameters = "{\n \"title\": \"Manager\"\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "{{apiPath}}/environments/{{envID}}/users/{{userID}}")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("Bearer {{accessToken}}", forHTTPHeaderField: "Authorization")
request.httpMethod = "PATCH"
request.httpBody = postData
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data else {
print(String(describing: error))
return
}
print(String(data: data, encoding: .utf8)!)
}
task.resume()
Example Response
200 OK
{
"_links": {
"self": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab"
},
"environment": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6"
},
"population": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/populations/60971d3b-cc5a-4601-9c44-2be541f91bf1"
},
"devices": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/58177d50-1f2b-4f08-a95c-c618c83c0669/devices"
},
"roleAssignments": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/roleAssignments"
},
"password": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/password"
},
"password.reset": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/password"
},
"password.set": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/password"
},
"password.check": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/password"
},
"password.recover": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/password"
},
"linkedAccounts": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/linkedAccounts"
},
"account.sendVerificationCode": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab"
},
"memberOfGroups": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/8376797d-641c-4e7b-8bc1-2fdf71916cab/memberOfGroups"
}
},
"id": "8376797d-641c-4e7b-8bc1-2fdf71916cab",
"environment": {
"id": "abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6"
},
"account": {
"canAuthenticate": true,
"status": "OK"
},
"accountId": "5",
"address": {
"streetAddress": "123 Main Street",
"locality": "Springfield",
"region": "WA",
"postalCode": "98701",
"countryCode": "US"
},
"createdAt": "2022-10-11T16:54:38.125Z",
"email": "joe@example.com",
"enabled": true,
"identityProvider": {
"type": "PING_ONE"
},
"lastSignOn": {
"at": "2022-10-11T17:03:47.696Z",
"remoteIp": "54.86.50.139"
},
"lifecycle": {
"status": "ACCOUNT_OK"
},
"locale": "en-gb",
"mfaEnabled": false,
"mobilePhone": "+1.4445552222",
"name": {
"formatted": "Joe Smith",
"given": "Joe",
"middle": "H.",
"family": "Smith",
"honorificPrefix": "Dr.",
"honorificSuffix": "IV"
},
"nickname": "Putty",
"photo": {
"href": "https://www.google.com/imgres?imgurl=https%3A%2F%2Fwww.pingidentity.com%2Fcontent%2Fdam%2Fping-6-2-assets%2Ftopnav-json-configs%2FPing-Logo.svg&imgrefurl=https%3A%2F%2Fwww.pingidentity.com%2Fen.html&tbnid=MbFHzW8q8CvofM&vet=12ahUKEwjJo936s7P7AhVrunIEHeO2BVQQMygAegUIARDAAQ..i&docid=LNAdqRbt76nJPM&w=800&h=800&q=ping%20identity%20user&hl=en&ved=2ahUKEwjJo936s7P7AhVrunIEHeO2BVQQMygAegUIARDAAQ"
},
"population": {
"id": "60971d3b-cc5a-4601-9c44-2be541f91bf1"
},
"preferredLanguage": "en-gb;q=0.8, en;q=0.7",
"primaryPhone": "+1.2225554444",
"timezone": "America/Los_Angeles",
"title": "Manager",
"type": "tele",
"updatedAt": "2022-11-16T19:15:59.525Z",
"username": "joe@example.com",
"verifyStatus": "NOT_INITIATED"
}