How to make an Ajax / jQuery call towards the Qlik Sense Repository Service API

    Summary:


    The article illustrates how the syntax may look like in jQuery (using an Ajax call) when developers query the Qlik Sense Repository Service API (QRS API) to ping for example the “full” end point – more details on end points can be found here https://help.qlik.com/en-US/sense-developer/3.1/Content/Home-developer.htm. Once the call is made, the expected result will be a JASON response holding details about the applications hosted on the Qlik Sense Server, information like applications ID, owner, creation date schema path etc. Then the response is intercepted and displayed within a web page.

     

    Description:

     

    At times developers find themselves in need to query the Qlik Sense Repository Service API, the question that may come to mind is, how the syntax looks like when using JavaScript (Ajax call), how the URL parameters should look like, what should we put in the header, will it be a GET or POST call and also if the Qlik Sense Proxy is willing to consume such request and send us back something that we can use in our web application? These questions will be addressed in the resolution part below. Before we proceed, there are a few assumptions we have in place and they are:

     

    • This example has been tested on Qlik Sense Enterprise 3.1.3.
    • The QRS call has been tested first in Postman to make sure we get a proper response from the API. It is a good habit to test such API calls in order to make sure we are using the right URL and parameters needed for the call.
    • In QMC under the Proxies section, you must allow HTTP, for this example to work.
    • There is a need for creating a new virtual proxy in Qlik Sense Management Console (QMC). See images below for inspiration, it is the header authentication method that has been picked for this test for our testing, see images below:

     

    QMC 1.png

     

    QMC 2.png

     

    Resolution:


    The first step as mentioned above was testing the call in Postman to see if the API call itself is valid or not and if we get any response from QRS API. The URL and values used in Postman as well as the JASON response we got looks like this:

     

    postman.png

     

    With regard to the actual syntax of the Ajax call, it looks like this, note the path in the URL, qlikserver1.domain.local/mash, where mash is the prefix of the virtual proxy we created earlier:

     

    $(document).ready(function() {
    $.ajax({
    type:"GET",
      url:"http://qlikserver.mydomain.somrething/mash/qrs/stream/full?Xrfkey=abcdefghijklmnop",
    headers:{
      "X-Qlik-Xrfkey":"abcdefghijklmnop",
      "hdr-user":"domain\\administrator" // Can be changed to fit your needs including passing html form values
    }
    }).done(function(data) {
    console.log(data);
      $("#greeting-content").html(JSON.stringify(data));
    });
    });

     

    $("#greeting-content") is the reference to our DIV in the HTML page that is meant to display the response.

     

    The JASON response passed on to the HTML page:

     

    html result.png

     

    In case something missing then kindly refer to the example full source code (Ajax2QRSAPI.zip) attached to this article.

     

    This document was generated from the following discussion: The specified item was not found.