#736 NHaystack with N4.7

Michael Brothers Fri 20 Sep

Hello all,

I am new to project haystack and I have a few questions. I am attempting to draw data out of a Niagara station (N4.7) and I am able to get a 200 status and login with this code using NodeJs.

const auth = require('@skyfoundry/haystack-auth');

var logMe = new auth.AuthClientContext("", "admin", "Admin12345", true);

logMe.login(function (headers) {
       logMe.sendReq(logMe.prepare(), "GET", "about", (res) => {console.log(res)})},
        function (msg) {console.log("Failed: " + msg);});

With the console.log(res) message I get a really huge object in return, and if i console log res.statusCode i get 200. I know this is registering in Niagara because in the application director I get this message every time i execute the code, just as it does in the browser: FINE [17:25:22 20-Sep-19 CDT][nhaystack] onAbout My question is, how would i go about parsing the response body? I get the ZINC grid in the browser, but I am stuck on how to parse that data from the sendReq(). I am using the node-haystack-auth module and would appreciate any response given.

Thank you

Brian Frank Fri 20 Sep

If you are using JavaScript, then you are probably going to find parsing the data in JSON easier. You can ask for the data in the format of your choice via the "Accept" HTTP header - see content negotiation. I am not 100% sure Niagara supports JSON, but pretty sure it does.

Michael Brothers Fri 20 Sep

I do believe it does. When I do the formats op it does send back application/json. I guess the easiest thing would be to res.json() or use body-parser? A question, would a res.body return undefined when getting a 200 status code in certain situations? Or is it because the content-type is incorrect?

Login or Signup to reply.