carpediemus
carpediemus8mo ago

weatherapi problem

Trying to fetch weather data from weatherapi, the ai wrote me a code: import fetch from 'node-fetch'; export default async function fetchWeatherForecast({ cityName, apiKey }) { const url = https://api.weatherapi.com/v1/forecast.json?key={apiKey}&q={cityName}&days=3; const response = await fetch(url); const data = await response.json(); return data; } But i keep getting an error whenever i try to test the call. Running the url with the api key in the browser returns the results without an issue. {"error":{"message":"An error occurred while fetching: TypeError [ERR_INVALID_URL]: Invalid URL"},"label":"build node","message":"An error occurred while fetching: TypeError [ERR_INVALID_URL]: Invalid URL"} I am just starting out with buildship so any help would be appreciated.
6 Replies
Gaurav Chadha
Gaurav Chadha8mo ago
Hi @carpediemus Can you share your project via in-app support, attach a link to this discord post. Will fix it.
carpediemus
carpediemus8mo ago
Sent, thanks
Gaurav Chadha
Gaurav Chadha8mo ago
HI @carpediemus, you can try again by esting the individual node, the invalid url should be solved on your project.
carpediemus
carpediemus8mo ago
hi there , thanks for the update. Unfortunatly i keep getting an error: {"error":{"nodeId":"test-node-1707946936528","nodeName":"Validate URL and Fetch 3-Day Weather Forecast","stage":"building node","errorObject":{"errors":[{"id":"","location":null,"notes":[],"pluginName":"","text":"Failed to write to output file: close /usr/src/app/bucket/builtNodes/test-node-1707946936528/1708008594719.cjs: interrupted system call"}],"warnings":[]}},"buildId":"1708008594719"} now it keep saying that ,y api key is disabled, but when i run the url directly it works fine: https://api.weatherapi.com/v1/forecast.json?key=e6e9ccf035494de1b6f145150241502&q=rehovot&days=3 even when a code has a static value it tell me the API key was disabled, but if i run the same url in the browser it works fine. import fetch from 'node-fetch'; export default async function fetchWeatherForecast({ cityName, apiKey }) { const url = 'https://api.weatherapi.com/v1/forecast.json?key=e6e9ccf035494de1b6f145150241502&q=rehovot&days=3'; const response = await fetch(url); const data = await response.json(); return data; }
Gaurav Chadha
Gaurav Chadha8mo ago
It is an issue in the code: you are not using the apiKey after passing as parameter in the function. You'll require to pass it in the url as ${apiKey} query parameter, you use AI Generator for help here.
carpediemus
carpediemus8mo ago
Thank @Gaurav Chadha . Running the code with parameters keeps sending the "API key has been disabled." error. Any clue why it might be happening? { "error": { "code": 2008, "message": "API key has been disabled." } }