Add Groups (v1)

Adds 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. The file format is as follows:

Group Name,Description
GroupA,GroupADescription
GroupB,GroupBDescription

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 groups are to be added. 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 API is asynchronous and returns the Job ID. Use the job status URI to determine whether adding groups is complete. The presence of status -1 in the response indicates that the addition is in progress. Any non-zero status except -1 indicates failure of adding a group.

This REST API is version v1.

Required Roles

Service Administrator or Access Control Manager

Table 12-47 Tasks for Adding a Batch of Groups

Task Request REST Resource
Create groups POST /interop/rest/security/<api_version>/groups
Create groups status GET /interop/rest/security/<api_version>/jobs/<jobId>

REST Resource

POST /interop/rest/security/<api_version>/groups

Supported Media Types: application/x-www-form-urlencoded

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.

The following table summarizes the request parameters.

Table 12-48 Parameters

Name Description Type Required Default
api_version Specific API version Path Yes None
filename

The name of the uploaded ANSI or UTF-8 encoded CSV file containing the groups to add, such as addGroups.csv.

The file must have been uploaded already using the Upload REST API.

File format example:

Group Name,Description
GroupA,GroupADescription
GroupB,GroupBDescription
Form Yes None

Response

Supported Media Types: application/json

Table 12-49 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 in JSON format.

Example 1, when job is in progress

{
    "links": [
        {
            "href": "http://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/interop/rest/security/<api_version>/groups",
            "rel": "self",
            "data": {
                "jobType": "ADD_GROUPS",
                "filename": "<filename>"
            },
            "action": "POST"
        },
        {
            "href": "http://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/interop/rest/security/<api_version>/jobs/<jobId ",
            "rel": "Job Status",
            "data": null,
            "action": "GET"
        }
    ],
    "status": -1,
    "details": null,
    "items": null
}

Example 2, when job completes with errors:

{
    "links": [
        {
            "href": "http://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com/interop/rest/security/<api_version>/groups",
            "rel": "self",
            "data": {
                "jobType": "ADD_GROUPS",
                "filename": ""
            },
            "action": "POST"
        }
    ],
    "status": 1,
    "details": "EPMCSS-20671: Failed to create groups. Invalid or insufficient parameters specified. Provide all required parameters for the REST API. ",
    "items": null
}

Example 3, when job completes without errors:

{
    "links": [
        {
            "data": null,
            "action": "GET",
            "href": " http://<SERVICE_NAME>-<TENANT_NAME>.<SERVICE_TYPE>.<dcX>.oraclecloud.com /interop/rest/security/<api_version>/jobs/<jobId>",
            "rel": "self"
        }
    ],
    "status": 0,
    "details": "Processed - 4, Succeeded - 3, Failed - 1.   ",
    "items": [
    {
				"GroupName":"<GROUPNAME>","Error_Details": "Failed to create a group with the name <GROUPNAME>. This group already exists in the system. Provide a different group name."
     }
   ]
}

Example 12-20 Java Sample Code

Prerequisites: json.jar

Common Functions: See: CSS Common Helper Functions for Java

public void addGroups(String fileName) {
		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);

			Map<String, String> restResult = CSSRESTHelper.callRestApi(new HashMap(), url, reqHeaders, reqParams,
					"POST");
			String jobStatus = CSSRESTHelper.getCSSRESTJobCompletionStatus(restResult, reqHeaders);
			System.out.println(jobStatus);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

Example 12-21 Shell Script Sample Code

Prerequisites: jq (http://stedolan.github.io/jq/download/linux64/jq)

Common Functions: See CSS Common Helper Functions for cURL

funcAddGroups() {
        url="$SERVER_URL/interop/rest/security/$API_VERSION/groups"
        params="filename=$1"
        header="Content-Type: application/x-www-form-urlencoded;charset=UTF-8"
        cssRESTAPI="addGroups"
        statusMessage=$(funcCSSRESTHelper "POST" "$url" "$header" "$USERNAME" "$PASSWORD" "$params" "$cssRESTAPI")
        echo $statusMessage
}

Example 12-22 Groovy Sample Code

Common Functions: See CSS Common Helper Functions for Groovy

def addGroups(fileName) {

	String scenario = "Creating Groups in " + fileName;
	String params = "filename="+ fileName;
	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, "POST", params, "application/x-www-form-urlencoded");
	if (response != null) {
		getJobStatus(getUrlFromResponse(scenario, response, "Job Status"), "GET");
	}
}
Common Functions