Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hello everyone,
I would like to download the script from all my apps. I use NetSDK and Visual Studio for this. It works for a single defined app. However, when I iterate over the app list, I get the error message that the app is already open, although according to the console I am already at the next app.
My Code
using Qlik.Engine;
using Qlik.Sense.Client;
using System;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main(string[] args)
{
string serverUri = "https://xxxxxxx.com/";
string exportBasePath = @"C:Export\";
Directory.CreateDirectory(exportBasePath);
using (ILocation location = Qlik.Engine.Location.FromUri(new Uri(serverUri)))
{
location.AsNtlmUserViaProxy(certificateValidation: false);
try
{
using (IHub hub = location.Hub())
{
var apps = hub.GetAppList();
foreach (var app in apps)
{
Console.WriteLine($"App: {app.AppName}");
IApp appData = hub.OpenApp(app.AppId);
string script = appData.GetScript();
string scriptFilePath = Path.Combine(exportBasePath, $"{app.AppName}.txt");
File.WriteAllText(scriptFilePath, script);
Console.WriteLine($" -> Export");
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Fehler: {ex.Message}");
}
}
}
}
I would also like to put the different apps in a corresponding folder depending on their stream. It is supposed to work via the “GetAllInfos” function, but this no longer seems to exist. I am using SDK version 16.9
Thanks and best regards
Patrick
var exportBasePath = Directory.CreateDirectory(exportBasePath);
using (Qlik.Engine.ILocation location = Qlik.Engine.Location.FromUri(serverUri))
{
location.AsNtlmUserViaProxy(certificateValidation: false);
var qlikApps = location.GetAppIdentifiers();
foreach (var appIdentifier in qlikApps) {
try
{
Console.WriteLine($"App: {appIdentifier.AppName}");
var qeapp = location.App(appIdentifier, Qlik.Engine.Session.Random, false);
string script = qeapp.GetScript();
FileInfo scriptFilePath = new FileInfo(Path.Combine(exportBasePath.FullName, appIdentifier.AppId, $"{appIdentifier.AppName}.txt"));
scriptFilePath.Directory.Create();
File.WriteAllText(scriptFilePath.FullName, script);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
You should be able to get the stream for which an app has been published from the "Meta" property of the appIdentifiers. Here's an example printing the names and associated streams of all apps:
var appIds = location.GetAppIdentifiers();
foreach (var appId in appIds)
{
var streamDef = appId.Meta.Get<JObject>("stream");
var streamName = streamDef?["name"] ?? "<none>";
Console.WriteLine($"{appId.AppName} stream={streamName}");
}
var exportBasePath = Directory.CreateDirectory(exportBasePath);
using (Qlik.Engine.ILocation location = Qlik.Engine.Location.FromUri(serverUri))
{
location.AsNtlmUserViaProxy(certificateValidation: false);
var qlikApps = location.GetAppIdentifiers();
foreach (var appIdentifier in qlikApps) {
try
{
Console.WriteLine($"App: {appIdentifier.AppName}");
var qeapp = location.App(appIdentifier, Qlik.Engine.Session.Random, false);
string script = qeapp.GetScript();
FileInfo scriptFilePath = new FileInfo(Path.Combine(exportBasePath.FullName, appIdentifier.AppId, $"{appIdentifier.AppName}.txt"));
scriptFilePath.Directory.Create();
File.WriteAllText(scriptFilePath.FullName, script);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
}
Hi Marc,
thank you for your code. Is it possible to replace the AppID with the stream name as the folder name.
Thank you and best regards
Patrick
You should be able to get the stream for which an app has been published from the "Meta" property of the appIdentifiers. Here's an example printing the names and associated streams of all apps:
var appIds = location.GetAppIdentifiers();
foreach (var appId in appIds)
{
var streamDef = appId.Meta.Get<JObject>("stream");
var streamName = streamDef?["name"] ?? "<none>";
Console.WriteLine($"{appId.AppName} stream={streamName}");
}
Thank you and best regards
Patrick
Hi All,
Can this be done using Python and how to connect to Qlik Sense Engine API to extract the script? Currently, there is no Python SDK for Qlik Sense OnPrem.
Thanks.
How to connect a WebSocket connection via Python is covered in the Article https://community.qlik.com/t5/Official-Support-Articles/Qlik-Sense-call-Qlik-Sense-Engine-API-with-P...
which also has some examples of how to open the app and perform activities, however for you use case you would need to send the appropriate requests over the websocket to open the doc, then request the Script,
you can figure out what those are from the Engine API Explorer in dev-hub https://<qlikSenseServer>/dev-hub/engine-api-explorer (among other things you might want to do)
but the opendoc request would look similar to this
{
"jsonrpc": "2.0",
"id": 2,
"delta": true,
"result": {
"qReturn": {
"qType": "Doc",
"qHandle": 1,
"qGenericId": "b19b7875-1111-1111-1111-7c6d58377a22"
}
}
}
and the get script request.
{
"handle": 1,
"method": "GetScript",
"params": {}
}
Thanks @Marc for the details. Will check on the given inputs.