Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
gal_polak
Creator
Creator

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)"

 

1 Solution

Accepted Solutions
gal_polak
Creator
Creator
Author

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
Stoyan_Terziev
Partner - Creator III
Partner - Creator III

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
Creator
Creator
Author

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"

Stoyan_Terziev
Partner - Creator III
Partner - Creator III

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
Creator
Creator
Author

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?
Stoyan_Terziev
Partner - Creator III
Partner - Creator III

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
Creator
Creator
Author

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!