Update User Using JSON Array
PATCH {{apiPath}}/environments/{{envID}}/users/{{userID}}
The sample shows the PATCH {{apiPath}}/environments/{{envID}}/users/{{userID}} operation to update attribute properties using a JSON array in the request body. The operation uses the application/vnd.pingidentity.user.scim.patch+json custom content type in the request header, and the request body must contain the Operations property with an array as its value.
The Operations property specifies the type of update operation in the Operations.op attribute. Options for this attribute include add, replace, and remove. The Operations.path attibute specifies the user schema property to modify in the PATCH. The Operations.value attribute specifies the new value for the modified user schema property.
|
The behavior of this PATCH operation follows rules as specified by the Internet Engineering Task Force (IETF) for modifying resources with PATCH. For more information, refer to section 3.5.2 of RFC 7644: System for Cross-domain Identity Management: Protocol. |
SCIM PATCH with multi-valued attributes
When you update a multi-valued attribute using application/json as the Content-Type HTTP header value, you must update the entire multi-valued attribute. The PATCH action associated with the application/vnd.pingidentity.user.scim.patch+json is useful for updating targeted elements in a multi-valued attribute. For example, the following multi-valued attribute specifies T-shirt sizes and colors:
{
"tShirt":[
{
"tshirtSize":"XS",
"tshirtColor":"Blue"
},
{
"tshirtSize":"XL",
"tshirtColor":"Red"
}
]
}
The following PATCH request body specifies two operations. The first operation performs a replace action; it finds all instances of tshirtSize with a value XS and replaces the current tshirtColor attribute with the new color Orange. For this modification, the Operations.path uses a SCIM expression to find the XS T-shirt sizes and update the associated tshirtColor attribute. The second operation uses an add action to add a new T-shirt size and color to the multi-valued atttribute.
{
"Operations":[
{
"op":"replace",
"path":"tShirt[tshirtSize eq \\\"XS\\\"].tshirtColor",
"value":"Orange"
},
{
"op":"add",
"path":"tShirt",
"value":[
{
"tshirtSize":"L",
"tshirtColor":"Yellow"
}
]
}
]
}
The multi-valued attribute looks like this after the update:
{
"tShirt":[
{
"tshirtSize":"XS",
"tshirtColor":"Orange"
},
{
"tshirtSize":"XL",
"tshirtColor":"Red"
},
{
"tshirtSize":"L",
"tshirtColor":"Yellow"
}
]
}
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/vnd.pingidentity.user.scim.patch+json' \
--header 'Authorization: Bearer {{accessToken}}' \
--data-raw '{
"Operations":[
{
"op":"replace",
"path":"email",
"value":"test@test.com"
}
]
}'
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/vnd.pingidentity.user.scim.patch+json");
request.AddHeader("Authorization", "Bearer {{accessToken}}");
var body = @"{" + "\n" +
@" ""Operations"":[" + "\n" +
@" {" + "\n" +
@" ""op"":""replace""," + "\n" +
@" ""path"":""email""," + "\n" +
@" ""value"":""test@test.com""" + "\n" +
@" }" + "\n" +
@" ]" + "\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(`{
"Operations":[
{
"op":"replace",
"path":"email",
"value":"test@test.com"
}
]
}`)
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
return
}
req.Header.Add("Content-Type", "application/vnd.pingidentity.user.scim.patch+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/vnd.pingidentity.user.scim.patch+json
Authorization: Bearer {{accessToken}}
{
"Operations":[
{
"op":"replace",
"path":"email",
"value":"test@test.com"
}
]
}
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/vnd.pingidentity.user.scim.patch+json");
RequestBody body = RequestBody.create(mediaType, "{\n \"Operations\":[\n {\n \"op\":\"replace\",\n \"path\":\"email\",\n \"value\":\"test@test.com\"\n }\n ]\n}");
Request request = new Request.Builder()
.url("{{apiPath}}/environments/{{envID}}/users/{{userID}}")
.method("PATCH", body)
.addHeader("Content-Type", "application/vnd.pingidentity.user.scim.patch+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/vnd.pingidentity.user.scim.patch+json",
"Authorization": "Bearer {{accessToken}}"
},
"data": JSON.stringify({
"Operations": [
{
"op": "replace",
"path": "email",
"value": "test@test.com"
}
]
}),
};
$.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/vnd.pingidentity.user.scim.patch+json',
'Authorization': 'Bearer {{accessToken}}'
},
body: JSON.stringify({
"Operations": [
{
"op": "replace",
"path": "email",
"value": "test@test.com"
}
]
})
};
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({
"Operations": [
{
"op": "replace",
"path": "email",
"value": "test@test.com"
}
]
})
headers = {
'Content-Type': 'application/vnd.pingidentity.user.scim.patch+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/vnd.pingidentity.user.scim.patch+json',
'Authorization' => 'Bearer {{accessToken}}'
));
$request->setBody('{\n "Operations":[\n {\n "op":"replace",\n "path":"email",\n "value":"test@test.com"\n }\n ]\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/vnd.pingidentity.user.scim.patch+json"
request["Authorization"] = "Bearer {{accessToken}}"
request.body = JSON.dump({
"Operations": [
{
"op": "replace",
"path": "email",
"value": "test@test.com"
}
]
})
response = http.request(request)
puts response.read_body
let parameters = "{\n \"Operations\":[\n {\n \"op\":\"replace\",\n \"path\":\"email\",\n \"value\":\"test@test.com\"\n }\n ]\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "{{apiPath}}/environments/{{envID}}/users/{{userID}}")!,timeoutInterval: Double.infinity)
request.addValue("application/vnd.pingidentity.user.scim.patch+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/788d4931-6936-43f2-82ff-178f5762298a"
},
"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/f22842c9-f1eb-41a5-8072-20041b609cf1"
},
"devices": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/devices"
},
"roleAssignments": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/roleAssignments"
},
"password": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/password"
},
"password.reset": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/password"
},
"password.set": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/password"
},
"password.check": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/password"
},
"password.recover": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/password"
},
"linkedAccounts": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/linkedAccounts"
},
"account.sendVerificationCode": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a"
},
"memberOfGroups": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users/788d4931-6936-43f2-82ff-178f5762298a/memberOfGroups"
}
},
"_embedded": {
"password": {
"status": "PASSWORD_EXPIRED"
}
},
"id": "788d4931-6936-43f2-82ff-178f5762298a",
"environment": {
"id": "abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6"
},
"account": {
"canAuthenticate": true,
"status": "OK"
},
"accountId": "5",
"address": {
"streetAddress": "123 Fake Street",
"locality": "Springfield",
"region": "Somewhere",
"postalCode": "78701",
"countryCode": "US"
},
"createdAt": "2021-03-02T18:19:26.564Z",
"email": "test@test.com",
"enabled": true,
"identityProvider": {
"type": "PING_ONE"
},
"lastSignOn": {
"at": "2021-03-31T19:37:12.129Z",
"remoteIp": "174.21.110.237"
},
"lifecycle": {
"status": "ACCOUNT_OK"
},
"locale": "en-gb",
"mfaEnabled": false,
"mobilePhone": "+1.4445552222",
"name": {
"formatted": "Leslie Jones",
"given": "Leslie",
"middle": "L",
"family": "Jones",
"honorificPrefix": "Dr.",
"honorificSuffix": "IV"
},
"nickname": "Les",
"population": {
"id": "f22842c9-f1eb-41a5-8072-20041b609cf1"
},
"preferredLanguage": "en-gb;q=0.8, en;q=0.7",
"primaryPhone": "+1.2225554444",
"timezone": "America/Los_Angeles",
"title": "The Great",
"type": "tele",
"updatedAt": "2021-10-28T19:32:06.911Z",
"username": "lesliejones@example.com",
"verifyStatus": "NOT_INITIATED"
}