Skip to main content
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
Showing results for 
Search instead for 
Did you mean: 
Partner - Contributor
Partner - Contributor

Need help on how to dynamically assign Cookie header using REST API connector in Qlik Sense

Hello Qlik Community,

I'm in need of some guidance on how to pass REST API authentication cookie dynamically for my API GET calls. I have gone through all the posts and articles related to setting cookie for REST connector but I'm not able to make it work so I'm hoping that you would be able to provide the solution or point me in the right direction.

Here's what I'm currently doing

- Using Postman, I'm doing a POST call to the REST API of the application to fetch the cookie

- Next, using Qlik REST API connector, I'm setting it up for a GET call and putting the Cookie information in the query header

- After testing the connection, I'm able to successfully load the data into Qlik app

- I tried adding the WITH CONNECTION syntax that was mentioned in some of the related posts but keep getting the HTTP protocol error 401 (Unauthorized): Requested resource requires authentication

My goal is to do multiple GET calls to fetch data from the third-party application but I don't want to create REST Connection in Qlik for each of them with a pre-defined session cookie as the cookie will expire after some time and it's not feasible to keep updating the cookie in the REST connectors every time I want to load data into my app as I want to set up a task for the app reload so want the session cookie to be dynamically set in my load script.

Below is my current load script that was generated by Qlik when I loaded the data through the REST Connection I created as mentioned in the initial steps. The script works if I remove the WITH CONNECTION as it directly gets the Cookie information from the REST Connector where I had entered it manually. I'm looking for a way to not depend on this REST Connector and use Qlik load script to get the session cookie and then use it as query headers for the subsequent GET calls. Please indicate where I'm going wrong and what I need to do to make this app work to dynamically generate the session cookie for authentication for the GET calls

Set dataManagerTables = '','records','availability','ips','groups','wifi','nodetonode','realservice','continuousRealservice';
//This block renames script tables from non generated section which conflict with the names of managed tables

For each name in $(dataManagerTables)
Let index = 0;
Let currentName = name;
Let tableNumber = TableNumber(name);
Let matches = 0;
Do while not IsNull(tableNumber) or (index > 0 and matches > 0)
index = index + 1;
currentName = name & '-' & index;
tableNumber = TableNumber(currentName)
matches = Match('$(currentName)', $(dataManagerTables));
If index > 0 then
Rename Table '$(name)' to '$(currentName)';
Set dataManagerTables = ;

Unqualify *;

LIB CONNECT TO [<Name of the REST Connection created>];

[name] AS [name_u0],
Timestamp([lastRestart] ) AS [lastRestart],
[__KEY_records] AS [-_KEY_records],
[__FK_records] AS [__KEY_root],
GeoMakePoint([latitude], [longitude]) AS [longitude_latitude];
FROM "records" PK "__KEY_records" FK "__FK_records")
FROM JSON (wrap on) "root" PK "__KEY_root" QDL
URL "<URL name>/api/probes",
HTTPHEADER "Cookie" "$(vCookie)"

[__FK_availability] AS [-_KEY_records];
FROM "availability" FK "__FK_availability")
FROM "records" PK "__KEY_records" FK "__FK_records")
FROM JSON (wrap on) "root" PK "__KEY_root" QDL;

Labels (1)
1 Reply

This will depend on the REST endpoint, but we have a doc that may be helpful:
Handling Refresh Tokens with the Qlik REST Connector

To help users find verified answers, please don't forget to mark a correct resolution or answer to your problem or question as correct.