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

Bad Exported file (call export api in qlik sense)

I export an app with these commands by PowerShell but when I try to open it in Qlik Sense desktop it says: "unsupported file format"

$hdrs = @{}
$hdrs.Add("X-Qlik-xrfkey","1234567890123456")
$hdrs.Add("X-Qlik-User","UserDirectory=XXX;UserId=XXXXX")
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}

$t = "22cde6c8-30b7-11ea-978f-2e728ce88125"
$url = "https://XXXXXXXXXX:4242/qrs/app/b2febd3f-eb7a-4783-bbbe-ac700468f39f/export/"+$t+"?skipData=True&xrfkey=1234567890123456"
$downloadPath = (Invoke-RestMethod -Uri $url -Method POST -Headers $hdrs -Certificate $cert).downloadPath


$url = "https://XXXXXXXXX:4242"+$downloadPath+"?&xrfkey=1234567890123456"
$file = Invoke-RestMethod -Uri $url -Method GET -Headers $hdrs -Certificate $cert
$file | Out-File c:\TestFolder\new2.qvf

Labels (3)
1 Solution

Accepted Solutions
Levi_Turner
Employee
Employee

If you used code I wrote, apologies 😀. This is running for me:

 

$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' 
$app = Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/full?filter=(name eq 'Random Data')&xrfkey=examplexrfkey123" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert
$exporttoken = Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/App/$($app.id)/export/6f9e5622-7306-4b00-9da2-15b132cf7984?xrfkey=examplexrfkey123&skipdata=true" -Method Post -Body $body -Headers $hdrs -ContentType 'application/json' -Certificate $cert
Invoke-RestMethod -Uri "https://$($FQDN):4242$($exporttoken.downloadPath)" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert -OutFile "$($app.name).qvf"

 

View solution in original post

6 Replies
Levi_Turner
Employee
Employee

If you used code I wrote, apologies 😀. This is running for me:

 

$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' 
$app = Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/full?filter=(name eq 'Random Data')&xrfkey=examplexrfkey123" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert
$exporttoken = Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/App/$($app.id)/export/6f9e5622-7306-4b00-9da2-15b132cf7984?xrfkey=examplexrfkey123&skipdata=true" -Method Post -Body $body -Headers $hdrs -ContentType 'application/json' -Certificate $cert
Invoke-RestMethod -Uri "https://$($FQDN):4242$($exporttoken.downloadPath)" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert -OutFile "$($app.name).qvf"

 

parviz_asoodehfard
Contributor III
Contributor III
Author

Would you please say I Should have this file by default? 

C:\ProgramData\Qlik\Sense\Host.cfg

Or should I generate by myself? if yes, what should I write inside it? 

And Can I ask where it will be saved?

Levi_Turner
Employee
Employee

That is the base64 encrypted file which lists the hostname for the Qlik site. The code is written to be run on the server but dynamically connect no matter what Qlik is installed as. If you know the hostname, you can statically define is a variable in the PowerShell code on your end.

parviz_asoodehfard
Contributor III
Contributor III
Author

Thank you. my problem solved. your code is great.

and the main problem was about putting values in variable so if I write the file like your command it will be solve.

Invoke-RestMethod -Uri $url -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert -OutFile $output

 
parviz_asoodehfard
Contributor III
Contributor III
Author

I found this:

https://github.com/levi-turner/QlikSenseScripts

It is great. But I can't find any file for "import". Do you have any sample for import?

I wrote this but it has 400 (bad request) error

 

$Body = @{
filename="test_import.qvf"
} | ConvertTo-Json

$url = "https://XXX:4242/qrs/app/import?name=test_import&xrfkey=1234567890123456"
$response = Invoke-RestMethod -Uri $url -Method POST -Headers $hdrs -Certificate $cert -Body $Body -ContentType 'application/json'
$response

Levi_Turner
Employee
Employee

Please create a separate thread for this ask.