Add a User to a Batch of Groups
Adds an existing user to a batch of groups in Access Control using an ANSI or UTF-8 encoded CSV file that was uploaded to the environment. Use the Upload REST API to upload the file. The file should be deleted after the API executes. With this API, you can see which records failed and the reason why they failed in addition to how many records passed and failed. The file format is as follows:
Group Name
GroupA
GroupB
The user is added to the groups only if these conditions are met:
- The user must exist in the identity domain that services the environment
- The user must be assigned to a pre-defined role in the identity domain
- The groups provided must exist in Access Control and must not be pre-defined groups
Additionally, the user running this API must be authorized to perform this action. This API should be run only by a service administrator in the environment where the user is to be added to the groups.
The API is asynchronous and returns the Job ID. Use the job status URI to determine whether the assignment of a user to the groups is complete. The presence of status -1 in the response indicates that the addition of a user to groups is in progress. Any non-zero status except -1 indicates failure of adding a user.
This API is version v1.
Required Roles
Service Administrator or Access Control – Manage
REST Resource
PUT /interop/rest/security/<api_version>/groups
Note:
Before using the REST resources, you must understand how to access the REST resources and other important concepts. See Implementation Best Practices for EPM Cloud REST APIs. Using this REST API requires prerequisites. See Prerequisites.
Table 12-41 Tasks for Adding a User to a Batch of Groups
Task | Request | REST Resource |
---|---|---|
Add a user to groups | PUT | /interop/rest/security/<api_version>/groups |
Add a user to groups status | GET | /interop/rest/security/<api_version>/jobs/<jobId> |
Request
Supported Media Types: application/x-www-form-urlencoded
The following table summarizes the request parameters.
Table 12-42 Parameters
Name | Description | Type | Required | Default |
---|---|---|---|---|
api_version | Specific API version | Path | Yes | None |
jobtype | The string should have the value ADD_USER_TO_GROUPS . This value denotes that the user is being added to the groups.
|
Form | Yes | None |
filename |
The name of the uploaded ANSI or UTF-8 encoded CSV file containing the groups to add the user to, such as The file must have been uploaded already using the Upload REST API. File format example:
|
Form | Yes | None |
username | The name of the user to add to the provided list of groups. This user must already exist. | Form | Yes | None |
Response
Supported Media Types: application/json
Table 12-43 Parameters
Name | Description |
---|---|
details |
In the case of errors, details are published with the error string |
status |
See Migration Status Codes |
links |
Detailed information about the link |
href |
Links to API call or status API |
action |
The HTTP call type |
rel |
Possible values: self or Job Status . If the value is set to Job Status , you can use the href to get the status
|
data |
Parameters as key value pairs passed in the request |
items |
Details about the resource |
links |
Details of the first URL to be requested to get the job details; rel is "Job Details" |
Examples of Response Body
The following examples show the contents of the response body in JSON format:
Example 1: Job is in Progress
{
"links": [
{
"href": https://<BASE-URL>/interop/rest/security/<api_version>/groups,
"rel": "self",
"data": {
"jobType": "ADD_USER_TO_GROUPS",
"filename": "<filename>",
"username": "<username>"
},
"action": "PUT"
},
{
"href": https://<EPM-CLOUD-BASE-URL>/interop/rest/security/<api_version>/jobs/<jobId>,
"rel": "Job Status",
"data": null,
"action": "GET"
}
],
"details": null,
"status": -1,
"items": null
}
Example 2: Job Completes with Errors
{
"links": [
{
"rel": "self",
"href": "https://<BASE-URL>/interop/rest/security/v1/jobs/<jobID>",
"data": null,
"action": "GET"
}
],
"details": "Failed to add user to groups. Input file <fileName> is not found. Specify a valid file name.",
"status": 1,
"items": null
}
Example 3: Job Completes without Errors
{
"links": [
{
"rel": "self",
"href": "https://<BASE-URL>/interop/rest/security/<api_version>/jobs/<jobId>",
"data": null,
"action": "GET"
}
],
"details": "Processed - 3, Succeeded - 2, Failed - 1.",
"status": 0,
"items": [
{
"GroupName":"<GROUPNAME>","Error_Details": "Group <GROUPNAME> is not found. Verify that the group exists."
}
]
}
Java Sample Code
Prerequisites: json.jar
Common Functions: See: CSS Common Helper Functions for Java
public void addUserToGroups(String fileName, String userName) {
try {
String url = this.serverUrl + "/interop/rest/security/" + apiVersion + "/groups";
Map<String, String> reqHeaders = new HashMap<String, String>();
reqHeaders.put("Authorization", "Basic " + DatatypeConverter
.printBase64Binary((this.userName + ":" + this.password).getBytes(Charset.defaultCharset())));
Map<String, String> reqParams = new HashMap<String, String>();
reqParams.put("filename", fileName);
reqParams.put("jobtype", "ADD_USER_TO_GROUPS");
reqParams.put("username", userName);
Map<String, String> restResult = CSSRESTHelper.callRestApi(new HashMap(), url, reqHeaders, reqParams,
"PUT");
String jobStatus = CSSRESTHelper.getCSSRESTJobCompletionStatus(restResult, reqHeaders);
System.out.println(jobStatus);
} catch (Exception e) {
e.printStackTrace();
}
}
Shell Script Sample Code
Prerequisites: jq (http://stedolan.github.io/jq/download/linux64/jq)
Common Functions: See CSS Common Helper Functions for cURL
funcAddUserToGroups() {
url="$SERVER_URL/interop/rest/security/$API_VERSION/groups"
params="filename=$1&jobtype=ADD_USER_TO_GROUPS&username=$2"
header="Content-Type: application/x-www-form-urlencoded"
cssRESTAPI="AddUserToGroups"
statusMessage=$(funcCSSRESTHelper "PUT" "$url" "$header" "$USERNAME" "$PASSWORD" "$params" "$cssRESTAPI")
echo $statusMessage
}
Groovy Sample Code
Common Functions: See CSS Common Helper Functions for Groovy
def addUserToGroups(fileName, userName) {
String scenario = "Adding users in " + fileName + " to group " + userName;
String params = "jobtype=ADD_USER_TO_GROUPS&filename="+ fileName +"&username="+ userName;
def url = null;
def response = null;
try {
url = new URL(serverUrl + "/interop/rest/security/" + apiVersion + "/groups");
} catch (MalformedURLException e) {
println "Please enter a valid URL"
System.exit(0);
}
response = executeRequest(url, "PUT", params, "application/x-www-form-urlencoded");
if (response != null) {
getJobStatus(getUrlFromResponse(scenario, response, "Job Status"), "GET");
}
}