Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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?
How do you get the token? For example is it HMAC? Is it retrieved from a POST call? etc.
Thanks for your reply,
It is retrieved through a POST call.
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]);