Posting to Slack from Qlik Sense load scripts – web service style (part 2)

As the first version of the Sense-to-Slack integration required you to lower the Sense security level, it is probably not a good option for enterprise Sense users, for example.

Instead, let’s set up a small node.js web service, which exposes an API that we can call just like we can retrieve data from any web page in the load script.

There are a couple of pre-requisites:

  1. Node.js must be installed on the machine where Sense is running (or some other machine in your network – for sake of simplicity I assume it’s on the same machine). You also need to have the Node libraries Restify and Node-Slack installed.
  2. You also need Qlik’s REST connector, at least if you are to avoid some messy URL character encodings. More on that later.

Setting up the Node.js server

Create a directory where you will store your Node apps. C:\node or something similar – you decide what’s suitable on your system. Then, get the code for the node server from GitHub. The code is pretty basic (make sure to use your own Slack web hook URL):

var restify = require('restify');
var Slack = require('node-slack');

var slackWebhookURL = '<fill in your web hook URL from Slack>';
var slack = new Slack(slackWebhookURL);

function respondSlack(req, res, next) {
// console.log(req.params);

 text: req.params.msg,
 username: req.params.from_user,
 icon_emoji: req.params.emoji


var server = restify.createServer({
 name: 'SlackProxy'

server.use(restify.queryParser()); // Enable parsing of http parameters
server.get('/slack', respondSlack);

server.listen(8080, function() {
 console.log('%s listening at %s',, server.url);

Run the server:

C:\node\slack_proxy>node slack_proxy.js
SlackProxy listening at http://[::]:8080

Log Slack entries from Sense load script, using the REST connector

Connection to Slack proxy

Now, create a new Sense app to try out the notification. In that app, set up a new data connection using the REST connector:

With the new connection in place, use the rest connector to connect to the proxy, and let the REST connector generate the code for you.

Finally, add the “WITH CONNECTION”… statement to send in the actual data that should be passed on to Slack. A good thing here is that the REST connector handles encoding of special characters like space, # etc – no need to do that manually. Very nice!

The resulting load script looks something like this (your data connection names will differ, of course):


FROM JSON (wrap on) "root"
 QUERY "channel" "#general",
 QUERY "from_user" "SenseBot",
 QUERY "msg" "Posted from Sense",
 QUERY "emoji" ":smile:"

 [channel] AS [channel],
 [from_user] AS [from_user],
 [msg] AS [msg],
 [emoji] AS [emoji]
RESIDENT RestConnectorMasterTable;

DROP TABLE RestConnectorMasterTable;

Reload the app, and voila – in Slack we get this:

Slack message created by Sense load script

Mission accomplished.

Log Slack entries from Sense load script, using the FROM command

If you don’t want to use the REST connector, or don’t have it installed, there is another way of achieving the same result as above.

Your Sense load script will instead look something like this:

FROM [http://localhost:8080/slack?channel=%23general&from_user=SenseBot2&msg=Another%20message%20from%20Sense&emoji=:smile:]
(txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

Notice how we have to convert space, # and other “special” characters to their hex equivalents? You could write a small function that does this for you (don’t think Sense has any built in function for URL escaping – or?), but with the REST connector being so easy to use – that should be the preferred option for most people.

In this case we get a Slack message like this:

Slack message using FROM command



6 Replies to “Posting to Slack from Qlik Sense load scripts – web service style (part 2)”

  1. Hi,

    Thanks a lot for this great feature. It is working like a charm!

    Unfortunately, if I try to use the \n for a new line it doesn’t work. I created a message with two lines in a Qlik variable and that works.

    Any idea what to do to make it work?


    1. Hmm, I’d have to test that myself to verify what works.. You could try using a double-back-slash, i.e. \\n instead of \\.
      On some platforms you need to quote special characters like \, with a quoting character – which happens to be \ too…. Slightly confusing, yes.

  2. Indeed, thanks a lot! This is really cool!

    I installed all the requirements today so I had all the latest versions. I then had to make small changes to the code in order for it to work:

    text: req.query.msg,
    username: req.query.from_user,
    icon_emoji: req.query.emoji



  3. Thanks for sharing this info.

    What’s the purpose of the node.js proxy server? If you can do a HTTP GET or POST request from Qlik using the REST connector, why not do it directly to the Slack API server?

    Or is this the solution for your comment in your previous post where you couldn’t get it to work directly?

    1. You are absolutely right in that you can post to Slack simply by using the Qlik REST connector.
      And yes – the solution I drafted in that post comes from the days where the Qlik REST connector was limited in its features and functions.

      That said, there are some advantages to using a micro service for these kind of things.
      If the only thing you want to do is post the most basic messages to Teams for Slack, you can do that directly from the Qlik load script.

      But if you want to take full advantage of those IM tools’ formatting features, creating a chat bot etc – then you need to dive deeper into their APIs.
      And that’s NOT easily (not even a smart idea…) done in Qlik script.

      An example could be the reload failure notifications in the open source Butler tool (
      There you can choose between email, Slack and Teams notifications when reload tasks in Qlik Sense fails.
      You can choose between basic or advanced Slack/Teams notifications, where the basic ones are more or less one liners.

      The advanced notifications on the other hand use the Slack/Teams APIs to create richly formatted notifications like this:

Leave a Reply

Your email address will not be published.