PingOne Platform APIs

Create Group

 

POST {{apiPath}}/environments/{{envID}}/groups

The POST {{apiPath}}/environments/{{envID}}/groups operation creates one group.

By default, groups are created per environment. Optionally, you can also create groups per population. For more information, refer to Creating groups.

Prerequisites

  • Refer to Groups for important overview information.

Request Model

Refer to the Groups data model for full property descriptions.

Property Type Required?

customData

JSON blob

Optional

description

String

Optional

externalId

String

Optional

name

String

Required

population.id

String

Optional

userFilter

String

Optional

Headers

Authorization      Bearer {{accessToken}}

Content-Type      application/json

Body

raw ( application/json )

{
   "name": "Managers",
   "description": "This is a test group",
   "customData": {
       "groupOwner": "Tom Jones",
       "securityGroup": true
   },
   "userFilter": "title eq \"Manager\""
}

Example Request

  • cURL

  • C#

  • Go

  • HTTP

  • Java

  • jQuery

  • NodeJS

  • Python

  • PHP

  • Ruby

  • Swift

curl --location --globoff '{{apiPath}}/environments/{{envID}}/groups' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{accessToken}}' \
--data '{
   "name": "Managers",
   "description": "This is a test group",
   "customData": {
       "groupOwner": "Tom Jones",
       "securityGroup": true
   },
   "userFilter": "title eq \"Manager\""
}'
var options = new RestClientOptions("{{apiPath}}/environments/{{envID}}/groups")
{
  MaxTimeout = -1,
};
var client = new RestClient(options);
var request = new RestRequest("", Method.Post);
request.AddHeader("Content-Type", "application/json");
request.AddHeader("Authorization", "Bearer {{accessToken}}");
var body = @"{" + "\n" +
@"   ""name"": ""Managers""," + "\n" +
@"   ""description"": ""This is a test group""," + "\n" +
@"   ""customData"": {" + "\n" +
@"       ""groupOwner"": ""Tom Jones""," + "\n" +
@"       ""securityGroup"": true" + "\n" +
@"   }," + "\n" +
@"   ""userFilter"": ""title eq \""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}}/groups"
  method := "POST"

  payload := strings.NewReader(`{
   "name": "Managers",
   "description": "This is a test group",
   "customData": {
       "groupOwner": "Tom Jones",
       "securityGroup": true
   },
   "userFilter": "title eq \"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))
}
POST /environments/{{envID}}/groups HTTP/1.1
Host: {{apiPath}}
Content-Type: application/json
Authorization: Bearer {{accessToken}}

{
   "name": "Managers",
   "description": "This is a test group",
   "customData": {
       "groupOwner": "Tom Jones",
       "securityGroup": true
   },
   "userFilter": "title eq \"Manager\""
}
OkHttpClient client = new OkHttpClient().newBuilder()
  .build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\n   \"name\": \"Managers\",\n   \"description\": \"This is a test group\",\n   \"customData\": {\n       \"groupOwner\": \"Tom Jones\",\n       \"securityGroup\": true\n   },\n   \"userFilter\": \"title eq \\\"Manager\\\"\"\n}");
Request request = new Request.Builder()
  .url("{{apiPath}}/environments/{{envID}}/groups")
  .method("POST", body)
  .addHeader("Content-Type", "application/json")
  .addHeader("Authorization", "Bearer {{accessToken}}")
  .build();
Response response = client.newCall(request).execute();
var settings = {
  "url": "{{apiPath}}/environments/{{envID}}/groups",
  "method": "POST",
  "timeout": 0,
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Bearer {{accessToken}}"
  },
  "data": JSON.stringify({
    "name": "Managers",
    "description": "This is a test group",
    "customData": {
      "groupOwner": "Tom Jones",
      "securityGroup": true
    },
    "userFilter": "title eq \"Manager\""
  }),
};

$.ajax(settings).done(function (response) {
  console.log(response);
});
var request = require('request');
var options = {
  'method': 'POST',
  'url': '{{apiPath}}/environments/{{envID}}/groups',
  'headers': {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer {{accessToken}}'
  },
  body: JSON.stringify({
    "name": "Managers",
    "description": "This is a test group",
    "customData": {
      "groupOwner": "Tom Jones",
      "securityGroup": true
    },
    "userFilter": "title eq \"Manager\""
  })

};
request(options, function (error, response) {
  if (error) throw new Error(error);
  console.log(response.body);
});
import requests
import json

url = "{{apiPath}}/environments/{{envID}}/groups"

payload = json.dumps({
  "name": "Managers",
  "description": "This is a test group",
  "customData": {
    "groupOwner": "Tom Jones",
    "securityGroup": True
  },
  "userFilter": "title eq \"Manager\""
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer {{accessToken}}'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
<?php
require_once 'HTTP/Request2.php';
$request = new HTTP_Request2();
$request->setUrl('{{apiPath}}/environments/{{envID}}/groups');
$request->setMethod(HTTP_Request2::METHOD_POST);
$request->setConfig(array(
  'follow_redirects' => TRUE
));
$request->setHeader(array(
  'Content-Type' => 'application/json',
  'Authorization' => 'Bearer {{accessToken}}'
));
$request->setBody('{\n   "name": "Managers",\n   "description": "This is a test group",\n   "customData": {\n       "groupOwner": "Tom Jones",\n       "securityGroup": true\n   },\n   "userFilter": "title eq \\"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}}/groups")

http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Post.new(url)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer {{accessToken}}"
request.body = JSON.dump({
  "name": "Managers",
  "description": "This is a test group",
  "customData": {
    "groupOwner": "Tom Jones",
    "securityGroup": true
  },
  "userFilter": "title eq \"Manager\""
})

response = http.request(request)
puts response.read_body
let parameters = "{\n   \"name\": \"Managers\",\n   \"description\": \"This is a test group\",\n   \"customData\": {\n       \"groupOwner\": \"Tom Jones\",\n       \"securityGroup\": true\n   },\n   \"userFilter\": \"title eq \\\"Manager\\\"\"\n}"
let postData = parameters.data(using: .utf8)

var request = URLRequest(url: URL(string: "{{apiPath}}/environments/{{envID}}/groups")!,timeoutInterval: Double.infinity)
request.addValue("application/json", forHTTPHeaderField: "Content-Type")
request.addValue("Bearer {{accessToken}}", forHTTPHeaderField: "Authorization")

request.httpMethod = "POST"
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

201 Created

{
    "_links": {
        "self": {
            "href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/groups/dbd479cb-fcd3-4c34-b5d3-ee2b60c86067"
        },
        "environment": {
            "href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6"
        },
        "allUserMembers": {
            "href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users?filter=memberOfGroups%5Bid%20eq%20%22dbd479cb-fcd3-4c34-b5d3-ee2b60c86067%22%5D"
        },
        "directUserMembers": {
            "href": "https://api.pingone.com/v1/environments/abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6/users?filter=memberOfGroups%5Bid%20eq%20%22dbd479cb-fcd3-4c34-b5d3-ee2b60c86067%22%20and%20type%20eq%20%22DIRECT%22%5D"
        }
    },
    "id": "dbd479cb-fcd3-4c34-b5d3-ee2b60c86067",
    "environment": {
        "id": "abfba8f6-49eb-49f5-a5d9-80ad5c98f9f6"
    },
    "name": "Managers",
    "description": "This is a test group",
    "customData": {
        "groupOwner": "Tom Jones",
        "securityGroup": true
    },
    "createdAt": "2021-05-21T22:34:09.539Z",
    "updatedAt": "2021-05-21T22:34:09.539Z",
    "userFilter": "title eq \"Manager\""
}