In This Article
This article provides examples on how to manage Business Units programmatically using the IriusRisk API. These steps will require an API key if you've not yet generated one.
Permissions Required
- ALL_USERS_UPDATE
- PRODUCTS_LIST_ALL
- MANAGE_USERS_BU
- PRODUCT_UPDATE
Instructions
The following examples will demonstrate use cases from the complete set of Business Unit API endpoints found here.
Adding Multiple Business Units to a Project
Multiple Business Units can be added directly to the "groups" block in an API call as shown below:
curl -X 'PUT' \ 'https://example.iriusrisk.com/api/v1/products/example-project/businessunits' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -d '{ "groups": [ "BusinessUnit1", "BusinessUnit2" ] }'
Adding Multiple Business Units to Multiple Projects
Multiple business units can be added to multiple projects simultaneously by relying on a for loop directly from the shell.
First, we'll cast our desired business units to a list. With a standard zsh this would look like:
projects=(Project1 Project2 Project3)
Be aware this operation varies based on your shell. Using fish for example, this same operation would look like:
set projects Project1 Project2 Project3
Next, we'll iterate on our new list of Business Units using a for loop in conjunction with our previous API call:
for project in $projects; curl -LX PUT "https://example.iriusrisk.com/api/v1/products/{$project}/businessunits" -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'api-token: your-API-token-here' -d '{ "groups": [ "BusinessUnit1","BusinessUnit2" ] }'; end
We can clean up the JSON output into a more digestible format by taking the same command from above and piping the loop into jq, a JSON parser:
for project in $projects; curl -LX PUT "https://example.iriusrisk.com/api/v1/products/{$project}/businessunits" -H 'Accept: application/json' -H 'Content-Type: application/json' -H 'api-token: your-API-token-here' -d '{ "groups": [ "BusinessUnit1","BusinessUnit2" ] }' | jq; end
If successful, this should produce human-readable output for each project that looks similar to this:
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 248 0 203 100 45 949 210 --:--:-- --:--:-- --:--:-- 1186
{
"ref": "example-project",
"name": "Example Project",
"revision": 1,
"type": "STANDARD",
"status": "OPEN",
"priority": 0,
"tags": null,
"workflowState": null,
"udts": [],
"groups": [
"BusinessUnit1",
"BusinessUnit2"
],
"users": null
}
Comments
0 comments
Please sign in to leave a comment.