Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
cecilieleonhard
Partner - Contributor
Partner - Contributor

Qlik Sense rest API with changing login token

Hello!

Does anyone know if it is possible to get data from an API where the login token changes with each login?`

My case is the following:

To connect to the API I'm trying to connect to, I have two tokens, one which is for the current login and another one which I need to get a new token for the next time I login. That means that I need Qlik to save the second token for my next login so that I can get a new login-token and a refresh token.

Does anyone know how to do this?

3 Replies
Levi_Turner
Employee
Employee

How do you get the token? For example is it HMAC? Is it retrieved from a POST call? etc.

cecilieleonhard
Partner - Contributor
Partner - Contributor
Author

Thanks for your reply, 

 

It is retrieved through a POST call.

Levi_Turner
Employee
Employee

Ahh. Well you can use WITH CONNECTION to pass a param from the POST to subsequent GETs. For example:

 
LIB CONNECT TO 'CONNECT';
SET vRequestBody = '{"username":"foo","password":"bar"}';  
let vRequestBody = replace(vRequestBody,'"', chr(34)&chr(34)); 

RestConnectorMasterTable:
SQL SELECT 
	"Set-Cookie" as "Set-Cookie"
FROM JSON "_response_header" PK "__KEY__response_header"
WITH CONNECTION (   
    URL "URL://Path",   
    HTTPHEADER "Content-Type" "application/json",   
  BODY "$(vRequestBody)"  
  );
  
  
Let cookie = Peek('Set-Cookie',0,'RestConnectorMasterTable');
Let session_id = Trim(SubField(cookie,';',1));
Trace $(session_id); 
DROP TABLE RestConnectorMasterTable;
// Begin subsequent GET with the Cookie from the JSON response from earlier
let URL_path = 'URL://Path';
let vURL_path = replace(URL_path,'"', chr(34)&chr(34)); 
LIB CONNECT TO 'Workflow';

RestConnectorMasterTable:
SQL SELECT 
	"totalWorkflowCount",
	"__KEY_root"
FROM JSON (wrap on) "root" PK "__KEY_root"
WITH CONNECTION (   
    URL "$(URL_path)",
    HTTPHEADER "Cookie" "$(session_id)"  

  )   ;

[Workflowcount]:
LOAD	[totalWorkflowCount] AS [totalWorkflowCount]
RESIDENT RestConnectorMasterTable
WHERE NOT IsNull([__KEY_root]);