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#

Any project with a failing scenario will work here. For convenience, you can use this one:

  1. From the Dataiku Design homepage, click + New Project > DSS tutorials > Advanced Designer > Webhook Reporters.

  2. 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:

  • Authorized (a score of 1 in the authorized_flag column)

  • Flagged for potential fraud (a score of 0)

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.

  1. 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.

  2. Have a Jira project key where you want the issue to be created. We’ll use KAN in this tutorial.

  3. Follow Atlassian’s documentation to create an API token.

  4. 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.

  1. Open the Data Refresh scenario.

  2. Within the Settings tab, click Add Reporter > Webhook.

  3. Name it Create Jira issue on failure.

  4. 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).

  5. For Request headers, click Add Header. Then enter:

    • Authorization as the header key.

    • Basic <your base64 encoded token> as the header value.

  6. 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}"
        }
    }
    
Dataiku screenshot of a webhook reporter.

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.

  1. Once you’ve saved the webhook reporter, click Run to manually launch the scenario.

  2. Navigate to the Last Runs tab to find a failed scenario run and what should be a successful webhook reporter.

    Dataiku screenshot of the last runs of a scenario showing a webhook reporter.
  3. Check your Jira instance for an issue in the project that you’ve specified.

    Dataiku screenshot of an issue in Jira created through a webhook reporter.

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.