API Correct Timestamp Get Sensors API Call

Hello,
I’m looking at using the Purple Air API call Get Sensors Data to pull sensor data.

The field last_seen states “The UNIX time stamp of the last time the server received data from the device.”

I’m assuming this is the time that corresponds with the measured data (ex pm1.0, pm2.5, etc.) correct? Every sensor returned shows a slightly different value which makes sense.

As this is just a number, if I convert in python datetime.fromtimestamp(last_seen) I get a time that is in the timezone of the computer I’m running the code on (it seems to be within a few minutes of when I ran the query to the API).

Is this timestamp in UTC, the time of the sensor, or some other time?

Should I be using last_seen for this, or something else?

Thanks!

The field last_seen returns most recent time that the sensor reported to the database. Sensors report every two minutes, so assuming the sensor is actively reporting, the timestamp you’ll get will be less than two minutes old. That’s why you’re seeing that the time returned is within a few minutes of querying.

Time from the API is returned in the form in which it was called. For example, if you use the timestamp 2023-06-08T16:38:33Z, the data will be returned in UTC, since you specified UTC with the “Z” in the timestamp. If you use the timestamp 2023-06-08T16:38:33Z-6:00, the data will be returned in UTC-6:00.

UNIX timestamps are always in UTC, so if you make your call with a UNIX timestamp, the data returned in the response will be in UTC.