Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
deep2021
Creator III
Creator III

Qlik sense Rest API issue - Internal server error.

Hi All,

 

I am trying to connect Rest API.

I am able to fetch tokens and data successfully.

 

But now I need to fetch token dynamically, so that I am passing the vales in variables.

 

I am using the code as per below,

Variable-

vToken =''Token value

vAPI_Link = 'Passing the API link from where we need to fetch the data'

 

Condition in load data statement.

 

FROM CSV (header on, delimiter ",", quote """") "CSV_source"
WITH CONNECTION (URL "$(vAPI_Link)",
HTTPHEADER "accept" "text/csv",
HTTPHEADER "Authorization" "Bearer $(vToken)"
);

 

However, I am getting an error as per the below,

deep2021_0-1673552156139.png

 

 

Can you please suggest on this

Labels (1)
8 Replies
Frank_S
Support
Support

Perhaps one of these might help..

 

https://community.qlik.com/t5/Official-Support-Articles/How-to-approach-Error-500-Internal-server-er...

https://community.qlik.com/t5/Connectivity-Data-Prep/Internal-Server-Error-500-using-REST-Connector-...

 

Kind regards...

Please remember hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
NadiaB
Support
Support

Hi @deep2021 

Are you saying that if you configure the REST connection it works but if you add the WITH CONNECTION  to make it dynamic it fails ? 

I did a quick thest as follows and it worked for me: 

Variables:

set vAPI_Link= 'https://<mytenant>.us.qlikcloud.com/api/v1/users';
set vToken = '<mytoken>';

Connection details:

WITH CONNECTION (URL "$(vAPI_Link)",
HTTPHEADER "Authorization" "Bearer $(vToken)"
);

Could it be that one of the values from the variables is incorrect?

Maybe you can test without variables first to verify the values are correct and then replace one by one the variables. 

Hope it helps!

Don't forget to mark as "Solution Accepted" the comment that resolves the question/issue. #ngm
deep2021
Creator III
Creator III
Author

Hi @NadiaB 

I can access the token successfully and able to fetch in the variable.

Below is the snapshot for the same,

deep2021_0-1673559762909.png

 

But in the second part while accessing the data I do not know where it is going wrong.

 

We are using Qliksense on prem.

I am not getting the below link,

set vAPI_Link= 'https://<mytenant>.us.qlikcloud.com/api/v1/users';

For fetching the data I am using the link like below,

vAPI_Link = link that I used in Postman.

and below is the snap for connection string, that I am using,

 

deep2021_0-1673560989247.png

 

 

Thanks,

Deep

 

NadiaB
Support
Support

Hi @deep2021 

I would suggest to test with the REST connector alone first, use the preview option to get the query and execute it, after that works fine then start making changes. 

The picture doesn't show much to troubleshoot, other option would be to test from Postman and verify the values that are passed are correct. 

500 is a generic error, you would need to get the response and the descriptive error to see what is missing, probably Postman will generate a more descriptive error if you test with it . 

Hope it helps. 

Don't forget to mark as "Solution Accepted" the comment that resolves the question/issue. #ngm
deep2021
Creator III
Creator III
Author

Hi,

 

In Postman and in qlik I am able to fetch the data successfully

 

In Postman I used below parameters and same I used in qlik,

Token URL-

deep2021_0-1673565824775.png

Body URL to fetch Token info-

deep2021_1-1673565880375.png

URL to fetch Data and values that I passed highlighted in yellow-

deep2021_2-1673566010313.png

 

The same parameters are also working fine in qlik but while passing these values in variables and in automations it throws an error.

Thanks

 

 

 

 

deep2021
Creator III
Creator III
Author

Hi,

 

After passing the token value in variable it is working fine.

 

I am using variable like below,

LET vToken ='Token Value'

But whenevr I am trying to retrive token value from code,

it is showing me the below error,

deep2021_0-1673836645277.png

 

Could you please suggest me on this.

 

I am using the below code,

LET vToken_API = 'Conn string name';


/* Token Generation Sub Routine Code */
SUB Get_Token

LIB CONNECT TO '$(vToken_API)';

RestConnectorMasterTable:
SQL SELECT
"access_token",
"expires_in",
"scope",
"jti",
"token_type",
"refresh_token"
FROM JSON (wrap on) "root";

TOKEN:
LOAD
[access_token],
[expires_in],
[scope],
[jti],
[token_type],
[refresh_token]
RESIDENT RestConnectorMasterTable;

DROP TABLE RestConnectorMasterTable;

let vToken = Peek('access_token',0,'TOKEN');

//TRACE token=[$(vToken)];
TRACE token=$(vToken);

Drop Table TOKEN;

ENDSUB


Call Get_Token

 

Thanks

NadiaB
Support
Support

Hi @deep2021 

It's hard to analyze without having the actual connection to test against, the following post has a document that describes step by step how to accomplish what you are looking for:

https://community.qlik.com/t5/Qlik-Sense-Documents/Handling-Refresh-Tokens-with-the-Qlik-REST-Connec...

Hope it helps!

Don't forget to mark as "Solution Accepted" the comment that resolves the question/issue. #ngm
deep2021
Creator III
Creator III
Author

Hi,

 

Now I am able to fetch the data. Can you please suggest how to use paging in qlik to fetch a number of files that holds data from rest API?

 

I have head endpoint to get total count of files. For paging I need to skip some parameters ,and limitation is that I can fetch only 100000 records in one request.

Can you please share the example?

 

 

Thanks