Qlik Community

Qlik Connectors Discussions

Discussion Board for collaboration regarding Qlik Connectors.

gal_polak
New Contributor III

How to connect to API through the script

Hi all, 

I have an API that i need to connect to, and i know i can use the REST connector. 

but i need more flexibility for example:

i need to connect to the following api: https://api.game.com/usergroups?apikey='asdasdjlkascass2'

but need to change the apikey that is being sent dynamically

OR

change the header that is being sent, 

how can i do that? 

 

i thought that maybe i will have some kind of an option from the script editor to write something like this:

CUSTOM CONNECT "http://api.game.com/usergroup?apikey=$(KEY)"

 

Labels (2)
1 Solution

Accepted Solutions
gal_polak
New Contributor III

Re: How to connect to API through the script

This is very creative and i like it 🙂 

unfortunately it is not working.

but i found a way to change the headers:

 
 

 Annotation 2019-11-14 171752.png

 

and it will be good enough for now. 

 

thx for all your help! 

View solution in original post

6 Replies
Partner
Partner

Re: How to connect to API through the script

Hi Gal,

 

Basically the question is if you need to authenticate or not. If not - you can connect to as if you are loading internet file.

That's straight-forward with QV and quite tricky but still naively possible in QS.

 

If you can drop the URL in the browser and that fetches the information you need (basically scraping it),  you can write the code with a bit of help.

But if you need to parse headers with token for authentication you need to check the Qlik REST connector.

 

I hope that helps!

 

Kind regards,

S.T.

gal_polak
New Contributor III

Re: How to connect to API through the script

My problem is that i need to authenticate, 

i have multipal URL (apis) each one of theme have different api key, 

so i need some kind of a way to change the path when i use the "CONNECT"

Partner
Partner

Re: How to connect to API through the script

Hi Gal,

 

We didn't clarify if this is Qlik View or Qlik Sense?

I think once you generate your "CONNECT" or LIB: statement, you can use variables to modify certain paths in it.

Still if you need to authenticate, I don't think you can bypass using REST connector. Do you have it installed?

 

Kind regards,
S.T.

gal_polak
New Contributor III

Re: How to connect to API through the script

Sorry,
It's Qlik Sense
and yes i have it stored.

and i created the connector,
so as i said, another option is i can change the header of the connector dynamically,
is it possible? can you write a short example maybe?
Partner
Partner

Re: How to connect to API through the script

Hi Gal,

 

Using the same connection and dynamically changing the header is not possible with native QS functionality to my knowledge.

I don't have a reliable test connection to play with so I can't be sure this success is legitimate (actually I'm quite sure it is not):

image.png

But for the sake of science, you can give it a shot and let's check what is happening. 

The request field says:
$(=vTest)

 

Kind regards,

S.T.

gal_polak
New Contributor III

Re: How to connect to API through the script

This is very creative and i like it 🙂 

unfortunately it is not working.

but i found a way to change the headers:

 
 

 Annotation 2019-11-14 171752.png

 

and it will be good enough for now. 

 

thx for all your help! 

View solution in original post