4

I'm using the webcams.travel API from RapidAPI (link to API doc) and I've set everything up using browserify, unirest, node, require, etc.

The API response is in json and the Response Header is being output, but the Response Body is supposed to give me an object with webcams, but instead it shows as "undefined". This is my output now:

image of the console output

Is the problem in the parsing of the json, or does it have something to do with unirest? I'm thankful for any help.

Code in my app.js (which is the suggested request snippet from the API site):

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);
});
Grokify
  • 15,092
  • 6
  • 60
  • 81
scummtomte
  • 53
  • 8
  • Where is your code? Let's see that. Can't really say its a parsing error by guessing. – basic Dec 17 '18 at 19:19
  • Thanks for your comment. I've now added the code in the post. – scummtomte Dec 17 '18 at 19:21
  • Your code works fine? See this repl: https://repl.it/repls/YellowgreenLinenPython – basic Dec 17 '18 at 19:33
  • @basic Yes, the code is working fine in your example as well as on the RapidAPI web test endpoint-thing. But when I run the code locally in the browser, the body response is undefined, and I have no idea why (since the header response seems to work). – scummtomte Dec 17 '18 at 19:48
  • 1
    Hi, I’m the CTO of RapidAPI. You can contact support@rapidapi.com and our team will take care of you. Just a friendly suggestion, it is not the best idea to publish you token (X-RapidAPI-Key) here. – Andrey Bukati Dec 17 '18 at 22:12
  • Thanks Andrey, I've now sent a mail. – scummtomte Dec 18 '18 at 09:05
  • @basic, here's also the zipped project in its most minimal form, in case you or anyone else can see the problem: https://pomo.wetransfer.com/downloads/f4c22be2eb141119b9c383b0ffd5759e20181218110340/8cca35 – scummtomte Dec 18 '18 at 11:17

1 Answers1

1

Following up because I got interest—I eventually solved this issue when I encountered it with Imgur’s API by using the Fetch API instead of Unirest. There seems to be some issue with RapidAPI and Unirest, but when I contacted support they were unaware of any issues.

I recommend trying fetch() if you’re still encountering this.

Daniel G. Wilson
  • 14,955
  • 2
  • 32
  • 39
  • 1
    Weird, I concur with your finding,before reading this answer, I spent like 2 hours figuring out why unirest was not working. Thank you so much, fetch has always helped. – siddharthrc Sep 23 '19 at 02:41