Update Population
PUT {{apiPath}}/environments/{{envID}}/populations/{{popID}}
To update a population resource, you must know the environment ID and the ID of the population to modify. Use PUT {{apiPath}}/environments/{{envID}}/populations/{{populationID}} to update the attribute values for a population in the specified environment.
An optional default property can be used to assign the population as the default for the environment. When new users are created, they are assigned to the environment’s default population, unless otherwise specified. When default is set to true, all other populations within the environment are set to false.
Populations, by default, use the default password policy and default theme for the environment. However, you’ve the option to:
-
Assign a password policy specific to this population with the
passwordPolicy.idproperty in the request body. To unassign thepasswordPolicy.idproperty, omitpasswordPolicy.idfrom the request body, and the population again uses the default password policy for the environment. -
Assign a theme specific to this population with the
theme.idproperty in the request body. To unassign thetheme.idproperty, omittheme.idfrom the request body, and the population again uses the default theme for the environment.
Prerequisites
-
Refer to Populations for important overview information.
Request Model
| Property | Type | Required? |
|---|---|---|
|
String[] |
Optional |
|
Boolean |
Optional |
|
String |
Optional |
|
String |
Required |
|
String |
Optional |
|
String |
Optional |
|
String |
Optional |
Refer to the Populations data model for full property descriptions.
Example Request
-
cURL
-
C#
-
Go
-
HTTP
-
Java
-
jQuery
-
NodeJS
-
Python
-
PHP
-
Ruby
-
Swift
curl --location --globoff --request PUT '{{apiPath}}/environments/{{envID}}/populations/{{popID}}' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{accessToken}}' \
--data '{
"name" : "Accounting",
"description" : "Accounting group",
"default": false,
"passwordPolicy": {
"id": "{{passwordPolicyID}}"
}
}'
var options = new RestClientOptions("{{apiPath}}/environments/{{envID}}/populations/{{popID}}")
{
MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("", Method.Put);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer {{accessToken}}");
var body = @"{" + "\n" +
@" ""name"" : ""Accounting""," + "\n" +
@" ""description"" : ""Accounting group""," + "\n" +
@" ""default"": false," + "\n" +
@" ""passwordPolicy"": {" + "\n" +
@" ""id"": ""{{passwordPolicyID}}""" + "\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}}/populations/{{popID}}"
method := "PUT"
payload := strings.NewReader(`{
"name" : "Accounting",
"description" : "Accounting group",
"default": false,
"passwordPolicy": {
"id": "{{passwordPolicyID}}"
}
}`)
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))
}
PUT /environments/{{envID}}/populations/{{popID}} HTTP/1.1
Host: {{apiPath}}
Content-Type: application/json
Authorization: Bearer {{accessToken}}
{
"name" : "Accounting",
"description" : "Accounting group",
"default": false,
"passwordPolicy": {
"id": "{{passwordPolicyID}}"
}
}
OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n \"name\" : \"Accounting\",\n \"description\" : \"Accounting group\",\n \"default\": false,\n \"passwordPolicy\": {\n \"id\": \"{{passwordPolicyID}}\"\n }\n}");
Request request = new Request.Builder()
.url("{{apiPath}}/environments/{{envID}}/populations/{{popID}}")
.method("PUT", body)
.addHeader("Content-Type", "application/json")
.addHeader("Authorization", "Bearer {{accessToken}}")
.build();
Response response = client.newCall(request).execute();
var settings = {
"url": "{{apiPath}}/environments/{{envID}}/populations/{{popID}}",
"method": "PUT",
"timeout": 0,
"headers": {
"Content-Type": "application/json",
"Authorization": "Bearer {{accessToken}}"
},
"data": JSON.stringify({
"name": "Accounting",
"description": "Accounting group",
"default": false,
"passwordPolicy": {
"id": "{{passwordPolicyID}}"
}
}),
};
$.ajax(settings).done(function (response) {
console.log(response);
});
var request = require('request');
var options = {
'method': 'PUT',
'url': '{{apiPath}}/environments/{{envID}}/populations/{{popID}}',
'headers': {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{accessToken}}'
},
body: JSON.stringify({
"name": "Accounting",
"description": "Accounting group",
"default": false,
"passwordPolicy": {
"id": "{{passwordPolicyID}}"
}
})
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
import json
url = "{{apiPath}}/environments/{{envID}}/populations/{{popID}}"
payload = json.dumps({
"name": "Accounting",
"description": "Accounting group",
"default": False,
"passwordPolicy": {
"id": "{{passwordPolicyID}}"
}
})
headers = {
'Content-Type': 'application/json',
'Authorization': 'Bearer {{accessToken}}'
}
response = requests.request("PUT", url, headers=headers, data=payload)
print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('{{apiPath}}/environments/{{envID}}/populations/{{popID}}');
$request->setMethod(HTTP_Request2::METHOD_PUT);
$request->setConfig(array(
'follow_redirects' => TRUE
));
$request->setHeader(array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer {{accessToken}}'
));
$request->setBody('{\n "name" : "Accounting",\n "description" : "Accounting group",\n "default": false,\n "passwordPolicy": {\n "id": "{{passwordPolicyID}}"\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}}/populations/{{popID}}")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Put.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer {{accessToken}}"
request.body = JSON.dump({
"name": "Accounting",
"description": "Accounting group",
"default": false,
"passwordPolicy": {
"id": "{{passwordPolicyID}}"
}
})
response = http.request(request)
puts response.read_body
let parameters = "{\n \"name\" : \"Accounting\",\n \"description\" : \"Accounting group\",\n \"default\": false,\n \"passwordPolicy\": {\n \"id\": \"{{passwordPolicyID}}\"\n }\n}"
let postData = parameters.data(using: .utf8)
var request = URLRequest(url: URL(string: "{{apiPath}}/environments/{{envID}}/populations/{{popID}}")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("Bearer {{accessToken}}", forHTTPHeaderField: "Authorization")
request.httpMethod = "PUT"
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/populations/941b174d-1471-47e0-8ebf-fd934c472deb"
},
"environment": {
"href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6"
}
},
"id": "941b174d-1471-47e0-8ebf-fd934c472deb",
"environment": {
"id": "abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6"
},
"name": "Accounting",
"description": "Accounting group",
"userCount": 0,
"createdAt": "2022-02-07T22:17:16.241Z",
"updatedAt": "2022-02-08T14:06:50.335Z",
"passwordPolicy": {
"id": "3d36d311-c424-4b61-b1da-865faced4d00"
},
"default": false
}