project_cryptoverse
project_cryptoverse copied to clipboard
bing news api not working
i am getting a bad request error and it is not fetching any data
/search?q=${newsCategory}&safeSearch=Off&textFormat=Raw&freshness=Day&count=${count}
use this on cryptoNewsApi.js and keep the base the url const baseUrl = "https://bing-news-search1.p.rapidapi.com/news";
My news section wouldn't work at all until I skipped ahead and used useState, it has been confusing.
I've skipped ahead to add useState, reconfigured my query to
/search?q=${newsCategory}&safeSearch=Off&textFormat=Raw&freshness=Day&count=${count}
and I'm still getting
GET https://bing-news-search1.p.rapidapi.com/news/search?q=[object%20Object]&safeSearch=Off&textFormat=Raw&freshness=Day&count=undefined 400 (Bad Request)
At least my error changed from 404 to a 400. I've been stuck on this for hours, any help would be greatly appreciated.
GET https://bing-news-search1.p.rapidapi.com/news/search?q=[object%20Object]&safeSearch=Off&textFormat=Raw&freshness=Day&count=undefined 400 (Bad Request)
In the above request newsCategory
is of type string, but I can see it has got transformed into something like object%20Object
, and count
is undefined.
My Opinion:
- Check whether the parameters
newsCategory
andcount
which is passed has valid value.
Here Check inside news.jsx I passed -> const {data:cryptoNews} = useGetCryptoNewsQuery({type:'CryptoCurrency',count:10})
and inside cryptoNewsApi query builder I did ->
query: (category) => createRequest(/search?q=${category.type}&safeSearch=Off&textFormat=Raw&freshness=Day&count=${category.count}
);
Passed whole object with props from news.jsx and just fetched it inside Builder; Easy Peasy Problem Solved;
Hope it helps because its working in my project like this and i came across same problem too.
Thank you both.