Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content
Announcements
WEBINAR June 25, 2025: Build on Apache Iceberg with Qlik Open Lakehouse - REGISTER TODAY
cancel
Showing results for 
Search instead for 
Did you mean: 
vasilev
Creator
Creator

Uploading app trough REST API via Python script

Hello guys,

I am trying to upload a Qlik Sense app into the QMC with a python script using the REST API.

https://help.qlik.com/en-US/sense-developer/May2024/Subsystems/RepositoryServiceAPI/Content/Sense_Re...

 

I am using the following script:

 

import requests


requests.packages.urllib3.disable_warnings()

xrf = '1234567890123456'

#Set up necessary headers comma separated
headers = {
    'X-Qlik-Xrfkey': xrf,
    'X-Qlik-User': 'UserDirectory=INTERNAL;UserId=sa_repository',
    'Content-Type': 'application/vnd.qlik.sense.app'
}

#Set the endpoint URL

#Set up the certificate path
cert = ('C:/LocalUserData/Certificates/Sense TEST/client.pem', 'C:/LocalUserData/Certificates/Sense TEST/client_key.pem')


# Open file
with open("C:/Users/<user_id>/Downloads/ImportREST.qvf", "rb") as f:
    files = {'file': f.read()}

# Send the POST request
try:
    response = requests.request("POST", url, headers=headers, files=files, verify=False, cert=cert)
    response.raise_for_status()  # Raise an error for bad responses
    print('Upload successful!  Server responded with:', response.text)
except requests.exceptions.RequestException as err:
    print('Upload failed:', err)
 
 
After executing the script I am getting the error "500 Server Error: Internal Server Error for url: https://servername:4242/qrs/app/upload?name=ImportREST&Xrfkey=1234567890123456".
 
I tried to upload the same app with Postman and it worked perfectly. These are my settings in Postman.
 
vasilev_0-1716566038633.pngvasilev_1-1716566065689.pngvasilev_2-1716566087535.png

 

I am struggling all the day with this issue I have no idea what I am doing wrong in Python. Has anybody an idea what could be the problem with the script?

 

BR,

Rumen

Labels (2)
1 Solution

Accepted Solutions
Marc
Employee
Employee

https://github.com/clintcarr/qrspy/blob/d6950b4d746cbe99b88edbd830bfb9e923544f2d/qrspy.py#L794


def import_app(self, name, filename):
"""
Imports an application
:param name: Name of application to import
:param filename: Path and file of qvf
:returns: HTTP Status Code
"""
path = 'qrs/app/upload?name={0}'.format(name)
headers["Content-Type"] = "application/vnd.qlik.sense.app"
headers["Connection"] = "Keep-Alive"
with open(filename, 'rb') as app:
return self.post(path, app)

View solution in original post

5 Replies
Marc
Employee
Employee

https://github.com/clintcarr/qrspy/blob/d6950b4d746cbe99b88edbd830bfb9e923544f2d/qrspy.py#L794


def import_app(self, name, filename):
"""
Imports an application
:param name: Name of application to import
:param filename: Path and file of qvf
:returns: HTTP Status Code
"""
path = 'qrs/app/upload?name={0}'.format(name)
headers["Content-Type"] = "application/vnd.qlik.sense.app"
headers["Connection"] = "Keep-Alive"
with open(filename, 'rb') as app:
return self.post(path, app)

vasilev
Creator
Creator
Author

It works fine! Thank you @Marc 

Nareshgp
Contributor III
Contributor III

Hi @vasilev ,

what exactly you made changes in your code to get this worked as per Marc reply. 

could you please share the code which is working for you using python.

Thanks in advance

 

BR,

Naresh

Nareshgp
Contributor III
Contributor III

Hi @Marc ,

I am struggling to incorporate the above code with python to upload the Qlik Sense application. 

could you please help me with working code for this.

 

Thanks

Marc
Employee
Employee

if you check the link in my original post, 

you will see that the ReadMe has instructions on how to connect to your Qlik Sense Server 

Instantiate-the-connectqlik-class

Once you have the QRS class you can then use it to Import the apps with the import_app method, (just adapt the for loop for a single qvf rather than for each app in the dir)

Import-the-apps-in-a-folder-into-a-server