WXforum.net

Weather Station Hardware => Air Quality Sensors => Topic started by: saratogaWX on May 27, 2022, 01:01:41 PM

Title: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: saratogaWX on May 27, 2022, 01:01:41 PM
It appears they shut off the old queries like http://www.purpleair.com/json?show=4299 and now redirect to a server that won't respond to the query.

https://community.purpleair.com/t/discontinuation-of-the-json-and-data-json-urls/713 says
Quote
adrian
13h

After a few years of grace period, we are now redirecting these two URLs (www.purpleair.com/json and www.purpleair.com/data.json ) to a server that will not respond.

Please contact us if you have any questions or need any help getting going on our new API, at https://api.purpleair.com .

Sigh.. I've sent an email to request a READ key, and will rework my scripts to use it instead.  Meanwhile, the realtime query script(s) are very broken.. no data available.

For weather software developers that support realtime queries, they'll have to obtain keys and rewrite that portion of their software.
Grumble.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: waiukuweather on May 27, 2022, 02:52:19 PM
WD already has option to use purple air api luckily
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 27, 2022, 03:10:14 PM
Where do you request the API key?  I'm not seeing it readily.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 27, 2022, 03:13:37 PM
Looks like just their regular "Contact us" page is to be used.
https://www2.purpleair.com/pages/contact-us
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: Forever on May 27, 2022, 03:22:40 PM
WD already has option to use purple air api luckily
It's does but after entering my API key my graph is still flat lined. I think the graph is linked to the old method and not the new one.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 27, 2022, 03:53:25 PM
For the PHP script, I had the two sensorida and sensoridb.  Do I use the a value for Weather Display sensor number?

I got a read key, so I'm part way there I think.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: saratogaWX on May 27, 2022, 08:13:51 PM
I've reworked the purpleair-inc.php script to use the new API.  Seems to be working on my page now.

They were fairly fast in providing an API key, but stunningly, the process was via email...  The FAQ on their site needs to be changed now that the old method is turned off.

Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: waiukuweather on May 28, 2022, 02:54:11 AM
re WD, it should still be graphing OK
what shows in file

airqualityapi.txt

also though WD can get data via local IP (if your purple air sensor is connected to your LAN)
in the file airquality.txt
is there the data
pm2.5_aqi":
and if so, is that giving the correct aqi value
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 28, 2022, 11:50:01 AM
In the old script, there was sensorida and sensoridb.  Are these the same for the new script?  Or where do I find it?
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: saratogaWX on May 28, 2022, 11:53:22 AM
Yes, the sensorids haven't changed with the new API.  Mine was 4299,4300 and remains that for the new API.

The API returns stats, stats_a, stats_b now so you only have to query the primary (a) sensor to get the (b) sensor data too.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 28, 2022, 11:58:18 AM
Yeah, that's what I did, I'm getting no data.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 28, 2022, 12:01:04 PM
re WD, it should still be graphing OK
what shows in file

airqualityapi.txt

also though WD can get data via local IP (if your purple air sensor is connected to your LAN)
in the file airquality.txt
is there the data
pm2.5_aqi":
and if so, is that giving the correct aqi value
here is the latest file I had.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 28, 2022, 12:05:09 PM
 [ You are not allowed to view attachments ]
re WD, it should still be graphing OK
what shows in file

airqualityapi.txt

Here are my settings.  What's odd is when I do a test of the top one, I now get an error.  I never used to.  But after the error, it will show the numbers anyway.
I un-checked the "Use local data for 1.0 and 10.0 PM size data", just to see if the lower api part will work now.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: saratogaWX on May 28, 2022, 12:29:57 PM
The 302 just indicates a temporary redirect was returned.. the api.purpleair.com should be accessed via https likely.

The local URL shouldn't have changed in response (mine hasn't).
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: 92merc on May 28, 2022, 12:34:26 PM
Even if I disable the API section, I still get that error message.  So I don't think it's related to adding the API section I never had.

On the PA Community forum, there were some questions about a firmware 7 version that is being rolled out.  I didn't pay attention to what version I had out of the box.  But I'm now at 7.00 .  I'm beginning to wonder if that could be related to the new errors, if mine did get the update, and not everyone has it yet.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: waiukuweather on May 28, 2022, 02:45:48 PM
if you have local IP working for purple air data, I have now added where it will use PM2.5 value from that data instead of trying to get it from the cloud
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: Forever on May 29, 2022, 03:23:09 PM
I tried to use the file Ken provided but after entering my station and key I only get a blank page. What am I doing wrong?
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: saratogaWX on May 29, 2022, 03:49:01 PM
The purpleair-inc.php doesn't directly produce visible output .. it has to be used with something like the wxpurpleair.php page attached.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: Forever on May 29, 2022, 03:59:55 PM
Thanks Ken, I'm getting data now. Now lets see if I can incorporate the changes into the script I'm using.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: zeppline on May 29, 2022, 04:48:39 PM
Ken I am lost. Do i still need get-purpleair-aqi or is it replaced with purple-inc and wxpurpleair. having a senior moment. I only have one ID and it is only 5 numbers? I have the keys and am waiting for purpleair to get back with two ID,s. Thanks Joe
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: waiukuweather on May 29, 2022, 05:12:18 PM
i have tested the api in WD , using a Station ID number (you can  get that for your station via the purple air map) and a api key for someones purple air sensor and it does work
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: saratogaWX on May 29, 2022, 05:24:49 PM
Ken I am lost. Do i still need get-purpleair-aqi or is it replaced with purple-inc and wxpurpleair. having a senior moment. I only have one ID and it is only 5 numbers? I have the keys and am waiting for purpleair to get back with two ID,s. Thanks Joe

You need an API key for api.purpleair.com access to data --only the READ key need be used.  The station number of your station hasn't changed, so you already have that.

If you configure purpleair-inc.php with your station number and the API READ key, then it can pull data from api.purpleair.com.
The wxpurpleair.php page is needed to present the data gathered by purpleair-inc.php (since that script only gets, but not presents the data).

Hope this helps...
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: Forever on May 29, 2022, 08:20:47 PM
I tried but I have no idea what I'm doing. Anyone want to look at my file and let me know what I'm doing wrong?
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: saratogaWX on May 29, 2022, 09:01:51 PM
The issue is likely with
Code: [Select]
$PurpleAirAPI = 'blank';
You need to request API keys from contact@purpleair.com .  Include your real name and sensorid in the request.

They’ll email back with two API keys, one for Read and one for Write.  Copy the Read key to replace the word ‘blank’ and upload the changed file.  You must have a valid API key for queries to api.purpleair.com
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: Forever on May 29, 2022, 09:12:13 PM
Hi Ken,

I have an API key but removed it before uploading the file so other don't use it.
Title: Re: Heads-up: PurpleAir JSON query now requires an API key... grrrrr.
Post by: Forever on June 14, 2022, 11:33:29 AM
FYI, It looks like todays version of WD fixed the flat line graph issue.