Punch deliveries
Every punch reaches a Time and Attendance tenant in a delivery. A tenant takes a delivery only when it is signed with a delivery key that the tenant issued. This page shows how to issue keys. It shows how to send punches from Connect or from your own system. It also shows what happens when a delivery is refused.
How punches find their tenant
Section titled “How punches find their tenant”Every delivery names the tenant its punches are for. There are two ways in.
- Within one install, you use an
in_processsink with the receiverattendance. It hands punches to the engine without the network. See the time sink. The sink names the tenant. It carries one of the tenant’s delivery keys as its secret. - From anywhere else, the sender posts the same batch to
POST /api/attendance/tenants/{tenant}/deliveries. “Anywhere else” means another install’s Connect or a third-party system. The post is signed with one of the tenant’s keys. See delivering punches.
The key decides who gets in. Anyone can make a sink that names a tenant. Only a sender that the tenant gave a key to can put punches into it.
export KEY=$(hourctl -t acme attend delivery-keys create --label "acme clocks")hourctl -t acme sink add acme-time --receiver attendance --receiver-tenant acme \ --secret-env KEY --event punchIn a setup file, name the environment variable that holds the key:
[[sink]]id = "acme-time"type = "in_process"receiver = "attendance"tenant = "acme"secret_env = "ACME_DELIVERY_KEY"events = ["punch"]A sink whose receiver is attendance must name a tenant. A setup without one is refused when it is checked. One sink feeds one tenant.
A sink in a Connect tenant’s setup is sent that Connect tenant’s punches. An install-level sink is sent every Connect tenant’s punches. See sinks.
Whose punch it is
Section titled “Whose punch it is”Each punch belongs to the person the sender names by this system’s id. There are two ways to name the person:
- the event’s
person_id, which a sink that speaks for a system fills in; or - the
person_idof the route the punch came by (data.route), which Connect gives a routed punch. The route’scodesbecome the punch’s labor context values of the same names.
A punch with neither belongs to an unlinked person. That person is known by the sender’s ids. The id is Connect’s id of the person in their sync group, such as hq~0c6f2a1e-.... It has the Connect tenant in front, unless it is the default tenant. An example is acme.hq~0c6f2a1e-....
A punch that names no one at all is kept as an unreadable punch.
Delivery keys
Section titled “Delivery keys”A delivery key is write-only. It delivers punches into the tenant that issued it, and it does nothing else. It reads nothing. It changes no setup. It reaches no other route. An API token cannot make a delivery.
hourctl -t acme attend delivery-keys create --label "dealer-north connect"hourctl -t acme attend delivery-keys listhourctl -t acme attend delivery-keys revoke 3f9a0c21d4e8The API routes are POST and GET /api/attendance/tenants/{tenant}/delivery-keys, and DELETE /api/attendance/tenants/{tenant}/delivery-keys/{id}. An install token, the admin login, or the tenant’s own token (attend:acme) can issue, list and revoke a tenant’s keys.
| Issuing | The answer carries the secret once. The secret is hadk_ and 43 more characters. create prints only the secret, so KEY=$(hourctl -t acme attend delivery-keys create) captures it. Give it to the sender and keep no other copy, because it cannot be shown again. The audit trail records who issued each key. It never records the secret. |
| Listing | Each key shows its id, label, who issued it and when. It also shows last_used, which is when the key last delivered. The last_used value is updated at most once a minute. |
| Storage | Keys are stored encrypted with the install’s secret key (HOURADVANTAGE_SECRET_KEY), as webhook signing secrets are. When you change the secret key, each instance re-encrypts the keys with the new one as it starts. |
| Attributed | Every punch a key delivers is recorded with via delivery:<key id>. See who put a fact in. Each delivery taken in is also one info line in the log. The line has the tenant, the key’s id and the number of facts. |
| Revoking | From then on the key proves nothing. Every instance refuses it from the next delivery. The key stays in the list, flagged revoked, with when and by whom. Its secret is dropped. The audit trail’s entry names the key, its label, who issued it and when it last delivered. |
| Rotating | A tenant accepts every key it has issued. Issue a new key and give it to the sender. Revoke the old key once the sender uses the new one. You can tell because the old key’s last_used stops changing. |
Deleting a tenant deletes its keys. Keys are not part of a written-out tenant. A tenant loaded on another install issues its own keys there.
Delivering punches
Section titled “Delivering punches”POST /api/attendance/tenants/{tenant}/deliveries takes exactly what a Connect webhook sink posts. That is {"events": [...]}, with each event in the event contract. The engine records the punches and ignores other event types.
The endpoint takes no login and no API token. It takes only a signature by one of the tenant’s keys. The signature uses the scheme every Connect webhook sink signs with. It has two headers:
x-houradvantage-timestamp: when it was signed, in Unix seconds.x-houradvantage-signature:v1=followed by the hex HMAC-SHA256, keyed with the delivery key, of the timestamp, a., and the body exactly as sent. You can send severalv1=signatures separated by commas or spaces. One by any of the tenant’s keys is enough.
Sending the same punches again, at any time, records nothing twice. Each punch is kept under its event’s id. The answer is {"punches": <how many readable punches it took in>}. A punch that can’t be read is kept aside, as described below. It isn’t counted.
The endpoint is on the admin listener, but it needs no admin login. Publish it to the senders that need it. Use the same load balancer or proxy as the admin API.
Two things get a delivery refused with 401:
- It has no valid signature.
- Its timestamp is more than 5 minutes from the server’s clock, in either direction. This stops someone from replaying a captured delivery later. Keep the sender’s clock synchronized.
A sender that keeps failing is held off. Deliveries whose signature does not check out are counted for the sender, whatever tenants they name.
- After 10 failures, the sender’s next delivery is answered 429 before its body is read.
- That lasts until a failure is forgiven. One failure is forgiven every 10 seconds.
- A sender that guesses is held off whichever tenant it names. Send again later.
A ninth delivery that is being read while eight others still have signatures not yet checked is answered 503 with Retry-After. A Connect sink sends it again. See security.
Within one install
Section titled “Within one install”Connect tenant dealer-north feeds Time and Attendance tenant acme. The install, or acme’s own token, issues a key. The dealer makes an in_process sink with it:
export KEY=$(hourctl -t acme attend delivery-keys create --label "dealer-north")hourctl -t dealer-north sink add acme-time --receiver attendance \ --receiver-tenant acme --secret-env KEY --event punchThe dealer’s endpoints then name the sink in their sinks.
From another install
Section titled “From another install”On the install that keeps acme’s time (hours.example.com), issue a key. On the install with the clocks, make a webhook sink. It posts to the deliveries endpoint, with the key as its secret:
# on hours.example.comhourctl -t acme attend delivery-keys create --label "plant-2 install"
# on the install with the clockshourctl -t plant-2 sink add acme-time \ --url https://hours.example.com/api/attendance/tenants/acme/deliveries \ --secret-env DELIVERY_KEY --event punchThe webhook sink signs each batch with its secret. The receiving install checks the signature against acme’s keys. A refusal shows in the sending sink’s status, with the reason the receiving install gave.
A tenant’s webhook sink reaches only public addresses. The sending install can allow a destination by listing it in tenant_destinations. See security.
From another system
Section titled “From another system”Any system can deliver punches. It posts events in the event contract’s shape and signs them itself. These are the fields the engine reads from a punch event:
| Field | |
|---|---|
type | punch. |
id | 32 hex digits that stay the same when the punch is sent again. A hash of what identifies the punch at the source works. |
data.time | When the person punched, RFC 3339 with its offset. |
data.state_name | check_in, check_out, meal_out, meal_in, break_out or break_in. For anything else, pairing works out the direction. |
| the person | person_id or data.route.person_id. Otherwise Connect’s person in its group, which is an unlinked person. |
received_at | When the sender took the punch in. |
import hashlib, hmac, json, time, urllib.request
KEY = "hadk_..." # a delivery key acme issuedevent = { "id": hashlib.sha256(b"badge-7731|2026-10-07T08:00:00-05:00").hexdigest()[:32], "schema": 3, "type": "punch", "tenant": "default", "endpoint": "badges", "device": "door-1", "received_at": "2026-10-07T13:00:02Z", "person_id": "104552", "data": {"time": "2026-10-07T08:00:00-05:00", "state_name": "check_in"},}body = json.dumps({"events": [event]}).encode()ts = str(int(time.time()))signature = hmac.new(KEY.encode(), ts.encode() + b"." + body, hashlib.sha256).hexdigest()request = urllib.request.Request( "https://hours.example.com/api/attendance/tenants/acme/deliveries", data=body, method="POST", headers={ "content-type": "application/json", "x-houradvantage-timestamp": ts, "x-houradvantage-signature": "v1=" + signature, },)print(urllib.request.urlopen(request).read()) # {"punches":1}Sign the exact bytes you send. If you serialize the body again after signing, it reads differently and is refused.
A refused sink
Section titled “A refused sink”The engine refuses a delivery in the cases below. It keeps nothing of a refused delivery.
| What is wrong | The sink’s status shows | Over HTTP |
|---|---|---|
| The tenant does not exist (not created yet, or deleted). | The next row’s words: the sink's secret matches none of tenant 'acme''s delivery keys (wrong, or revoked), or the tenant does not exist | 401 the signature matches none of tenant 'acme''s delivery keys (wrong, or revoked) |
| The sink carries no key. | the sink carries no delivery key: ... | 401 the delivery is not signed: ... |
| The key is not one of the tenant’s (wrong, another tenant’s, or revoked). | the sink's secret matches none of tenant 'acme''s delivery keys (wrong, or revoked), or the tenant does not exist | 401 the signature matches none of ... |
| The signed timestamp is more than 5 minutes from the server’s clock. | 401 the delivery's timestamp ... is ... seconds from this server's clock ... | |
| The tenant is suspended. | tenant 'acme' is suspended | 409 |
| The sink names no tenant (a backstop; the setup requires one). | the sink names no tenant: ... |
Over HTTP, each refusal is {"error": "..."}. A Connect webhook sink shows it in its status after the status code, for example webhook returned 401 Unauthorized: the signature matches none of ....
The endpoint reveals nothing about which tenants exist until the caller proves one of the tenant’s keys. A missing tenant gets the same 401, in the same words, as a wrong key. Only after a key is proven is a suspended tenant answered 409.
An in_process sink gets the same words for a tenant that does not exist as for a key that is wrong. This is because anyone who may set a sink up may name any tenant in it. Suppose a sink waits and shows that refusal. Check it against hourctl attend tenants list and the tenant’s keys.
Connect’s outbox handles a refused delivery as it does for any sink that refuses:
- The sink keeps its place. The reason shows in its status and in the log. To see the status of an install-level sink, run
hourctl --install sinksor callGET /api/sinks/status. For a sink in a Connect tenant’s setup, runhourctl -t <tenant> sinksor callGET /api/tenants/{tenant}/sinks/status. - The outbox tries again. It waits longer each time, up to a minute between tries.
- Only that sink is held up. Every other sink, feeding other tenants, carries on.
Sometimes a tenant is created or resumed, or it issues a key. Then every instance retries the sinks that name it at once. They do not wait out their backoff. They deliver everything that waited, in order, from where they stopped. A punch delivered again is the same punch, so nothing is kept twice.
A punch that cannot be read
Section titled “A punch that cannot be read”The engine cannot read some punches. A punch may have no time, no device, or no one to place it on. The engine never drops such a punch. It never holds back the punches delivered with it.
The delivery is accepted. The engine keeps the event as it came, with the reason, among the tenant’s unreadable punches. You get them from GET /api/attendance/tenants/{tenant}/unreadable, oldest first, a page at a time.
To put one right, follow these steps:
- Record the punch it should have been, with
POST .../people/{person}/facts. - Delete the unreadable entry, with
DELETE .../unreadable/{id}.
hourctl attend unreadable list shows the unreadable punches. hourctl attend unreadable forget drops one that was put right.