Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello,
I have been wrestling with the qrs api for the past few days to create a process for moving apps from one environment to another. Currently my only goal is to download an app & upload it back onto the hub with a different name - I seem to have trouble with the app format as it is not recognized. Any help? Below is my request (excuse the poor text formatting).
var https = require('https');
var fs = require('fs');
var targetApp = 'Sandbox'
var options = {
hostname: <server.name>,
port: 4242,
path: '/qrs/app?xrfkey=abcdefghijklmnop',
method: 'GET',
headers: {
'x-qlik-xrfkey' : 'abcdefghijklmnop',
'X-Qlik-User' : 'UserDirectory= INTERNAL; UserId= sa_repository'
},
key: fs.readFileSync("client_key.pem"),
cert: fs.readFileSync("client.pem"),
ca: fs.readFileSync("root.pem")
};
//get app list
https.get(options, function(res) {
console.log("Got response: " + res.statusCode);
var body = '';
res.on("data", function(chunk) {
body += chunk;
});
res.on("end", function() {
var appList = JSON.parse(body);
//find target app id
var targetAppId = '';
for(var i = 0;i < appList.length;i++){
if(targetApp == appList[i].name){
var targetAppId = appList[i].id;
//1st export step of target app
options.path = '/qrs/app/' + targetAppId + '/export/' + targetAppId + '?skipData=false&xrfkey=abcdefghijklmnop';
options.method = 'POST';
https.get(options, function(resp) {
console.log("Got response (Export1): " + resp.statusCode);
var exportjson = '';
resp.on("data", function(chunk) {
exportjson += chunk;
});
resp.on('end',function(){
var exportobj = JSON.parse(exportjson);
//2nd export step on target app
options.path = exportobj.downloadPath + '&xrfkey=abcdefghijklmnop';
options.method = 'GET';
https.get(options, function(re) {
console.log('Got response (Export2): ' + re.statusCode);
var rawApp = '';
re.on('data',function(chunk){
rawApp += chunk;
});
re.on('end',function(){
//upload app with new name Test. This is where it fails with a 500 error due to invalid format
options.headers['Content-Type'] = 'application/vnd.qlik.sense.app';
options.path = '/qrs/app/upload?name=Test&xrfkey=abcdefghijklmnop';
options.method = 'POST';
var uploadApp = https.request(options,function(response){
console.log('Got response (upload): ' + response.statusCode);
response.on('data',function(chunk){console.log('body: ' + chunk);});
});
uploadApp.write(rawApp );
uploadApp.end();
//fs.writeFile(targetApp + '.qvf',rawApp,function (err){
// console.log(err);
//});
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
}
}
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});