Workflow Actions

Workflow automator enables admins to create automated workflows for routine processes by using events, conditions, and actions. You can define additional actions in an app so as to extend the capability of workflows. Take an example of a workflow that assigns all software license requests to a specific team. Now, you can add additional actions, such as granting access to GitHub, Azure, and other software, to automate the entire process.
Take a look at the GitHub Workflow Actions sample app for a demonstration of this feature.

Note:
You need to have CLI v4.6.0 or higher in order to use this feature. For more information on how to get the latest version, click here.

Create Actions

To build an action, you need to:

  1. Configure the actions.json file.
  2. Add an action callback in the server.js file.
Configure Actions

The actions.json file contains information about all actions defined in an app and must be added in the root folder of the app. The actions defined in the file must be of the following format.

actions.json Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{ "<actionCallbackName>": { "display_name": "", "parameters ": { "$schema": "http://json-schema.org/draft-04/schema#", "type": "<a valid data type specific to the JSON schema>", "properties": { "argument1": { "type": "<a valid data type specific to the JSON schema>" }, "argument2": { "type": "<a valid data type specific to the JSON schema>" } } } } }
EXPAND ↓

The fields and their description are listed in the following table.

FIELD DESCRIPTION
actionCallbackName Unique identifier of the callback function in the server.js file.
display_name Name of the action displayed in the workflow automator interface.
parameters Input parameters for the action. The input objects defined must follow the specified JSON-Schema.
description Definition of what the custom action does.


Sample action (action.json) to invite a user to a GitHub repository Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
{ "inviteUser" : { "display_name" : "Invite User to Organization", "parameters" : { "$schema": "http://json-schema.org/draft-04/schema#", "type": "object", "properties": { "user_github_handle": { "type": "string" }, "user_role": { "type": "string" } }, "required": [ "user_github_handle", "user_role" ] }, "description": "Sends an email invitation to a user to join GitHub." } }
EXPAND ↓
Define Action Callback

You must define the action callback in the server.js file. You must use the renderData() method to return the result of the action to the workflow automator. A data object is returned for success and an error object for failure.

server.js Copied Copy
1
2
3
4
5
6
7
actionCallbackName: function(args) { //implementation code //if success renderData(null, {"success": true, "data": response.body}); //if error renderData(null,{"success": false, "error": <error message/object>}); }

Sample action callback (server.js) to invite a user to the github repository Copied Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
exports = { inviteUser : function(args) { const options = {url : "https://api.github.com/orgs/${args.iparams.organization}/memberships/${args.user_github_handle}", headers : { Authorization : "Bearer ${args.iparams.gitAdminKey}", "Content-Type": "application/json" }, method: "PUT", data: { "role": args.user_role || "member" } }; request(options, function(error, response) { if(!error && response.statusCode === 200) { renderData(null, {"success": true, "data": response.body}); } renderData(null,{"success": false, "error": "Error while sending request to user"}); }); }
EXPAND ↓
Testing

To test actions on your machine, follow the steps below.

  1. In your console, navigate to your project directory and execute the following command. $ fdk run
  2. Open your browser and enter the URL: http://localhost:10001/web/test
  3. From the Select type drop-down list, select actions.
  4. From the Select an action drop-down list, select the action that you want to simulate and the corresponding payload is displayed.
  5. Edit the required values and click Simulate. When you edit the payload, ensure that it adheres to the JSON format.
  6. If the action is successfully simulated, Success is displayed.
  7. If there is a problem, Failed is displayed. Check if the payload is valid and resume testing.

Log in with your Freshservice account

Enter your helpdesk URL to proceed to login

Proceed

By clicking "Proceed", you agree to our Terms of Use.