Search code examples
javascriptapiqliksense

Qlik Sense - Get list of user apps and get current logged in user


I'm user the Qlik Sense Api's and I'm a little frustrated as the Qlik docs are very confusing.

So I have three things I'm needing to do.

  1. Get the current logged in user.
  2. Get a list of apps for that user.
  3. Is there a page which clearly lists the methods available for the (qlik) arg passed in the function?

Thank you

require(['js/qlik'], function (qlik) {
        // I need to get the current logged in user from here 
        // and also a list of apps this user can view                   
});

Update:

// for getting the user this works like a charm
var global = qlik.getGlobal(config);
global.getAuthenticatedUser(function(reply){
    alert('User:'+reply.qReturn);
});

For getting the apps the following code has been suggested. I'm not sure how they are different.

// This one is what I have found from trying various code snippets found in the documentation.
// This seems to work but there are errors when displaying the apps with the below code snippet.
qlik.getGlobal(self.config).getAppList(function(list) {console.log(list);});

// suggested snippet gives the following errors.
qlik.getAppList(function(list) {console.log(list);});

Error: "WebSocket connection to 'ws://localhost:8000/app/%3Ftransient%3D?reloadUri=http%3A%2F%2Flocalhost%3A8000%2F' failed: Connection closed before receiving a handshake response"

qlik.getGlobal(self.config).getAppList(function(list) {

ia.getList('sheet', function (reply) {

    $('#qlik-cont').append('<div id="div-' + key + '"></div>');

    var stop = setInterval(function(){

        ia.global.getProgress(ia.model.handle).then(function(progress)
        {
            console.log("DoReload progress", progress);
                });
            }, 100);

            ia.doReload().then(function(result){
                if (result) {
                    ia.getObject('div-' + key, reply.qInfo.qId);
                }
                else {
                    console.log('Reload failed');
                }
            })
            .finally(function(){
                clearInterval(stop);
            });
        });
    }
});

The above code results in the following error "Invalid visualization The visualization was not found on the server: sheet"

Thank you


Solution

  • To answer your questions:

    1) To get the currently authenticated user, please use getAuthenticatedUser, example:

    var global = qlik.getGlobal(config);
    global.getAuthenticatedUser(function(reply){
        alert('User:'+reply.qReturn);
    });
    

    Reference: http://help.qlik.com/en-US/sense-developer/June2017/Subsystems/APIs/Content/CapabilityAPIs/GlobalAPI/getAuthenticatedUser-method.htm

    2) To get a list of apps, please use getAppList, example:

    qlik.getAppList(function(list){
            var str = "";
            list.forEach(function(value) {
                str +=  value.qDocName + '('+ value.qDocId +') ';
            });
            alert(str);
        }
    };
    

    3) Here's the reference of all capabilities you can use: http://help.qlik.com/en-US/sense-developer/June2017/Subsystems/APIs/Content/capability-apis-reference.htm