Qlik Community

Ask a Question

Qlik Catalog

Discussion Board for collaboration on Qlik Catalog

cancel
Showing results for 
Search instead for 
Did you mean: 
brandon-ao
Contributor
Contributor

Authenticating with Qlik Data Catalyst REST API

I'm trying to connect to the API for Qlik Data Catalyst with PowerShell. The API documentation provides everything I need to make a call. In this attempt I am trying to use the the GET method, GET/source/v1/getSources. When I make the request, I get a successful response. However the content of the response is HTML: it appears that the request is not valid because it is the HTML of the login page. I noticed in the documentation it does not provide the method for providing credentials. I've tried encoding them in the header to no avail. Here is an example of the script I am running (with server removed):

$header = @{'Accept' = 'application/json'}
$uri = "http://SERVER:8080/podium/source/v1/getSources?type=EXTERNAL&count=500&sortAttr=name&sortDir=ASC"
Invoke-WebRequest -Uri $uri -Method Get -Headers $header

According to the curl example provided in the documentation, this is all that is needed. I assume that we somehow need to authenticate a user through this request because of the false positive response. Please advise how to proceed.

Labels (1)
1 Solution

Accepted Solutions
jrenwa144
Partner
Partner

Hi Brandon

My understanding is that you are writing a powershell script to get a source/entity details. In that case, first we need to establish a 'session' by creating a 'cookie file' and use that cookie file in subsequent API calls via curl. Below is an example - syntax is specific to Linux, but i am sure it shouldn't be much different for powershell as well.

cd /working_directory_where_u_want_to_create_cookie_files/

curl -v -s -c ./cookie-jar-j.txt --data 'j_username=user_name@domain&j_passwordplain_or_encyrpted_pwd' 'http://URL:8080/podium/j_spring_security_check'

#Once the above is created use in subsequent calls. Example below to import a prepare object from Dev to PROD (or any other environment)

cmd="curl -s -b ./cookie-jar-j.txt -X POST 'http://URL:8080/podium/metadataImport/v2/upload/Workflows' -F 'file=@${import_file_name}'"

Just FYI - One more common pitfall is, the account used to execute REST commands via script should have ADMIN access on the target object (source/entity/connector etc) Else it would return ambiguous results.

Let me know for any further questions.

Regards

Jitender Renwa

View solution in original post

3 Replies
jrenwa144
Partner
Partner

Hi Brandon

My understanding is that you are writing a powershell script to get a source/entity details. In that case, first we need to establish a 'session' by creating a 'cookie file' and use that cookie file in subsequent API calls via curl. Below is an example - syntax is specific to Linux, but i am sure it shouldn't be much different for powershell as well.

cd /working_directory_where_u_want_to_create_cookie_files/

curl -v -s -c ./cookie-jar-j.txt --data 'j_username=user_name@domain&j_passwordplain_or_encyrpted_pwd' 'http://URL:8080/podium/j_spring_security_check'

#Once the above is created use in subsequent calls. Example below to import a prepare object from Dev to PROD (or any other environment)

cmd="curl -s -b ./cookie-jar-j.txt -X POST 'http://URL:8080/podium/metadataImport/v2/upload/Workflows' -F 'file=@${import_file_name}'"

Just FYI - One more common pitfall is, the account used to execute REST commands via script should have ADMIN access on the target object (source/entity/connector etc) Else it would return ambiguous results.

Let me know for any further questions.

Regards

Jitender Renwa

View solution in original post

jrenwa144
Partner
Partner

Hi Brandon

Can you confirm if you were able to resolve the issue? 

Regards

Jitender Renwa

iulihardt
Partner
Partner

Does it keep working?

Im tryng do it, but my postman return:
'Could not verify the provided CSRF token because your session was not found.'

 

iulihardt_0-1618867400532.png