Exporting an App using REST API in C# .NET
David Maurice Jan 9, 2017 12:49 AMHi everyone, we're setting up a small environment where I will be automating the transfer of Qlik Sense Apps to different engines on different servers. Using the APIs I've been able to Import, Publish and get a ticket for Exporting an app, but not been able to use the APIs to Export.
I'm probably missing something obvious, but it's not clear to me with the Export call:
How do I deal with the body of the request returned? I've written the content directly to the file system, but it's not a proper app when opened, so I'm not sure if I have to remove headers, decompress, or even look on the file system on the server or somewhere else (as you have to specify your path) to get the file export working. It looks like the text returned is almost a Qlik Sense App (comparing it with the original).
I've also got task triggering working in C# via this example (and got the other API calls working): Working with REST API to trigger reload tasks
My code is:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strServerName + @":4242/qrs/download/app/" + strAppID + "/" + strRequestGUID + "/" + strFilename + "?xrfkey=" + xrfkey); request.Method = "GET"; request.Accept = "application/vnd.qlik.sense.app"; request.Headers.Add("X-Qlik-xrfkey", xrfkey); request.Headers.Add("id", strAppID); // Add the certificate to the request and provide the user to execute as request.ClientCertificates.Add(SenseCert); request.Headers.Add("X-Qlik-User", strUserStringForQlik); //Send the request using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { using (Stream stream = response.GetResponseStream()) { //So at this point, we have a stream when put into raw text looks like // a Qlik Sense App, but is not a Qlik Sense app. using (StreamWriter sw = new StreamWriter(strFilename, false, Encoding.UTF8)) { StreamReader sr = new StreamReader(stream, Encoding.UTF8); //We write the data to a file here, but it won't load in Qlik Sense while (!sr.EndOfStream) { string strLinedata = sr.ReadLine(); sw.WriteLine(strLinedata); } } } }