eapowertools-archive / qsaas

Unsupported - A wrapper for the Qlik Sense Enterprise SaaS APIs.
GNU General Public License v3.0
12 stars 0 forks source link

'/temp-contents/{id}' endpoint not working #5

Closed rbaranowskizpr closed 2 years ago

rbaranowskizpr commented 2 years ago

Hello,

the '/temp-contents/{id}' doesent't seem to work. I try to download the temp files but get error:

Exception: (400, '{"traceId":"000000000000000091142e92aab392d5","errors":[{"code":"TCS-002","title":"Improper request query","detail":"Improperly formatted query","meta":{"locale":"en-US","errorType":"Error","sourceErrors":"failed to parse incoming query: schema: invalid path \"limit\""}}]}\n')

My code below:

from qsaas.qsaas import Tenant import json

q = Tenant(config="./config.json")

apiresponse = q.post('apps/f7078a93-9ab3-45a1-92c9-894372fd5439/export', json.dumps({"NoData":True}))

apiresponsedheader = dict(apiresponse.headers)

fileid= apiresponsedheader['Location'].split("/api/v1/")[1]

print(fileid)

fileresponse = q.get(fileid)

fileresponse

danielpilla commented 2 years ago

Hi @rbaranowskizpr, There isn't a way to do this in qsaas entirely, yet. A wrapper function to download an app has been suggested, however. I will add it when I have the bandwidth. In the meantime, you can use a combination of qsaas and raw requests. Here is an example (note is saves the file to the current dir, you could add another param for that):

from qsaas.qsaas import Tenant
import requests

q = Tenant(config="config.json")

app_id = '9560d47e-fa03-4203-a26f-02e0425c4346'

def download_app(app_id, name, withData=False):
    global q
    noData = "false" if withData else "true"
    resp = q.post(f'apps/{app_id}/export', {}, params={"noData": noData})
    tempContents = resp.headers['location']

    r = requests.get(
        f"{q.tenant}{tempContents}", stream=True, headers=q.auth_header)
    with open(f"{name}.qvf", 'wb') as file:
        for chunk in r.iter_content(chunk_size=1024):
            file.write(chunk)

download_app(app_id, 'my_app2', withData=True)