I’m new to using the purple air API and am trying to access historical data in a python script. My ultimate goal is to collect data from about 30 sensors over a year long period. I keep getting errors related to having an invalid API key/ payment required when I try to access sensor data. (I’ve tried some simple code to access sensor data as a test). I’m confused about the following:
- I haven’t really figured out the API points system. I read that I needed to add the points to a specific project, so I did that in Purple Air Develop. However, I’m not sure how I can access the points in that project in the python script.
- I’ve also read that I need approval to access historical endpoints. How do I obtain approval for that?
Thanks in advance for any insight!
Hi, @Avery_Parks, to answer your questions:
API keys are linked to a specific project. In the API keys tab on the develop.purpleair.com website, you can either create new API keys which are linked to a project, or edit existing keys and change the project they’re linked to. After the keys are linked to a project with points, they should be able to retrieve data without the error you are receiving. Details on adding points to your develop account can be found here: New API Dashboard.
Historical endpoints used to require approval up until the release of the develop site. If you created an account on the develop site yourself, you should have access to the historical endpoints with any new API keys created. Old API keys will still need to be granted access through us. If this is the case, send an email to us with your API keys at firstname.lastname@example.org.
Also as an additional note, getting data from the historical endpoints on the API has a 2 point base cost per request, as opposed to 1 point for the real-time endpoints. Every field retrieved requires the same amount of points however. Further details on API pricing are available in this article: API Pricing.
Thanks so much for this response @Josh_PurpleAir! I’m still a bit confused about accessing the points in python. When I’m building a request in python, I’m creating a url. Should the url somehow call the specific project in order to access the points? Or should the points just become accessible once they are linked to a project?
The url you’re building doesn’t need to reference projects at all. Having the API key included is all that’s needed for points to be deducted.
So you’ll just need to ensure the project the API key is linked to has points added to it. I hope this answers your questions clearly.
I understand, thanks so much for your help!