Accessing policies remotely using the REST API
The REST API allows you to access and run policies over a REST interface.
Users must possess the impactAdminUser
role to access the
REST interface.
Executing a policy
To execute a policy without any parameters, send a GET
request:
curl -u <USERNAME>:<PASSWORD> -k https://<HOST>:<PORT>/restui/policyui/policy/<POLICY>/run
Where the following definitions apply:
USERNAME
is the name of the Impact user.
PASSWORD
is the Impact user's password.
HOST
is the hostname or IP address of the Impact server.
PORT
is the backend port for the Impact server.
POLICY
is the name of the policy to run.
Example
curl -u impactadmin:password -k https://impacthost:9081/restui/policyui/policy/TestPolicy1/run
If the request succeeded, the following message is returned:
Successfully executed the Policy: TestPolicy1
Execute a policy with output parameters
To execute a policy that returns a response, send a GET
request:
curl -u <USERNAME>:<PASSWORD> -k https://<HOST>:<PORT>/restui/policyui/policy/<POLICY>/runwithoutput
The policy must be configured with one or more output parameters otherwise no response is returned.
See Configuring policy parameters and enabling actions
Example
curl -u impactadmin:password -k https://impacthost:9081/restui/policyui/policy/TestPolicy2/runwithoutput
If the request succeeded, a JSON string is returned with the following policy context and output parameters:
{"ReportsPolicyName":{"items":[{"ReportsPolicyName":"TestPolicy2"}]},"PolicyName":{"items":[{"PolicyName":"TestPolicy2"}]},"ActionNodeName":{"items":[{"ActionNodeName":"TestPolicy2"}]},"OUTVAR":{"items":[{"OUTVAR":"Some Text"}]}}
Execute a policy with input and output parameters
To execute a policy that accepts input and returns output, send a POST
request:
curl -u <USERNAME>:<PASSWORD> -X POST -k https://<HOST>:<PORT>/restui/policyui/policy/<POLICY>/runwithinputparameters -H "Content-Type: application/json;charset=utf-8"
The policy must be configured with input and output parameters.
See Configuring policy parameters and enabling actions
POST
request must declare a JSON
content type header
("Content-Type: application/json;charset=utf-8"
) otherwise the request is
ignored.Example
curl -u impactadmin:password -X POST -d '{"STRING1":"test","NUM1":123}' -k https://impacthost:9081/restui/policyui/policy/TestPolicy3/runwithinputparameters -H "Content-Type: application/json;charset=utf-8"
If the request succeeded, a JSON
string is returned with the following policy
context and output variables:
{"ReportsPolicyName":{"items":[{"ReportsPolicyName":"TestPolicy3"}]},"STRING1":{"items":[{"STRING1":"test"}]},"PolicyName":{"items":[{"PolicyName":"TestPolicy3"}]},"ActionNodeName":{"items":[{"ActionNodeName":"TestPolicy3"}]},"OUTVAR":{"items":[{"OUTVAR":"Some result"}]},"NUM1":{"items":[{"NUM1":"123"}]}}
Retrieving a policy
To retrieve the text of a policy, send a GET request:
curl -u <USERNAME>:<PASSWORD> -k https://<HOST>:<PORT>/restui/policyui/policy/<POLICY>/load
Example
curl -u impactadmin:password -k https://impacthost:9081/restui/policyui/policy/TestPolicy3/load
If the request succeeded, a JSON string with a copy of the policy text is returned. The policy text will be in Java string format and special characters such as newlines, double quotes and slashes will be escaped.
{"script":"Log(\"Test\");\n\nLog(CurrentContext());\n\nLog(EventContainer);\n"}
Listing all polices
To list all the policies in the Impact server, send a GET request to
/restui/policyui/policy/list
curl -u <USERNAME>:<PASSWORD> -k https://<HOST>:<PORT>/restui/policyui/policy/list
Example
curl -u impactadmin:password -k https://impacthost:9081/restui/policyui/policy/list
If the request succeeded, a JSON string with an array of the policy names is returned.
{"identifier":"name","label":"name","items":[ {"name":"DefaultExceptionHandler"},
{"name":"DefaultPolicyActivatorExample"}, {"name":"DeployProject"},
{"name":"DiscreteOidSetTest"}, {"name":"DiscreteOidTest"}, ..... ]}