Yahoo Weather API Not Being Able To Search Through Variables

221 Views Asked by At

Alright, so this sounds like a weird question. I am using yahoo weather API, and discord.js to make a weather command. I use YQL and WOIED to try to have someone enter in their place they want to search up. Here is the variable search:

const query = new YQL(`SELECT * FROM weather.forecast WHERE woeid in (SELECT woeid FROM geo.places(1) WHERE text= ${place})`)

When I use the variable input though, it does not work, and will give me this error:

Cannot read property 'results' of undefined

Now, when I manually input the place I want to see, it works. Here is what I mean:

const query = new YQL(`SELECT * FROM weather.forecast WHERE woeid in (SELECT woeid FROM geo.places(1) WHERE text= "Broomfield, Co")`)

Note that I have my main emphasis on the WHERE text = portion of each search query

Any help would be greatly appreciated!

2

There are 2 best solutions below

0
jaredkwright On BEST ANSWER

Unless the variable you are inserting has double quotes as part of the string, you are going to have to insert them yourself in the format string. For example:

const query = new YQL(`SELECT * FROM weather.forecast WHERE woeid in (SELECT woeid FROM geo.places(1) WHERE text= "${place}")`)
0
bluecereal On

It looks like there is something wrong with the place variable. You could try doing

console.log(`place: ${place}`);

before you initialize your query to see what's wrong with it. It could be improperly formatted (e.g. "Broomfield, Colorado"), or it could contain nothing at all.