Tutorial | Webhook reporters in scenarios#
Scenario reporters can send messages to a variety of possible channels, including email, Microsoft Teams, and Slack. However, you can also use a webhook reporter to launch HTTP requests from other APIs. Let’s use Jira as one example!
Get started#
Objectives#
In this tutorial, you will:
Use a webhook reporter to post scenario information to an API.
More specifically, automatically create issues in Jira from the failure of a Dataiku scenario.
Prerequisites#
Dataiku 12.0 or later.
A Jira connection and API token (discussed below).
If you’ve never created a reporter, it’s recommended to begin with Tutorial | Scenario reporters.
Create the project#
From the Dataiku Design homepage, click + New Project.
Select Learning projects.
Search for and select Webhook Reporters.
Click Install.
From the project homepage, click Go to Flow (or
g
+f
).
From the Dataiku Design homepage, click + New Project.
Select DSS tutorials.
Filter by Advanced Designer.
Select Webhook Reporters.
From the project homepage, click Go to Flow (or
g
+f
).
Note
You can also download the starter project from this website and import it as a zip file.
Use case summary#
The project has three data sources:
Dataset |
Description |
---|---|
tx |
Each row is a unique credit card transaction with information such as the card that was used and the merchant where the transaction was made. It also indicates whether the transaction has either been:
|
merchants |
Each row is a unique merchant with information such as the merchant’s location and category. |
cards |
Each row is a unique credit card ID with information such as the card’s activation month or the cardholder’s FICO score (a common measure of creditworthiness in the US). |
Collect API information from Jira#
Jira is one example of a software tool to which you may wish to relay scenario information. We can do this with a webhook reporter, but we first need a few pieces of information from Jira.
If you don’t already have one, create a Jira account. You’ll need to know your instance URL, such as
dataiku.atlassian.net
and the email address associated with your Jira account.Have a Jira project key where you want the issue to be created. We’ll use
KAN
in this tutorial.Follow Atlassian’s documentation to create an API token.
Following Atlassian’s documentation on basic authentication for REST APIs, BASE64 encode a string of the form
useremail:api_token
, and save it. In other words, run the following in a terminal:
echo -n <your jira user email>:<your api token> | base64
Tip
Our goal is to demonstrate a webhook, but an alternative to a webhook reporter in the case of Jira is to use a mail handler.
Create the webhook reporter#
Once we have this information from Jira, we can create the webhook reporter in the scenario.
Open the Data Refresh scenario.
Within the Settings tab, click Add Reporter > Webhook.
Name it
Create Jira issue on failure
.For the URL, enter
https://<your instance url>/rest/api/2/issue
(e.g.https://dataiku.atlassian.net/rest/api/2/issue
for a cloud instance).For Request headers, click Add Header. Then enter:
Authorization
as the header key.Basic <your base64 encoded token>
as the header value.
In the Body section, copy-paste the JSON below as a starting point, adjusting the values for the issue type and project key as necessary.
{ "fields": { "summary": "[DSS] Scenario execution failure - ${scenarioName}", "issuetype": { "name": "Issue" }, "project": { "key": "KAN" }, "description": "The scenario ${scenarioName} triggered by ${triggerName} (${triggerType}) has failed. \nStep to fail was: ${firstFailedStepName}\n\nYou can check the scenario log at ${scenarioRunURL}" } }
Tip
Feel free to further customize the body according to the documentation for a rest/api/2/issue endpoint, as well as variables related to the scenario found at the bottom of the scenario’s Settings page.
Run the scenario#
Once the webhook reporter is in place, we can run the scenario.
Once you’ve saved the webhook reporter, click Run to manually launch the scenario.
Navigate to the Last Runs tab to find a failed scenario run and what should be a successful webhook reporter.
Check your Jira instance for an issue in the project that you’ve specified.
What’s next?#
Congratulations! You’ve seen how to use a webhook reporter to post scenario results to an API outside of the other messaging channels.
See also
You can find more about reporters in the reference documentation.