Skip to main content

Design

The Design blog is all about product and Qlik solutions, such as scripting, data modeling, visual design, extensions, best practices, and more!

Ouadie
Employee
Employee

I’m always on the lookout for a tool that would make my life easier as a developer. Qlik-cli is a great asset to have in your toolbox when working with Qlik Sense SaaS. As its name suggests, it is a command line interface that lets you tap into Qlik’s published APIs and take advantage of the full power and possibilities of Qlik Cloud.

Being able to perform any administrative task from the command line can be very attractive for developers or system administrators who, for one, are used to dealing with cloud platforms via a cli, but also just want to access certain tools quickly without going through the management console graphical interface especially when trying to execute tasks in bulk or automate certain workflows.

So whether you are looking to run tasks or reloads, check on those reloads, move apps between environments, manage user access, or make updates at a large scale, qlik-cli is the right tool for that.

You can check out this recent blog post for a great introduction to the qlik-cli to learn about what it is and walk through the installation process to get up and running quickly: https://community.qlik.com/t5/Qlik-Design-Blog/Using-Qlik-cli-to-automate-workflows/ba-p/1943319

How does it works:

Once you’ve installed qlik-cli on your machine, you will need to grab your API Key from the Qlik Cloud tenant and create and configure a context from the command line to authenticate to Qlik Sense SaaS.

You can always view contexts if you happen to have multiple tenants or users via the "qlik context ls" command, and switch between them using "qlik context use <context-name>"

1.png

With qlik-cli’s built-in documentation, it’s very intuitive to see see which commands and flags you can use by adding --help to any command.

For instance qlik app --help will return the following:

2.png

What are some of the things you can use qlik-cli for:

A quick and easy example to show how easy it is to perform certain tasks with qlik-cli is to create an app, add a script and reload it:

 

qlik app create --attributes-name cli-testapp -q
qlik app script set <path-to-script> --app <appid>
qlik reload create --appId <appid>

 

3.png

That’s it! Running just 3 lines is all it takes to have an app ready for use.

4.png

But what if we wanted to create 10 apps instead of one?

Easy, all we got to do is wrap that same command we used above (qlik app create —attributes-name <name>) in a shell script “for” loop.

 

$appIds = @()
function appExists {
	param([String] $appName)
	$result = qlik item ls --resourceType app --name $appName | ConvertFrom-Json
	return $result[0].resourceId
}

For ($i=0; i -lt 10; $i++) {
	$name = "qlik-cli-app-$i"
	$app = appExists -appName $name
  if(!$app) {
		$app = qlik app create --attributes-name $name -q | Out-String
	}
	$appIds += $app
}

return $appIds

 

5.png

You can view a more detailed tutorial on qlik.dev: https://qlik.dev/tutorials/creating-and-deleting-apps-in-bulk-with-qlik-cli 

A good idea then is to maybe create a space and move all these apps to it with a few commands such as: “qlik space create” and “qlik app space update

You can also do some basic task chaining by using a function that runs against a JSON object containing task name, app id and status. This process can be especially helpful when wanting to execute a reload upon the completion status of a preceding reload.

Here is a tutorial that walks you through doing just that: https://qlik.dev/tutorials/task-chaining-with-qlik-cli 

Another great application of the qlik-cli for folks who are moving away from Qlik Sense Enterprise Client-Managed to Qlik Cloud, is to use it for migration. By leveraging basic PowerShell scripts and qlik-cli commands, you can facilitate and speed up a process that would otherwise be tedious. You can find more information about the whole process here . Take a look at the PowerShell scripts (download and extract the “Qlik Cloud migration tools” zip file) to see qlik-cli commands in action for inspiration.

I hope this post helped you get a sense of how powerful yet simple qlik-cli can be when it’s used alongside shell scripting to access and unlock the full potential of Qlik Cloud APIs.