1. Home
  2. Application Programming Interface
  3. Qlik Sense, how to use Survalyzer API as data source

Qlik Sense, how to use Survalyzer API as data source

A prerequisite for using Survalyzer’s API is the unblocking of the public IP-Address. A step by step instruction is available here: http://education.survalyzer.com/knowledge-base/api-usage-introduction/

Keep in mind that retrieving data using the Survalyzer API a is a 2-step process. First a connection is needed for retrieving an access token. Only after having created an access token the actual data connection can be set up.

After installing Qlik Sense navigate to the Data load editor and set up a new connection.

Step 1: Retrieving the access token

Hit ‘Test connection’ to test the configuration and save. Click on the select data button  to select the data and then choose to insert the script.

Get a data preview of that call to receive the access token. Without that token it won’t be possible to retrieve any data. Copy the AccessToken value.

Step 2: Setting up a connection for retrieving survey data

Make sure that the url you’re using contains the correct server and locale.

To get Survey Data it’s usually the ReadSurveyData call from our public api.

Define the query headers as seen in the picture above: Content-Type: application/json

Accept: application/json Authorization: Bearer [AccessToken]

Set all Settings as seen above. Hit ‘Test connection’ to test the configuration and save.

Click on the select data button to select the data and choose ‘Insert script’.

Qlik Sense will now insert the load script based on the access token created earlier. This access token is hard coded and will expire after 3 hours, making it impossible to fully automate the data fetching process. The get around this, some extra scripting is needed using the token variable created earlier.

Step 3: Modify the Qlik load script to use the access token as a variable

You’ll find something like this in your script:

LIB CONNECT TO 'REST_httpsdpd.survalyzer.chpublicapiLoginGetApiToken';
RestConnectorMasterTable:
SQL SELECT
   "$type",
   "accessToken",
   "isSuccess"
FROM JSON (wrap on) "root";

This is the connection to receive the AccessToken, which now must be saved in a variable. You can save the token like this:

[root]:
LOAD
   [accessToken]
RESIDENT RestConnectorMasterTable;
Let vAccessToken = Peek('accessToken',0,'RestConnectorMasterTable');
DROP TABLE RestConnectorMasterTable;

Like this you save the AccessToken in a variable. To use it in the next connection we have to add some small script to the GetSurveyData call.

Within the inserted script for the survey data you’ll find something like this:

FROM JSON (wrap on) "root" PK "__KEY_root";

Here we need to add the saved AccessToken like this:

FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION (
HTTPHEADER "Authorization" "Bearer $(vAccessToken)"
);

Now with every reload, Qlik will first request a new refresh token, then store it into a variable, and finally use that token in the following REST call to complete the authorization.

Updated on January 29, 2020

Was this article helpful?

Related Articles