socrata / discuss

Discuss all the things!
https://dev.socrata.com
Apache License 2.0
10 stars 3 forks source link

[data.cdc.gov/8xkx-amqh] Is an API token required for a simple query? #142

Open SomervilleTom opened 3 years ago

SomervilleTom commented 3 years ago

API Docs: https://dev.socrata.com/foundry/data.cdc.gov/8xkx-amqh

I want to run a simple query once each day, collecting only a few columns.

I've tried (using wget) an example that collects just the date: wget "https://data.cdc.gov/resource/8xkx-amqh.json?$select=date"

The result is a 400:


--2021-07-08 12:18:56--  https://data.cdc.gov/resource/8xkx-amqh.json?=date
Resolving data.cdc.gov (data.cdc.gov)... 52.206.140.205, 52.206.68.26, 52.206.140.199
Connecting to data.cdc.gov (data.cdc.gov)|52.206.140.205|:443... connected.
HTTP request sent, awaiting response... 400 Bad Request
2021-07-08 12:18:56 ERROR 400: Bad Request.
```|

When I make the same request with no query string (`https://data.cdc.gov/resource/8xkx-amqh.json`), it works fine but I get the full dataset.

What am I missing?
andybloch commented 2 years ago

You need to url encode the '$' as '%24':

wget "https://data.cdc.gov/resource/8xkx-amqh.json?%24select=date"

That should work. In a browser address bar you might not have to do that. If your query includes spaces, those should be replaced with +, and other characters may need to be url encoded too.

SomervilleTom commented 2 years ago

Jeesh, I thought I had tried that (I experimented with many variants of URL encoding the query string).

Worked like a charm, thank you.

SomervilleTom commented 2 years ago

I apparently spoke to soon. While the query worked, it answered with only the data for today. I expected to get data for each (like the full URL).

Here's the query I used:

wget "https://data.cdc.gov/resource/8xkx-amqh.csv?%24select=date%2Cfips%2Crecip_state%2Crecip_county%2Cseries_complete_yes"

Here is the query that I've been using (that delivers all rows).

wget "https://data.cdc.gov/api/views/8xkx-amqh/rows.csv?accessType=DOWNLOAD"

I was expecting the today's query to answer the same number of rows but with only the specified fields.

While I've read through the documentation for socrata several times, I apparently missed the section(s) that explain this behavior.