I’m currently using the webcams.travel API via RapidAPI in my project, set up with Browserify, Unirest, and Node.js.
While I can see the Response Header and the API response comes in JSON format, I am encountering an issue where the Response Body is supposed to present an object with webcam details, but it returns as ‘undefined’. Here’s the output I am dealing with:
Could the issue stem from how the JSON is being parsed, or is it related to Unirest itself? I’d appreciate any guidance on this matter.
Here’s a snippet from my app.js that follows the recommended request format from the API documentation:
var unirest = require('unirest');
unirest.get("https://webcamstravel.p.rapidapi.com/webcams/list/continent=AN?lang=en&show=webcams%3Aimage%2Clocation")
.header("X-RapidAPI-Key", "MY_RAPID_API_KEY")
.end(function (result) {
console.log(result.status, result.headers, result.body);
});
your callback parameter looks off. change result
to response
in your .end() function - unirest expects a different naming convention. also, check if continent=AN actually returns data. antarctica probably doesn’t have many webcams lol
I’ve hit this Unirest issue before - it’s usually the callback structure. Your syntax looks fine, but add some error handling to see what’s going on:
.end(function (response) {
if (response.error) {
console.log('Error:', response.error);
} else {
console.log('Status:', response.status);
console.log('Body:', response.body);
}
});
Also check your API key permissions in the RapidAPI dashboard. Sometimes the key authenticates but doesn’t have subscription access to return actual data - you’ll get undefined body even with a 200 status.
That undefined body issue with RapidAPI and Unirest is usually bad header parsing. Your X-RapidAPI-Key looks fine, but you’re missing the X-RapidAPI-Host header - most RapidAPI endpoints need it. Add .header("X-RapidAPI-Host", "webcamstravel.p.rapidapi.com")
to your request chain. Had the exact same problem last month and this fixed it right away. Without the host header, the API gateway can’t route your request properly even though authentication works, so you get empty responses despite good status codes.