Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Beauty_Fades
Partner - Contributor
Partner - Contributor

QIX JSON API Authentication

Good evening,

I've been developing a wrapper tool that streamlines the Qlik Engine JSON API calls within a Python library. All features work as intended for my local apps.

However, we want to expand the library to work on the SaaS version of Qlik, that is, I want to execute the commands from the JSON API in an app that is hosted on a tenant in the cloud.

I first tried working with the REST API, but it is far from ideal and I find the documentation lacking. I then stumbled upon the QIX API (https://qlik.dev/apis/json-rpc/qix#docs) which seemed to be what I was after: being able to execute the JSON commands in an app that is in the cloud. Is this correct?

 

I then proceeded to attempt a connection using the Python Websockets library, but I keep getting authentication errors even following the procedures explained in QIX's documentation.

A Python test code is as follows:

 

 

 

import websocket

api_key = 'eyJhbGciOiJFUzM4NCIsImtpZCI6ImNkOWI3MzU2LWI5YzAtNDYwMi05MzY3LTMyOWEzNTljNmE2MCIsInR5cCI6IkpXVCJ9.eyJzdWJUeXBlIjoidXNlciIsInRlbmFudElkIjoiSlg3bWE2eTRrd0syUHhrQXgzajJKalpMWUZJa2ZibjMiLCJqdGkiOiJjZDliNzM1Ni1iOWMwLTQ2MDItOTM2Ny0zMjlhMzU5YzZhNjAiLCJhdWQiOiJxbGlrLmFwaSIsImlzcyI6InFsaWsuYXBpL2FwaS1rZXlzIiwic3ViIjoieklfR3paeWJqTi1tRUlQVnZxd2ZGUm5jU25DMzhJMTMifQ.1yHY6guEfAi2PgNz5NDEUzYadJ7lW1LZRMt63QNzvOSguDYH2fnt0j04dXOnxGoHKqGj-C7Da6IHN3Hv7cLvKbqA9Pin3qLSdDA6TA4wrL3MkZ7o7hHgP8GGGFlBTe39'  # API key generated in Profile > API Keys
authHeader = {'Authorization': 'Bearer ' + api_key}
host = 'wss://<my-tenant>.us.qlikcloud.com/app/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'

websocket.enableTrace(True)
ws = websocket.WebSocket()
ws.connect(host, header=authHeader)

 

 

 

Where <my-tenant> is where I put my tenant's alias hostname and the xxx's is my app's ID.

However, when the code is run, I still get a "401 Unauthorized" error message, as follows:

Beauty_Fades_0-1624034355491.png

Has anyone succeded in this? Must I use JWT Token instead of an API key? How do I properly authenticate?

Any help is appreciated, thanks!

 

 

Labels (1)
  • SaaS

1 Solution

Accepted Solutions
Beauty_Fades
Partner - Contributor
Partner - Contributor
Author

Hello, thanks for the info!

Although, I've been able to authenticate properly using the following piece of code:

import websocket
import json

api_key = 'eyJhbGciOiJFUzM4NCIsImtpZCI6ImNkOWI3MzU2LWI5YzAtNDYwMi05MzY3LTMyOWEzNTljNmE2MCIsInR5cCI6IkpXVCJ9.eyJzdWJUeXBlIjoidXNlciIsInRlbmFudElkIjoiSlg3bWE2eTRrd0syUHhrQXgzajJKalpMWUZJa2ZibjMiLCJqdGkiOiJjZDliNzM1Ni1iOWMwLTQ2MDItOTM2Ny0zMjlhMzU5YzZhNjAiLCJhdWQiOiJxbGlrLmFwaSIsImlzcyI6InFsaWsuYXBpL2FwaS1rZXlzIiwic3ViIjoieklfR3paeWJqTi1tRUlQVnZxd2ZGUm5jU25DMzhJMTMifQ.1yHY6guEfAi2PgNz5NDEUzYadJ7lW1LZRMt63QNzvOSguDYH2fnt0j04dXOnxGoHKqGj-C7Da6IHN3Hv7cLvKbqA9Pin3qLSdDA6TA4wrL3MkZ7o7hHgP8GGGFlBTe39'
authHeader = {'Authorization': 'Bearer ' + api_key}
host = 'wss://<my-tenant>.us.qlikcloud.com/app/5078a285-39f8-4bd1-8b1b-351d6cef77ea/'

ws = websocket.WebSocket()
ws.connect(host, header=authHeader,
           origin='https://<my-tenant>.us.qlikcloud.com')
print(ws.recv())

 

 

The problem was that the default protocol used in Pythons websocket library was http, and Qlik doesn't like that, so changing to htpps fixed it.

If anyone else finds this problem, that's the solution that worked.

View solution in original post

2 Replies
PadmaPriya
Support
Support

Hello @Beauty_Fades 

 

Please refer to the below article:

Connecting to the Qlik Engine JSON API ‒ Qlik Sense for developers

 

Thanks,

Padma Priya

Help users find answers! Don't forget to mark a solution that worked for you! If already marked, give it a thumbs up!
Beauty_Fades
Partner - Contributor
Partner - Contributor
Author

Hello, thanks for the info!

Although, I've been able to authenticate properly using the following piece of code:

import websocket
import json

api_key = 'eyJhbGciOiJFUzM4NCIsImtpZCI6ImNkOWI3MzU2LWI5YzAtNDYwMi05MzY3LTMyOWEzNTljNmE2MCIsInR5cCI6IkpXVCJ9.eyJzdWJUeXBlIjoidXNlciIsInRlbmFudElkIjoiSlg3bWE2eTRrd0syUHhrQXgzajJKalpMWUZJa2ZibjMiLCJqdGkiOiJjZDliNzM1Ni1iOWMwLTQ2MDItOTM2Ny0zMjlhMzU5YzZhNjAiLCJhdWQiOiJxbGlrLmFwaSIsImlzcyI6InFsaWsuYXBpL2FwaS1rZXlzIiwic3ViIjoieklfR3paeWJqTi1tRUlQVnZxd2ZGUm5jU25DMzhJMTMifQ.1yHY6guEfAi2PgNz5NDEUzYadJ7lW1LZRMt63QNzvOSguDYH2fnt0j04dXOnxGoHKqGj-C7Da6IHN3Hv7cLvKbqA9Pin3qLSdDA6TA4wrL3MkZ7o7hHgP8GGGFlBTe39'
authHeader = {'Authorization': 'Bearer ' + api_key}
host = 'wss://<my-tenant>.us.qlikcloud.com/app/5078a285-39f8-4bd1-8b1b-351d6cef77ea/'

ws = websocket.WebSocket()
ws.connect(host, header=authHeader,
           origin='https://<my-tenant>.us.qlikcloud.com')
print(ws.recv())

 

 

The problem was that the default protocol used in Pythons websocket library was http, and Qlik doesn't like that, so changing to htpps fixed it.

If anyone else finds this problem, that's the solution that worked.