API Usage - high points consumed for get_sensor endpoint

I make a request to the following URL every 2 minutes:

https://api.purpleair.com/v1/sensors?fields=last_seen,pm2.5_atm_a,pm2.5_atm_b&show_only=ID1,ID2,ID3,ID4,ID5 HTTP/1.1

where IDn is an integer sensor_index. So 5 sensors, 3 fields every 2 minutes.

Could someone help me understand why my typical daily usage looks like this:

|Date|Endpoint|Points consumed|Total calls|Data usage|
| --- | --- | --- | --- | --- |
|01 Jan|get_sensor|221,495|1429|4.68 MB|
|01 Jan|get_sensors|13,113|717|281.97 KB|

The get_sensors points/# calls looks right but where are the get_sensor calls coming from and why is the points consumed so high?

Thanks,
Kevin

Hi @khp, a call to get_sensor which retrieves all data for a sensor typically costs a bit above 150 points. Dividing 221,495 points by 1429 results in an average point cost of 155 per get_sensor call. Returning all data is the default behavior for get_sensor calls when no fields are specified.

Additionally, there’s 1440 minutes in a day. I suspect that there’s some code calling the get_sensor endpoint with your key once every minute for a single sensor, and retrieving all data reported by not specifying any fields (it could also be two sensors every two minutes).

If you’re unsure of how these calls are being made, you could try disabling the current API key and creating a new one to use for your get_sensors calls. Disabling an API key can be done on https://develop.purpleair.com in the “API Keys” tab by clicking the pencil icon and changing “Status” to “Disabled.”

You can also set a host restriction for your API key to limit the hosts or IP addresses it can be used from. By leaving the old API key as active and setting a host restriction of your IP address, you could confirm that these calls are coming from your IP address. Host restrictions can be modified similarly to the status as detailed above.

1 Like

Hi Joshua, thank you for the reply. The only endpoint I am requesting is get_sensors, not get_sensor. Is it possible you are converting the get_sensors call to 5 internal get_sensor calls and not passing through the requested fields?

The get_sensors endpoint doesn’t convert to separate get_sensor requests on the backend. Additionally, the get_sensor requests are a little under 2 times the amount of the get_sensors requests as opposed to 5 times as many. I made some test calls mirroring what you provided (with different sensor indexes) and was not able to replicate the issue.

Try generating a new API key and see if it encounters the same issue when making the get_sensors calls.

1 Like

Thank you Josh, with your help I was able to track down the problematic client.

2 Likes