Skip to main content

How to run Qlik AutoML prediction using Call URL block in Qlik Application Automation

No ratings
cancel
Showing results for 
Search instead for 
Did you mean: 
Ankit_KSingh
Support
Support

How to run Qlik AutoML prediction using Call URL block in Qlik Application Automation

Last Update:

Aug 8, 2022 5:00:57 AM

Updated By:

Ankit_KSingh

Created date:

Aug 19, 2022 9:42:12 AM

Attachments

Qlik Application Automation has a "Call URL" block that allows you to call a URL when the automation needs data from a URL or when it needs to send data to a URL. This article explains how this block can be used to run a Qlik AutoML prediction right from the Qlik Application Automation.

The Call URL block calls a URL, typically from an API.

call_url_1.png

 

Configuring a call URL block to run a Qlik AutoML prediction

 

Things we need from the Qlik AutoML environment

  • The base Url to use

                  Ex: https://{enter_your_automl_env_here}/api/v1/automl/graphql 

  • API key (you can get it from the Profile Settings -> API key, from your tenant.
  • Deployment Id: You can get it from the Url of “ML Deployment” from the hub.

                  Ex: ML Deployment Url:

                  https://{automl_environment_url}/automl/deployed-model/5048076e-bea6-xxxx-b79e-a8a45b316b08 

                 Deployment Id: 5048076e-xxxx-43fa-b79e-a8a45b316b08

 

Inputs for the block

  • URL: You can get it from the Qlik AutoML environment as mentioned above.
  • Method: POST
  • Headers: You need to add two headers as a key-value pair.
    • Authorization: Bearer {Enter API Key Here}
    • Content-Type: application/json

How this works

Running a Prediction Dataset makes use of 2 API calls:
  • Step1: we call the “List Predictions” Api which takes in “deploymentId” as input and returns the “predictionIDs”.
  • Step2: We use this predictionID in the next API call to run the prediction. This process is explained in two steps below.
Please see below for details

Step 1(List Predictions): First we need to call the API to list the prediction datasets from a deployed model. For this, we need to add proper ‘query” and “variable” params in the call URL block.

You can use the ‘Raw Input’ option to enter these parameters.

call_url_2.png

IMP Note: Your ML Deployment model must have at least one dataset prediction to run.

Please copy the following JSON and replace the deploymentId with your deploymentId you got from ML Deployment Url and paste it into the automation after triggering the raw input option of ‘Params’.

 

 

 

 

{
    "query": "query Predictions($filter: PredictionFilter) {\r\n  predictions(filter: $filter) {    total    rows {      id    }  }}",
    "variables": {
        "filter": {
            "deploymentId": "5048076e-xxxx-43fa-xxxx-a8a45b316b08"
        }
    }}

 

 

 

 

call_url_3.png

Output from this Call Url block will contain the list of Ids of Prediction datasets from your selected ML Deployment.

call_url_5.png

Step 2(Run Prediction): Now we need to call the RunPrediction API with the prediction dataset Id we obtained in the previous step as the input. For this, we need to add proper ‘query” and “variable” params in the call URL block.

You can use the ‘Raw Input’ option to enter these params

call_url_4.png

Please copy the following JSON and replace the predictionID with the predictionID you got in the output in the previous step and paste it into the automation after triggering the raw input option of ‘Params’.

 

 

 

 

{
  "query": "mutation RunPrediction($predictionId: String!) {  runPrediction(predictionId: $predictionId) {    info {      id      status    }  }}",
  "variables": {
    "predictionId": "c1bdbd62-xxxx-40e0-xxxx-b10c5bd7d350"
  }
}

 

 

 

 

call_url_6.png

Running this will run the Prediction dataset whose Id you provided.

call_url_7.png

Steps to create an automation that will run on a schedule

  1. Create new automation and drag a Call URL block from the left panel onto the canvas.

    call_url_8.png

  2. In the settings of the start block, select the run mode as ‘Scheduled’ and select the ‘Scheduled Every’ to desired option to make the automation run regularly.

    call_url_9.png

  3. Now set up the Call Url block as explained above to call the “List Predictions” API. Enter your deployment Id in the parameters.

    call_url_10.png

  4.  Take a variable block from the left panel, add a string variable, and set the value to ‘id’ from the result of the above Call Url block by selecting the ‘Select all id(s) from list rows’ option.

    call_url_11.png

    call_url_12.png

  5. Now take a loop block from the left panel and set it to loop through the values in the “PredictionId’ variable.

    call_url_13.png

  6. Take another Call Url block from the left panel and set it to call the ‘Run Prediction’ API as explained above. Set the predictionID value to the ‘item in loop’ in the params. Add this block inside the loop.

    call_url_14.png

  7.         Add an output block and set it to get the output from the second Call Url block.

 

We have attached an example template showcasing the above automation as a JSON file. You can upload(import) this file into your application automation.

You can find the process to import the file into automation here: How-to-import-and-export-automations 

 

The information in this article is provided as-is and will be used at your discretion. Depending on the tool(s) used, customization(s), and/or other factors ongoing support on the solution below may not be provided by Qlik Support.

 

Labels (2)
Contributors
Version history
Last update:
‎2022-08-08 05:00 AM
Updated by: