COVID-19 data

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

9.8 / 10

Latency

62ms

Service Level

100%

Back to All Discussions

API call error

avatar
LauraLeeLee
a year ago

I’m receiving error when the API is called of “You are not subscribed to this API”, when indeed I am subscriped and have API key for it. The free version.

React project, have the API key in * .env* and retrieving it with* process.env*

What may be causing the issue?

Thank you for your assistance
Lee

avatar
Gramzivi commented a year ago

See that you follow this example: https://github.com/Sourcerers/covid19-api/blob/master/examples/javascript/GetLatestTotalsFetch.js
I see you had 3 successful requests in last week. Also, can you send full request (masking your API key), maybe there is some error in request structure?

avatar
LauraLeeLee commented a year ago

Thank you for your response.

I had success with requests last month and before…no problem with the calls, and with using this structure.
I took a pause from the code and returned to it.
It didn’t work for me this week at all, no successful requests on my end, I’d either get the ‘too many requests’ or the 'you are not subscribed to this API" message, no data.

Thank you for your assistance.

Here is my request…again same structure as before when it did work, I haven’t changed anything with it.

fetchCovid = async (country) => {
    const API_KEY = process.env.REACT_APP_COUNTRIES_API_KEY;
    const response = await fetch(
      `https://covid-19-data.p.rapidapi.com/country?format=json&name=${country}`,
      {
        'method': 'GET',
        'headers': {
          'x-rapidapi-host': 'covid-19-data.p.rapidapi.com',
          'x-rapidapi-key': 'API_KEY',
        }
      }
    )
    .then(response => response.json()
    ).then(data => {
      console.log("fetchCovd:", data);
      this.setState({apiData: [...this.state.apiData, data]});
      if(this.state.apiData.length > 0) {
      }
      return data;
    })
      .catch(err => {
        console.log(err);
    });
  }

*** UPDATE
I restructured the call to have it structured as per your indication to follow the example.

Same thing occurs, message of"You are not subscribed to this API"

avatar
LauraLeeLee commented a year ago

with my code above, if I plug the api-key directly into the call, the call works, retrieves the data.
That would be the 3 successful calls this week…4 counting today.

However I don’t want the api key in my code, I have it in the .env file.

 const API_KEY = process.env.REACT_APP_COUNTRIES_API_KEY;
    console.log(API_KEY);
    console.log(process.env.REACT_APP_COUNTRIES_API_KEY);

Both log the api-key from the .env file correctly.

But when I have ‘API_KEY’ for the value in the call, it fails, renders message "You are not subscribed to this API"
I’m failing to see why the variable of the api key when applied in the call doesn’t work, especially when it did before. Problem occurred this week.

Thank you,
Lee

avatar
LauraLeeLee commented a year ago

RESOLVED

For anyone else looking.

As I said, it was something I was overlooking.
In my .env file where I have the api key, at the end of the creation of the REACT_APP variable-- i had a semi colon at the end-- this was causing the issue with my key.

Works now.

Join in the discussion - add comment below:

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