Invoke Workflows
Invoke Workflows
Introduction
Invoke workflow
Introduction
Snow Automation Platform's API allows invoking workflows from other system. To invoke a workflow, a json string with all the parameter values and information of what activity in the workflow the parameter belongs to must be posted to the API. A workflow can have one or more workflow activities and an activity can have one or more parameters. All parameters that require a value must be posted to the API when the workflow is invoked.
Example
A software is synchronized from Snow License Manager with SAM Automation book. By invoking a workflow, a request of a specific software can be triggered from another system.
Invoke Workflow
To invoke a workflow in Snow Automation Platform, perform the following steps:
- Find the parameter values.
- Create the json string.
- Post the json string to the API endpoint.
The information posted to the API should contain the following object structure:
- A list of parameters, where each parameter defines:
- The value of the parameter
- A reference to the parameter
- A reference to the workflow activity
- Optionally, the display name
- A reference to the workflow to invoke
- Optionally, a reference to the service to invoke the workflow for
NOTE
A parameter, workflow activity, workflow, or service can be referenced by name, Id or MissitoId.
If a reference is made by a name or other free text fields, then the integration might fail if the name of the attribute is changed. To minimize the risk of integration failure, it is recommended to use Id or MissitoId, because they are never changed.
However, in this guide, the objects are referenced by a name to increase the readability. The display name for the parameters is used in addition to the Id. Also, the display names for the service and the workflow are used instead of the MissitoIds.
NOTE
If the reference to the service is not set, there will be no reference to what service was requested. However, the workflow will still execute with the same information.
Find the Parameter Values
- Log in to Snow Automation Platform user interface as an administrator.
NOTE
In this instruction, Google Chrome browser is used.
- On the Administer menu, click Service admin.
- Select the service.
- On the General tab for the service, find the following information and save the information. The information is used when the json file is created.
- Name
- Id and MissitoId (called Unique id in the user interface).
Note
The Identities are found in the tooltip for Name.
-
Press F12 to start Developer Tools.
-
In Developer Tools, click the Network tab to record the network traffic.
-
Send a request for the service:
-
Add the service to the Cart.
-
Go to Checkout.
-
Configure all required parameters.
-
Click Submit to send the request.
-
Verify that the order is successfully sent.
-
-
On the Network tab in the Developer Tools, investigate the call made to https://servername/API/OrderCart/[requestId]/Checkout :
-
Select the request named Checkout.
-
On the Headers tab, scroll down and expand Request Payload.
-
For every parameter, find the values for the parameters and save the information. The information is used when the json file is created.
-
Create the JSON String
NOTE
This instruction uses a workflow for installing a software as an example of how to create the json string.
-
Create a json framework:
$jsonBody = "{ 'Parameters': [], 'Workflow': {}, 'Service': {} }" -
Add a reference to the service.
Example:
'Service': { 'name': 'Adobe Acrobat XI Pro' }`
- Add a reference to the workflow.
Example:
'Workflow': { 'name': 'Install software' },`
-
Create a placeholder to pass information of each parameter:
{ 'value': '', 'parameter': {}, 'workflowActivity': {} } -
For each parameter, add value and references to the parameter.
Example:
{
'displayName': 'Target computer',
'value': 'DOMAIN\\computername',
'parameter': { 'id': 125 },
'workflowActivity': { 'id': 2 }
}
Note
Special characters, for example backslash, might need to be escaped.
- Finalize the json string.
Example:
$jsonBody = "{ 'Parameters': [
{
'displayName': 'Target computer', 'value': 'DOMAIN\\computername', 'parameter': { 'id': 125 }, 'workflowActivity': { 'id': 2 }
},
{
'displayName': 'Reason for request', 'value': '',
'parameter': { 'id': 139 }, 'workflowActivity': { 'id': 4 }
},
{
'displayName': 'Requesting user',
'value': 'DOMAIN\\username', 'parameter': { 'id': 184 }, 'workflowActivity': { 'id': 4 }
},
{
'displayName': 'Select manager approver', 'value': 'DOMAIN\\username', 'parameter': { 'id': 142 }, 'workflowActivity': { 'id': 5 }
}
],
'Workflow': { 'name': 'Install software' }, 'Service': { 'name': 'Adobe Acrobat XI Pro' }
}"
Post the JSON String to the API Endpoint
This instruction uses a workflow for installing a software as an example of how to post a json string to the API endpoint.
- Start Windows PowerShell ISE.
- Import the IgapCore module: Import-Module C:\Program Files\Snow Software\Snow Automation Platform \CoreScripts\IgapCore.psm1
- Assign the json string to a variable:
Example:
$jsonBody = "{ 'Parameters': [
{
'displayName': 'Target computer', 'value': 'DOMAIN\\computername', 'parameter': { 'id': 125 }, 'workflowActivity': { 'id': 2 }
},
{
'displayName': 'Reason for request',
'value': '',
'parameter': { 'id': 139 },
'workflowActivity': { 'id': 4 }
},
{
'displayName': 'Requesting user',
'value': 'DOMAIN\\username',
'parameter': { 'id': 184 }, 'workflowActivity': { 'id': 4 }
},
{
'displayName': 'Select manager approver',
'value': 'DOMAIN\\username', 'parameter': { 'id': 142 }, 'workflowActivity': { 'id': 5 }
}
],
'Workflow': { 'name': 'Install software' },
'Service': { 'name': 'Adobe Acrobat XI Pro' }
}"
-
Validate the json string before it is posted to the API, run ConvertFrom-Json on the string:
ConvertFrom-Json $jsonBody -
Post the jsonbody to the API endpoint: https://servername/API/InvokeWorkflow.
To automatically get the XSRF (cross-site request forgery) token needed to post information to the API, use the Invoke-APRestMethod cmdlet:
Invoke-APRestMethod -uri "http://localhost/API/InvokeWorkflow" -method Post - body $jsonBody -
Verify that the request was successfully submitted.
| id | : 9 |
|---|---|
| requestingUserID | : DOMAIN\username |
| requestingUserDisplayName : Firstname Lastname (firlas) | |
| status | : Submitted |
| dateCreated | : 2017-06-20T18:44:30.9121341+02:00 |
| dateModified | : 2017-06-20T18:44:30.9121341+02:00 |
| self | : @ |
The request should also be visible in the Request monitor in Snow Automation Platform.
NOTE
The new endpoints to invoke workflows are protected against cross-site request forgery. This requires you to get and pass a session cookie and header with the http request. To simplify this there is a function added in the IgapCore.psm1 PowerShell module. Import this module or get the functions from it into the script that invokes the workflow.