Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
michael_botelho
Contributor
Contributor

Data Alerts in Mashup

Hello. I have been tasked with adding the functionality to create a data alert on a column in all table objects. I am not sure how to do this and the documentation isn't very thorough. I tried posting a payload to /api/v1/data-alerts with an existing api key, but am getting a console error 401 (unauthorized). I do not have admin access to the management console. Is there something in the management console that needs to be updated so I can make api calls to the qlik rest api? I tried making calls to several endpoints and all either error 401 or return html with Unauthorized text.

Labels (2)
4 Replies
DaveChannon
Employee
Employee

Hi @michael_botelho 

Could you share a little more context on what you're trying to achieve here? Are you building a web app/ mashup with custom components, or are you using nebula for the components and wish to add a context menu to it? Or is this within the Qlik Sense client experience, and you're creating an extension?

Regarding the 401, if you can create a data alert interactively, then you should be able to create one programmatically. Does your API key work when you do a GET to the data-alerts endpoint?

michael_botelho
Contributor
Contributor
Author

Hey @DaveChannon 

I am wanting to add this to our existing mashups that mostly use the qlik capability apis. They are fairly simple.  The task I was given was to replicate the data-alert functionality in the front end of the app (right-click, add data alert in context menu) in the actual mashup. To start I tried just adding a sample data alert with a payload copied from the network tab when creating a data alert in the qlik app. I get 401. I tried a GET request to list data alerts 401. I tried a few other random GET requests to different endpoints and mostly get 401 error, occasionally I get a response that is just html saying '401 Unauthorized'.  I am able to create data alerts interactively. What is interesting is if I use postman, I can successfully post a new data alert. However, copying the code from postman to my mashup gives me the same 401 error. I am not sure what the difference is between calling from postman vs browser other than that there is no origin in postman. I am trying to see if there is some admin related configuration that is preventing me from calling these endpoints. (the url I am calling from, differs from the url I am making requests to, but I get no CORS related erros)

DaveChannon
Employee
Employee

Hey @michael_botelho 

So I took the node code that I have from Postman and that ran within an app I have using the same API key I'm using in postman with no modifications.

401 would normally indicate that the auth isn't right. E.g. if I remove a character from my token, I'll get the 401. Are you absolutely certain you're passing the auth correctly? Working example below:

var https = require('follow-redirects').https;
var fs = require('fs');

var options = {
  'method': 'GET',
  'hostname': 'orchestration.eu.qlikcloud.com',
  'path': '/api/v1/data-alerts',
  'headers': {
    'Authorization': 'Bearer eyJhbGc...',
    'Content-type': 'application/json',
    'Accept': 'application/json'
  },
  'maxRedirects': 20
};

var req = https.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function (chunk) {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });

  res.on("error", function (error) {
    console.error(error);
  });
});

req.end();
michael_botelho
Contributor
Contributor
Author

Hello @DaveChannon ,

I have copied the code direclty out of postman and I get this error. You mentioned using node, have you tried making this call in the browser? That is what I am trying to accomplish.