0

I try to make an API call with Node Js. My Goal is to get the current state of my Phillips hue light.

But i always get an error message: SyntaxError: Unexpected token u in JSON at position 0 I searched the web but couldn't find a solution to solve the problem and i don't understand what this error message means.

here is the code i use to make the call( don't worry "username" is just a place holder).

const request = require('request');
request('https://192.168.1.10/api/<username>/lights/', function (error, response, body) {

        var huelights = JSON.parse(body)
        console.log(huelieghts);

});
  • 2
    Look at the value you get - log it. If it cannot be parsed, then it's not valid JSON. Since it says that `u` at position zero is wrong, it means the first character of what you get is `u` instead of `{` or `[` or `"` or a number or `n` (for `null`). As a guess, I'd say you are getting `undefined` - starts with a `u` and it's a common enough string. But it might also be an error message like `unable to complete request` or something along those lines. At any rate, without knowing what your data is, it's very hard to actually help – VLAZ Oct 06 '20 at 19:26
  • Doubt your hue bridge has an SSL certificate. Try making your request using `http` instead of `https` – miknik Oct 06 '20 at 20:36

0 Answers0