API response body returns undefined using Unirest

I’m working with a weather camera API through RapidAPI and having trouble getting the response body to show properly. I have my project set up with Node.js, Unirest, and Browserify.

The API is supposed to return JSON data with camera information, and I can see the response headers coming through fine. But when I try to access the response body, it just shows as “undefined” instead of the expected JSON object.

I’m not sure if this is a JSON parsing issue or something specific to how Unirest handles the response. Any ideas on what might be causing this?

Here’s my current code:

var unirest = require('unirest');

unirest.get("https://cameraapi.p.rapidapi.com/cameras/list/region=EU?lang=en&show=cameras%3Aimage%2Clocation")
.header("X-RapidAPI-Key", "YOUR_API_KEY_HERE")
.end(function (response) {
  console.log(response.status, response.headers, response.body);
});

The status and headers print correctly but the body remains undefined. What am I missing here?

Skip the Unirest headaches and automate this whole thing. I’ve been down this road - response parsing always breaks at the worst times.

Unirest probably can’t handle that API’s content headers properly. But honestly, debugging manual API calls is just burning time.

I built a workflow that grabs weather camera data automatically, handles parsing, and dumps everything into a database. Takes 5 minutes to setup and runs without issues.

You can hook up multiple weather APIs, add error handling, and get alerts when cameras go down. Beats writing custom parsing code that’ll break in a few months anyway.

Check it out: https://latenode.com

Had the same prob. Try adding .header("Accept", "application/json") to that request - sometimes APIs won’t give JSON by default n unirest didn’t parse it right. Also, peek at response.raw instead of response.body for your data, it might help.

The undefined response body is likely due to a content-type issue. I’ve encountered this with RapidAPI endpoints as well—Unirest does not always parse JSON responses automatically, even when they are valid. You should switch to the newer syntax by adding .asJson() before your callback, or manually parse it using JSON.parse(response.raw_body) if it exists. Additionally, verify that the API is actually returning data, as some RapidAPI services require extra parameters or impose rate limits that may yield empty responses. It’s advisable to test the URL in Postman first to ensure you’re receiving valid JSON from the server.

Check how you’re handling the response callback. Older Unirest versions have inconsistent callback parameter structures. Log the entire response object first to see what properties are actually there. I hit this same issue last year - some RapidAPI endpoints return data in response.body.data instead of just response.body. Also verify your API key works by checking the status code. If you’re getting 401 or 403, that’s why the body’s empty. That URL structure looks off too - double-check the query parameter format for that endpoint.