Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
adam_westhusing
Contributor II
Contributor II

QRS Export App without data

The documentation states that there is an option to skip data when exporting the app (/qrs/app/{id}/export/{token}?skipData={skipData}), however when I go to use the API, I'm receiving a Bad Request.

Additionally, when I query the API to get all of the endpoints (/qrs/about/api/description?extended=true), there is no such indication that this is possible.  These are the only options I see for export:

    "GET /qrs/app/{id}/export [resource=manual, bodytype=Void, returntype=Guid]"

    "DELETE /qrs/app/{id}/export/{token} [resource=manual, bodytype=Void, returntype=AppExportResponse]"

    "POST /qrs/app/{id}/export/{token} [resource=manual, bodytype=Void, returntype=AppExportResponse]"

Is there a way to export an app without data?  If that's not possible, is there an API to remove all data from an app and then I can export it after that call?

1 Solution

Accepted Solutions
Levi_Turner
Employee
Employee

Hey Adam,

Are you on Qlik Sense June 2018? Because the export without data option was first introduced there. Other builds will throw a 400 bad request response (because it is a bad request).

On Qlik Sense June 2018, this PowerShell code is running on my side:

$hdrs = @{}

$hdrs.Add("X-Qlik-Xrfkey","examplexrfkey123")

$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")

$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}

$body = '{}'

$Data = Get-Content C:\ProgramData\Qlik\Sense\Host.cfg

$FQDN = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($($Data)))

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'

$guid = [guid]::NewGuid()

$download = Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/App/c9fadcd3-20f5-434b-a0f8-a73e46943294/export/$($guid)?xrfkey=examplexrf..." -Method Post -Body $body -Headers $hdrs -ContentType 'application/json' -Certificate $cert

Invoke-RestMethod -Uri "https://$($FQDN):4242$($download.downloadPath)" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert |  Set-Content small.qvf -Encoding Ascii

Obviously the AppID will need adjusting for your environment.

View solution in original post

9 Replies
Levi_Turner
Employee
Employee

Hey Adam,

Are you on Qlik Sense June 2018? Because the export without data option was first introduced there. Other builds will throw a 400 bad request response (because it is a bad request).

On Qlik Sense June 2018, this PowerShell code is running on my side:

$hdrs = @{}

$hdrs.Add("X-Qlik-Xrfkey","examplexrfkey123")

$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")

$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}

$body = '{}'

$Data = Get-Content C:\ProgramData\Qlik\Sense\Host.cfg

$FQDN = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($($Data)))

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'

$guid = [guid]::NewGuid()

$download = Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/App/c9fadcd3-20f5-434b-a0f8-a73e46943294/export/$($guid)?xrfkey=examplexrf..." -Method Post -Body $body -Headers $hdrs -ContentType 'application/json' -Certificate $cert

Invoke-RestMethod -Uri "https://$($FQDN):4242$($download.downloadPath)" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert |  Set-Content small.qvf -Encoding Ascii

Obviously the AppID will need adjusting for your environment.

adam_westhusing
Contributor II
Contributor II
Author

Ah, understood.  I am not using June 2018.  I'm using April 2018.  That explains my response when I queried /qrs/about/api/description.

I still have not found a way to export an app without data via the QRS REST API, but I believe I have found a workaround using the Qlik Engine API.  ltu‌ if I get no other response, I'll mark your response as the correct answer because it explains why skipData was not working for export.

Levi_Turner
Employee
Employee

Well the functionality won't be present until 2018-06 so nothing is going to work on the QRS level until then. You _should_ be able to use the Engine API to open the app without data then save it, but I am light on the Engine API to be honest.

adam_westhusing
Contributor II
Contributor II
Author

That's exactly what I did.

analienx
Contributor III
Contributor III

Hi Adam, do you think you could share the code how you opened the app without data and saved it as a different app?

THank you!!

adam_westhusing
Contributor II
Contributor II
Author

Sure.

            // Dump data from app for export

            IAppIdentifier appID = this.location.AppWithId(qlikApp.id.ToString());

            using (IApp app = await this.location.AppAsync(appID, noVersionCheck: true, noData: true))

            {

                await app.DoSaveAsync();

            }

            // Export app

            Guid uuid = Guid.NewGuid();

            string exportEndpoint = "/qrs/app/" + qlikApp.id + "/export/" + uuid.ToString();

            QlikExportAppResponse response = JsonConvert.DeserializeObject<QlikExportAppResponse>(this.client.Post(exportEndpoint, ""));

            string downloadsFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "Downloads");

            string downloadPath = System.IO.Path.Combine(downloadsFolder, qlikApp.name + ".qvf");

            await Task.Run(() => this.client.GetFile(response.downloadPath, downloadPath));

The client is the Qlik REST Client (https://github.com/kolsrud/qlik_rest_sdk) created by yko

nsm1234567
Creator II
Creator II

I stumbled across this response while trying to do something similar and found it very helpful, however, I'm not sure if your Powerhsell script still works as is but running this against a Qliksense Server September 2018 instance, doing "|  Set-Content small.qvf -Encoding Ascii" actually corrupted the exported QVF.

I found that I instead just needed to do:  -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert -OutFile $appname

Running this with the -Outfile parameter gave me the QVF  I was looking for and I was then able to import this to the hub.

alexandru
Employee
Employee

On June 2019 version,  using PostMan or Restlet Chrome addon, you can use the following:

Step 1:

POST https://qlikserver:4242/qrs/app/9cdea0b7-ca81-43ac-89ba-3e2e3302243f/export/9cdea0b7-ca81-43ac-89ba-3e2e3302243f?xrfkey=uqFXwZ66CmQbX9K1

Adding to request header:

skipData={True}

The return message should be 201, with the temporary link to download the qvf file:

{
"exportToken": "9cdea0b7-ca81-43ac-89ba-3e2e3302243f",
"appId": "9cdea0b7-ca81-43ac-89ba-3e2e3302243f",
"downloadPath": "/tempcontent/efab1eca-e8ac-4ceb-8cda-9e30ec2484c8/FARS%20Reporting.qvf?serverNodeId=f1e0fea0-f44f-4781-8506-03bdb4f0d8a8",
"cancelled": false,
"schemaPath": "AppExportResponse"
}

Step 2:

GET https://qlikserver:4242/tempcontent/c61a2f4b-2b67-42b3-ac04-48b8772e9c98/FARS%20Reporting.qvf?server...

Add these parameter to the request header:

serverNodeId=f1e0fea0-f44f-4781-8506-03bdb4f0d8a8

 

I prefer Restlet since it's helping me when the header is wrong, with the 409 error return header that I can understand what to fix in the json contruct

2019-10-01 11_27_56-Qlik-API-POST-ExternalProgramTask - Restlet Client.png

jainisha
Partner - Contributor II
Partner - Contributor II

Can you provide GET method example? As for me post is working fine getting downloadPath but while calling GET method receives error as "The requested resource cannot be found"