Webhooks summary
Starting with version 4.1.5 we support Webhooks.
Webhooks gives the user the possibility to run existing SIL scripts, from outside of the Jira/Confluence instance, by using a REST/HTTP client, and retrieve the results of the script run.
In order for this to be possible, we need 2 things:
- Create a SIL script.
- Configure a webhook to run that SIL script.
Creating a SIL script
Almost any SIL script can be used, but the two Webhooks specific SIL routines getWebhookPayload and appendToWebhookResponse are the ones that make this feature powerful.
Example 1 - Getting the Webhooks payload from the calling client and returning custom results and HTTP response code:
//getting the REST/HTTP call input parameters: WebhookPayload httpRequestPayload = getWebhookPayload(); //getting the used HTTP method: string httpMethod = httpRequestPayload.httpMethod;//This can be something like "GET", "POST", "PUT" etc. //getting the http request payload (body): string httpPayload = httpRequestPayload.payload; //getting the http query parameters: WebhookParam[] httpQueryParams = httpRequestPayload.queryParams; string firstQueryParamName = httpQueryParams[0].name; string firstQueryParamValue = httpQueryParams[0].values[0]; //sending the response back to the caller: appendToWebhookResponse("http method:"); appendToWebhookResponse(httpMethod); appendToWebhookResponse("payload:"); appendToWebhookResponse(httpPayload); appendToWebhookResponse("firstQueryParamName:"); appendToWebhookResponse(firstQueryParamName); appendToWebhookResponse("firstQueryParamValue:"); appendToWebhookResponse(firstQueryParamValue); //returning a custom HTTP status code: return true, 1234;
The format for the return line, if used, should be return <
true
|false
>[
, <Custom HTTP status code>];
The first argument can only have the values true or false. True means that the script run was correctly, and false means that the script encountered a problem when it was run.
Webhooks Configuration
To define what URI and HTTP method will be used to invoke a specific SIL script, the SIL Webhooks Configuration should be used. The page is located under Add-ons -> CPRIME PLUGINS CONFIGURATION.
To create a Webhook entry, click the "Add webhook".
Fill the form with the desired Webhook name, the HTTP Method that will be used to trigger this webhook, the path to the desired script to be invoked, and weather or not the invocation should be Synchronous or not.
Returns a number representing the duration of the re-index in milliseconds.
NOTE
Parameters:
- Directory - the directory type. Only MS Active Directory is supported at the moment. If you have other LDAP type, ask for support.
- Name - the LDAP configuration name, unique.
- Base DN - the base DN, used as a root for that LDAP.
- User / Password - the LDAP user and the password (it is not usually a single word, but a string like shown above).
There are also two optional parameters:
- Connection time-out, self explanatory
- Use cache - if checked, it will cache the records. Use it for better performance, but it may not reflect exactly what's in the LDAP database.
Click the Test button to test the configuration validity. Any errors are reported back into the page dialog, allowing you to adjust your configuration until the connection is established successfully.
Once added, the LDAP configurations can be edited, removed and tested from the same page:
Changes are visible immediately.
Webhooks Authentication
Fore the REST/HTTP client to be able to make any Webhooks calls, it needs to be authenticated into the Jira/Confluence instance.
Please see the official Atlassian Security pages:
- https://developer.atlassian.com/server/jira/platform/basic-authentication/
- https://developer.atlassian.com/cloud/confluence/basic-auth-for-rest-apis/