Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
neena123
Partner - Creator
Partner - Creator

How to retrieve Access Token using REST?

Hello!

I am very new to APIs and using REST to connect to retrieve my data. I am absolutely lost on the process of setting up a connection. I have downloaded the Rest connector and I do know that in order to retrieve my data it requires a 2 step Oauth approach. What I have is the grant type, client id and client secret information as well as the URL to get my access token. But how do I start this? Any guidance is appreciated! 

2 Solutions

Accepted Solutions
asinha1991
Creator III
Creator III

You will have to get full documentation of the REST request(with request examples) from the team that maintain REST server or API support

there must be 2 url one to fetch access token(you pass client id and client secret as query parameter) and other to get data.

access token has to be passed in second url as query parameter or header( you will see these options when you try to create a connection)

In QlikView, I don't think you can pass parameters dynamically (as it might not support with clause). I use qliksense which supports dynamic passing. It depends on how long your access token remains valid. You can fetch it manually everytime using clients like chrome advanced rest connection and put it manually in your rest call to fetch data if it is valid for considerable time like a week or a month etc. You can also use some other programming language to fetch and store data somewhere if you are a developer.

An example( qliksense but should help you understand)

 

 

//To fetch token, FetchConnection is the name of REST connection with url of fetching token . You can generate query using create query wizard
LIB CONNECT TO 'FetchConnection';

response:
SQL SELECT
"token_type",

"access_token"
FROM JSON (wrap on) "root";

let access_token = peek('access_token', -1);
let token_type = peek('token_type', -1);
trace $(access_token);

 

//this is call to fetch data url but instead of creating connection, i am passing dynamic values using with which may not work in qlikview

RestConnectorMasterTable:
SQL SELECT
xyz
FROM CSV (header on, delimiter ",", quote """") "CSV_source"

WITH CONNECTION (
Url "urltofetchdata",
HTTPHEADER "Accept" "application/json;odata=verbose",
HTTPHEADER "Authorization" "$(token_type) $(access_token)")


;


I will have data in RestConnectorMasterTable:

This video will help you understand how to create connection and create query using rest connector

https://www.youtube.com/watch?v=oUKNk1IZMZQ

View solution in original post

Brett_Bleess
Former Employee
Former Employee

Neena, just ensuring you also did read through the Help on the REST Connector, it is pretty robust.  Here is a link to the section I think you need in this case, but I will paste the top level link below that as well, so you can see everything.

https://help.qlik.com/en-US/connectors/Subsystems/REST_connector_help/Content/Connectors_REST/Create...

https://help.qlik.com/en-US/connectors/Subsystems/REST_connector_help/Content/Connectors_REST/REST-c...

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.

View solution in original post

7 Replies
cavetroll
Contributor III
Contributor III

Since you are new to REST I would suggest learning how to connect to it and set everything up inside of postman (free application) at https://www.getpostman.com/downloads/
Once you get a handle on how to pull data from it, it should be plug and play (copy and paste) to use the qlik rest connector.
-Cavetroll
asinha1991
Creator III
Creator III

You will have to get full documentation of the REST request(with request examples) from the team that maintain REST server or API support

there must be 2 url one to fetch access token(you pass client id and client secret as query parameter) and other to get data.

access token has to be passed in second url as query parameter or header( you will see these options when you try to create a connection)

In QlikView, I don't think you can pass parameters dynamically (as it might not support with clause). I use qliksense which supports dynamic passing. It depends on how long your access token remains valid. You can fetch it manually everytime using clients like chrome advanced rest connection and put it manually in your rest call to fetch data if it is valid for considerable time like a week or a month etc. You can also use some other programming language to fetch and store data somewhere if you are a developer.

An example( qliksense but should help you understand)

 

 

//To fetch token, FetchConnection is the name of REST connection with url of fetching token . You can generate query using create query wizard
LIB CONNECT TO 'FetchConnection';

response:
SQL SELECT
"token_type",

"access_token"
FROM JSON (wrap on) "root";

let access_token = peek('access_token', -1);
let token_type = peek('token_type', -1);
trace $(access_token);

 

//this is call to fetch data url but instead of creating connection, i am passing dynamic values using with which may not work in qlikview

RestConnectorMasterTable:
SQL SELECT
xyz
FROM CSV (header on, delimiter ",", quote """") "CSV_source"

WITH CONNECTION (
Url "urltofetchdata",
HTTPHEADER "Accept" "application/json;odata=verbose",
HTTPHEADER "Authorization" "$(token_type) $(access_token)")


;


I will have data in RestConnectorMasterTable:

This video will help you understand how to create connection and create query using rest connector

https://www.youtube.com/watch?v=oUKNk1IZMZQ

neena123
Partner - Creator
Partner - Creator
Author

Thanks for your help. I did download postman and got my access token. But now where do I "copy and paste" in Qlikview? I am sure there is some type of script I would need to write. Since it is a 2 step process I will need to be able to automate my Access Token so that I don't need to manually do it ever time I want the data to refresh right? 

asinha1991
Creator III
Creator III

yes, you should automate it but I doubt it can be done in QlikView...in Qliksense they provide a way to pass dyanamic value.

For QlikView you need to add it as query header in your create connection (you can see that in the video)

 
 
Brett_Bleess
Former Employee
Former Employee

Neena, just ensuring you also did read through the Help on the REST Connector, it is pretty robust.  Here is a link to the section I think you need in this case, but I will paste the top level link below that as well, so you can see everything.

https://help.qlik.com/en-US/connectors/Subsystems/REST_connector_help/Content/Connectors_REST/Create...

https://help.qlik.com/en-US/connectors/Subsystems/REST_connector_help/Content/Connectors_REST/REST-c...

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
shalini
Contributor III
Contributor III

HI, 

I have a scenario where i need to access the auth token to authenticate an external application integrated with qlik app.   are you aware of an API to access the token from my external app backend server so that i can authenticate my app with the same credentials without having to provide a separate login page which breaks the user experience.

Ken_T
Specialist
Specialist

did anyone ever figure this out, or no?