If you want to be notified or update your system every time a user unlocks a door you can use event log polling. The Parakey API uses ETag headers to indicate if any changes have been made on every endpoint, and we can use this ETag for event polling. By using the if-None-Match header on your request you will receive an "HTTP 304 Not modified" response if nothing has changed.
So to do EventLog polling setup a script that runs in an interval (we do not recommend an interval of less than 60 sec).
You need to keep track of two variables in your system:
lastETag- Always save the last received ETag to use in if-None-Match header.
lastFetchedCreatedAt- This is used to guarantee you will get all event logs since your last poll. Please be aware that createdAt might be different from the timestamp you receive in the EventLog. The timestamp is always the time the actual door was unlocked. For the first request before you set lastFetchedCreatedAt you can simply use new Date() (and you will only receive updates starting from now, or any date when you want to start reading from)
Then implement the following event poll flow:
- Poll the Get EventLogs endpoint with
- First time just save the ETag and move on
- Every following request send the
- If you receive an HTTP 304 Not modified response, nothing has changed and you do not have to continue, for every other HTTP response save the ETag and keep going
- Fetch Get EventLogs using
- Save lastFetchedCreatedAt = new Date();
- Loop through each EventLog and update your system.
We have also implemented webhook for EventLogs and are currently running them in beta. This means you will get an HTTP post every time the user unlocks a door and can react to this in "real time". If you are interested in this beta feature please contact us and we will give you information on how to get started.