Visual Crossing Weather

GRATIS CON POSSIBILITÀ DI UPGRADE
Da Visual Crossing Corporation | Aggiornamento לפני 4 ימים | Weather
Popolarità

9.8 / 10

Latenza

91ms

Livello di servizio

100%

Health Check

N/A

Torna a tutte le discussioni

Code example returning "undefined" in node app

Rapid account: Ajaen 4
ajaen4
hace 4 años

Hi!

I am trying to run the code snippet provided in my own app but instead of returning the same data its returning in the Rapid API web, I am getting an “undefined” object in the response. I have done this same thing with other APIs and it has worked properly.

The code I am using is the following:

var unirest = require(“unirest”);

var req = unirest(“GET”, “https://visual-crossing-weather.p.rapidapi.com/history”);

req.query({
“dayStartTime”: “8%3A00%3A00”,
“dayEndTime”: “20%3A00%3A00”,
“startDateTime”: “2019-01-01T00%3A00%3A00”,
“aggregateHours”: “24”,
“location”: “Berlin DE”,
“endDateTime”: “2020-01-11T00%3A00%3A00”,
“unitGroup”: “metric”
});

req.headers({
“x-rapidapi-host”: “visual-crossing-weather.p.rapidapi.com”,
“x-rapidapi-key”: “61a80f6c51msh8f57ee1e788e646p12608ajsn504e05a1388b”
});

req.end(function (res) {
if (res.error) throw new Error(res.error);

console.log(res.body);

});

Thank you for your help!

Rapid account: Ajaen 4
ajaen4 Commented hace 4 años

Hi again,
I have also tried running the request in postman and I get the response just fine. I have introduced a breakpoint in my node js app and this is the structure of the object returned by the request:
destroyed: (…)
readableHighWaterMark: (…)
_readableState: ReadableState {objectMode: false, highWaterMark: 16384, buffer: BufferList, length: 0, pipes: null, …}
readable: false
_events: {end: Array(2), error: Array(2), close: Array(2)}
_eventsCount: 3
_maxListeners: undefined
_mode: "fetch"
headers: {access-control-allow-credentials: “true”, access-control-allow-headers: “X-Requested-With, Content-Type, X-Codingpedia”, access-control-allow-methods: “GET, POST, DELETE, PUT”, access-control-allow-origin: “", cache-control: “no-cache,no-transform”, …}
rawHeaders: (32) [“access-control-allow-credentials”, “true”, “access-control-allow-headers”, “X-Requested-With, Content-Type, X-Codingpedia”, “access-control-allow-methods”, “GET, POST, DELETE, PUT”, “access-control-allow-origin”, "
”, “cache-control”, “no-cache,no-transform”, “connection”, “keep-alive”, “content-encoding”, “gzip”, “content-length”, “84”, “content-type”, “text/plain; charset=UTF-8”, “date”, “Sun, 12 Jan 2020 11:58:11 GMT”, “server”, “RapidAPI-1.0.32”, “x-powered-by”, “Visual Crossing Map Services”, “x-rapidapi-region”, “AWS - eu-central-1”, “x-rapidapi-version”, “1.0.32”, “x-ratelimit-requests-limit”, “500”, “x-ratelimit-requests-remaining”, “446”]
trailers: {}
rawTrailers: []
_fetchResponse: Response {type: “cors”, url: “https://visual-crossing-weather.p.rapidapi.com/his…Time=2020-01-11T00%3A00%3A00&unitGroup=metric”, redirected: false, status: 200, ok: true, …}
url: "https://visual-crossing-weather.p.rapidapi.com/history?dayStartTime=8%3A00%3A00&dayEndTime=20%3A00%3A00&startDateTime=2019-01-01T00%3A00%3A00&aggregateHours=24&location=Berlin DE&endDateTime=2020-01-11T00%3A00%3A00&unitGroup=metric"
statusCode: 200
statusMessage: "OK"
request: Request {_events: {…}, _eventsCount: 6, _maxListeners: undefined, method: “GET”, headers: {…}, …}
toJSON: ƒ responseToJSON()
caseless: Caseless {dict: {…}}
setEncoding: ƒ (type)
on: ƒ (type, next)
body: undefined
code: 200
status: 200
statusType: 2
info: false
ok: true
clientError: false
serverError: false
error: false
created: false
accepted: false
nonAuthoritativeInformation: false
noContent: false
resetContent: false
partialContent: false
multiStatus: false
alreadyReported: false
imUsed: false
multipleChoices: false
movedPermanently: false
found: false
seeOther: false
notModified: false
useProxy: false
temporaryRedirect: false
permanentRedirect: false
badRequest: false
unauthorized: false
paymentRequired: false
forbidden: false
notFound: false
methodNotAllowed: false
notAcceptable: false
proxyAuthenticationRequired: false
requestTimeout: false
conflict: false
gone: false
lengthRequired: false
preconditionFailed: false
requestEntityTooLarge: false
uriTooLong: false
unsupportedMediaType: false
rangeNotSatisfiable: false
expectationFailed: false
misdirectedRequest: false
unprocessableEntity: false
locked: false
failedDependency: false
upgradeRequired: false
preconditionRequired: false
tooManyRequests: false
requestHeaderFieldsTooLarge: false
internalServerError: false
notImplemented: false
badGateway: false
serviceUnavailable: false
gatewayTimeout: false
httpVersionNotSupported: false
variantAlsoNegotiates: false
insufficientStorage: false
loopDetected: false
notExtended: false
cookies: {}
cookie: ƒ (name)
raw_body: “”

As you can see, the body is still “undefinned”. I hope you can help me with this issue!

Regards

Rapid account: Ajaen 4
ajaen4 Commented hace 4 años

Hi, this is the information I get from the headers: access-control-allow-credentials: “true” access-control-allow-headers: “X-Requested-With, Content-Type, X-Codingpedia” access-control-allow-methods: “GET, POST, DELETE, PUT” access-control-allow-origin: “*” cache-control: “no-cache,no-transform” connection: “keep-alive” content-encoding: “gzip” content-length: “84” content-type: “text/plain; charset=UTF-8” date: “Sat, 11 Jan 2020 17:32:40 GMT” server: “RapidAPI-1.0.32” x-powered-by: “Visual Crossing Map Services” x-rapidapi-region: “AWS - eu-central-1” x-rapidapi-version: “1.0.32” x-ratelimit-requests-limit: “500” x-ratelimit-requests-remaining: “456”

Thanks for your help!

Rapid account: Awigmore
awigmore Commented hace 4 años

Thank you for your question.

I’ve tested your query in Postman and I receive results successfully.

Do you receive any additional information in the response headers that might indicate any additional information?

Thanks
Andrew

Partecipa alla discussione - aggiungi un commento di seguito:

Accedi/Iscriviti per pubblicare nuovi commenti