Can anyone share an example API call using CURL to retrieve historical data in CSV format for a date range or for the “last 24 hrs” ?
I’m struggling!
Can anyone share an example API call using CURL to retrieve historical data in CSV format for a date range or for the “last 24 hrs” ?
I’m struggling!
Here’s what I’m trying:
curl -X GET https://june2022.api.purpleair.com/v1/sensors/51921/history/csv -H "X-API-Key:XXXXX" "start_timestamp:2022-06-29T16:04:59Z end_timestamp:2022-06-30T16:04:59Z" "fields:pm2.5_atm_a%2C"
The result:
{
"api_version" : "V1.0.11-0.0.25",
"time_stamp" : 1657307039,
"error" : "MissingFieldsParameterError",
"description" : "Missing fields parameter."
}curl: (3) Port number ended with '-'
curl: (3) Port number ended with 'p'
Hi @ronswanson, your API call will need to look something like this:
curl -X GET "https://june2022.api.purpleair.com/v1/sensors/51921/history/csv?fields=pm2.5_atm_a&start_timestamp=2022-06-29T16:04:59Z&end_timestamp=2022-06-30T16:04:59Z" -H "X-API-Key:XXXXXX"
I do not believe you can pass query parameters the way you are doing so. You will need to include them in the URL. If you are sending multiple headers, I believe you will also need to have multiple ‘-H’. Lastly, the %2C from the fields should be removed.
Thank you this is very helpful to get me started!
Also, note that you do not need to specify both start and end timestamps. If you leave one out, the API will provide data for the maximum period before an end timestamp or after a start timestamp. If you leave both out, it will get the maximum period’s worth of data up to the current time.
That’s good to know. Is there any way to get just the last 24 hrs without specifying any dates?
Not at his time. We will also publish more details on the periods involved for each average soon.
One more question. If we are being asked to make requests no more than once per 10 minutes, is there any way to get multiple sensors’ data? I have 12 sensors that I’d like to retrieve history from, is this possible currently with the rate limits?
This is a great point and I’d like to get more clarification on it - I think the current suggestion is no more than once every 1-10 minutes. Currently in my test R scripts where I’m only trying to pull data from two sensors at a time, I have a 2 minute pause built into pulling each request. Once I get everything fully running, I’ll be looking at pulling data from at least 20 and up to 60 sensors at a time. I’d hope I wouldn’t run into firewall issues with requesting that amount of data.
Based on this prior comment it seems that querying groups of devices might be considered in future.