COVID-19 data

FREEMIUM
Verified
By Sourcerers | Updated 3 months ago | Data
Popularity

9.8 / 10

Latency

57ms

Service Level

100%

Back to All Discussions

Problem with getting API data using arguments set dynamically

avatar
lauraleerdh
a year ago

Hello,

I am building a function to grab the getDataByCountryCode, but want to do so dynamically so I can grab and display data for any country and date entered.

`https://covid-19-data.p.rapidapi.com/report/country/code?format=json&date-format=YYYY-MM-DD&date=2020-04-01&code=usa`,
`https://covid-19-data.p.rapidapi.com/report/country/code?format=json&date-format=YYYY-MM-DD&date=${date}&code=${country}`,

The 1st line will render all the data for the fixed date and the fixed country including the info for their provinces.
The 2nd line renders the data for the proper country-- but doesn’t provide any provinces.
****Note, I am not running both of those together, swapped them out.

I’ve used the dynamic arguments in another call using only country/country code - no date…end it works as it should, it returns all the data for that country
https://covid-19-data.p.rapidapi.com/country?format=json&name=${country}

I’m not seeing the why it doesn’t work with doing the same with the api for dailyReportByCountryCode

Any thoughts?

this is the full code for fetching dailyReportByCountryCode:

async function fetchCovidStates(date, country) {
	const response = await fetch(
		`https://covid-19-data.p.rapidapi.com/report/country/code?format=json&date-format=YYYY-MM-DD&date=${date}&code=${country}`,
		{
			method: 'GET',
			headers: {
				'x-rapidapi-host': 'covid-19-data.p.rapidapi.com',
				'x-rapidapi-key': '1978ddeb10msh1004486a6040eefp1d080ejsnf92e9b1ba7d7',
			},
		}
	);
	const results = await response.json();
	return results;
}

async function fetchAndDisplayState(date, country) {
	const data = await fetchCovidStates(date, country);

	displayStateData(data);
}

this is the call with the daily date entered dynamically and the country entered in per the call:

const today = new Date(); 
const todayDate = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
setTimeout(function() {
	fetchAndDisplayState(todayDate, 'usa')
}, 3000);

Any thoughts to where my error is with this api when I have it working with the api getLatestCountryDataByName?

Thank you,
Lee

avatar
Gramzivi commented a year ago

We have currently errors on daily report endpoints (I hope we will fix it till the end of the week)

avatar
lauraleerdh commented a year ago

Thank you.
I’ve also noted that when coding in a date to select, not all dates render data. Some dates render 0. Not sure if that error has also occurred for you or is a result of what you are all working on.

Thank you for the work you do.

Join in the discussion - add comment below:

Login / Signup to post new comments
Rating: 3.2 - Votes: 13