UKHSA-Internal/coronavirus-dashboard

Intermittent 400 errors calling the API

Closed this issue · 7 comments

Describe the bug
When calling the API, I keep getting 400 errors intermittently. I tested this out using Postman as well.

To Reproduce

  1. Do axios.get("https://api.coronavirus.data.gov.uk/v1/data") or fetch the endpoint on Postman repeatedly
  2. See error sometimes: response: "Invalid Query: the query is either empty or does not conform to the correct pattern. See the API documentations for additional information."

Expected behaviour
API always returns 200.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Mac
  • Browser Brave
  • Version 1.27

Smartphone (please complete the following information):

  • Device: iPhone 11
  • OS: iOS 14.7
  • Browser Brave
  • Version 14.7

Additional context
I'm trying to use this in this notebook: https://observablehq.com/@bluprince13/india-uk-covid-dashboard

You can see that it errors out there.

What's the exact API endpoint?

All APIs are working normally, otherwise you wouldn't be able to see the website.

I did consider that I may be getting throttled.

However, according to https://coronavirus.data.gov.uk/details/developers-guide#get-responses, if the requests were throttled, it should be returning 429 rather than 400.

I did consider that I may be getting throttled.

However, according to https://coronavirus.data.gov.uk/details/developers-guide#get-responses, if the requests were throttled, it should be returning 429 rather than 400.

You get a 429 if the request is throttled, which is very unlikely in APIv1. It has a very large quota.

What's the exact API endpoint?

https://api.coronavirus.data.gov.uk/v1/data

That's not a correct query though. You need to specify what you need.

See the developer's guide to learn about the API and query constructs, or use the download feature underneath the cards to get prepped endpoints.

That's not a correct query though. You need to specify what you need.

Oh right. So, how come it does work sometimes then?

I will try to be more specific and see if the API returns 200 more consistently.

That endpoint has and will never work.

It did work for me intermittently which is what confused me.

or use the download feature underneath the cards to get prepped endpoints

This helped me a lot! For anyone else who stumbles upon this, the cards on say https://coronavirus.data.gov.uk/details/cases have a download button that lets you download as JSON and takes you to the correct endpoint.