Connecting a system to the time tracker

The time tracker records working time. If your company also has a system where that time belongs — contracts, projects, tickets, invoices — the tracker can book it there: a person picks what the time is for (“Buchen auf”), and the tracker sends it over, keeps it up to date when it changes, and removes it when it is deleted.

Any system can be connected that answers four HTTP calls. contractmgmt does; another system can implement them itself, or a small bridge can translate them for a product you cannot change. The exact contract is booking-api.openapi.yaml; this page is the walk-through.

Booking is optional. Without a connection the tracker is a time tracker and nothing else, and even with one, only people allowed to book (“Darf auf Verträge und Projekte buchen”) see the picker, and they can always choose “keine Buchung”.

Setting up a connection

  1. In the system, create an API key for the tracker. (contractmgmt: Verwaltung → Zeiterfassung → “Neuen Zugang anlegen”. The key is shown once.)
  2. In the tracker, Verwaltung → Verbindungen → new connection: a name, the system’s address (e.g. https://vertrag.example.com) and that API key.
  3. The tracker then tells the system where to report invoiced bookings (PUT /api/v1/webhook). If that works, you are done. If not — the system does not offer the call, or was unreachable — the tracker shows the webhook address and key to enter in the system by hand.

From then on, people allowed to book see the system’s targets in the picker on the timer and the entry form.

What the system implements

All calls carry Authorization: Bearer <API key> and JSON.

Call When the tracker sends it Answer
GET /api/v1/booking-targets?email=… showing the picker (kept 5 minutes) 200 with [{id, label, group, active}]
PUT /api/v1/bookings/{id} a booked entry is saved 200/201/204, or 409 if invoiced
DELETE /api/v1/bookings/{id} deleted, unbooked, or booked elsewhere 200/204, 404 if unknown, or 409 if invoiced
PUT /api/v1/webhook the connection is created or re-keyed 200/204
  • Targets are whatever time can be booked to. id is yours, any string; label is what people see; group is a heading (a customer, say); active: false stops new bookings but keeps the name on existing ones. You may offer everyone the same targets and ignore email.
  • A booking is {email, name, targetId, date, minutes, note}. {id} is the tracker’s id for it: store it, because the same id comes again whenever the entry changes. A PUT replaces the booking with that id, so a repeated call does no harm. date is the day the work started (YYYY-MM-DD); the note is never empty.
  • The webhook call hands you {url, key}. Keep them for this API key, replacing earlier ones. If you never send events (below), answer 204 and ignore it.

The tracker sends in the background and retries what fails — timeouts (3 s to connect, 10 s to answer), network errors, any status not in the table — for about an hour and a half, then shows the entry to its person as “failed”, with your answer. So answer quickly, and put a readable reason in the body of an error.

Invoiced time: 409 and events

Once time is invoiced it should not change underneath the invoice. Two ways to say so, best both:

  • Answer 409 to a PUT or DELETE of an invoiced booking. The tracker locks the entry — its times and target can no longer be changed, nor the entry deleted; its note may still change but is not sent again — and does not retry.
  • Send an event as soon as you invoice, so the person sees the lock before trying to change anything: POST <url> with Authorization: Bearer <key> (both from the webhook call) and {"type": "booking.locked", "bookingId": "<id>"}. When the invoice is cancelled, send booking.unlocked and the entry may change again. The tracker answers 204; retry until it does — sending an event twice is harmless.

A system that never invoices needs neither: its bookings simply stay editable.

Checking your implementation

Before you connect the tracker, you can play its part with curl (replace address and key):

BASE=https://system.example.com
KEY=your-api-key

# The picker: a JSON list of {id, label, group, active}
curl -H "Authorization: Bearer $KEY" "$BASE/api/v1/booking-targets?email=anna@example.com"

# A booking, the same again (must replace, not duplicate), then gone
ID=7f8f7c3e-2c1d-4b9a-9a4e-1f0c2b3d4e5f
curl -X PUT -H "Authorization: Bearer $KEY" -H "Content-Type: application/json" \
  -d '{"email":"anna@example.com","name":"Anna Muster","targetId":"<an id from above>","date":"2026-11-27","minutes":105,"note":"Plugins updated"}' \
  "$BASE/api/v1/bookings/$ID"
curl -X DELETE -H "Authorization: Bearer $KEY" "$BASE/api/v1/bookings/$ID"   # 204, and 404 the second time

Then create the connection in the tracker, book an entry, and check it arrives. An entry that does not reach your system shows its state (“pending”, or “failed” with your answer) on the entry itself; a failed one has a button to send it again.

(For those working on the tracker itself: in development it runs a stand-in system at /dev/booking-stub, API key stub-api-key, implemented in lib/booking_stub.rb.)