Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
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

2 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