BKL Backend — API Testing Console

Register a company, log in as it, then create a branch beneath it and register users against either — each identified by their cell number — then check them in and out with a real photo upload. Every step below runs against this running server, in order. Responses appear inline; IDs are captured automatically.

checking server…

Captured values

Walkthrough

Endpoint reference

EndpointWhat it does
POST /api/v1/companiesRegister a company: full_name (the person), name, email, phone, password and terms_and_conditions. slug is derived from name when omitted; duplicates return 409. Open for a standalone company. With parent_id it adds a branch instead, which asks for none of the sign-up fields and requires logging in as that parent.
POST /api/v1/auth/loginLog in as a company with slug + password. Returns a bearer token.
POST /api/v1/auth/tokenSame, as an OAuth2 form (username = slug) for Swagger's Authorize button.
GET /api/v1/auth/meThe company the token belongs to.
GET /api/v1/companiesPaginated list. Filters: search, is_active, parent_id, only_main, limit, offset.
GET /api/v1/companies/{id}/sub-companiesThe companies directly beneath this one.
GET /api/v1/companies/{id}Fetch one company.
PATCH /api/v1/companies/{id}Partial update. Send location: null or "" to clear it.
DELETE /api/v1/companies/{id}Delete the company and cascade to its users. 204.
POST /api/v1/companies/{id}/usersRegister a user. phone identifies them within the company; duplicates return 409.
GET /api/v1/companies/{id}/users/by-phoneResolve a user by cell number (?phone=). 404 if no match.
GET /api/v1/companies/{id}/usersThat company's users. include_sub_companies=true rolls up the branches.
POST /api/v1/users/registerSame as above but company_id travels in the body.
GET /api/v1/usersAll users; optional company_id filter, search matches phone/email/name.
GET /api/v1/users/rolesThe accepted role values, with descriptions and which one is the default.
GET /api/v1/users/{id}Fetch one user.
PATCH /api/v1/users/{id}Update phone, email, name, role, active flag or password.
DELETE /api/v1/users/{id}Delete a user. 204.
Check-in / check-out
POST /api/v1/users/{id}/check-inOpen a shift. Optional latitude, longitude, photo_url, note. 409 if already checked in.
POST /api/v1/users/{id}/check-outClose the open shift, with its own coordinates and photo. 409 if not checked in.
GET /api/v1/users/{id}/attendance/currentThe user's open shift, or 404.
GET /api/v1/users/{id}/attendanceThat user's shift history.
GET /api/v1/companies/{id}/attendanceThe company's table. Filters: user_id, is_open, checked_in_from, checked_in_to, include_sub_companies.
GET /api/v1/attendance/{id}One attendance record.
GET /api/v1/companies/{id}/storageThe bucket this company's photos go to, and whether it exists.
Incident reports
POST /api/v1/users/{id}/incidentsReport an incident. message required, photo optional. 400 if the user is inactive.
GET /api/v1/users/{id}/incidentsThat user's reports, newest first. Filters status, has_photo.
GET /api/v1/companies/{id}/incidentsThe company's log. Filters: user_id, status, search, has_photo, reported_from, reported_to, include_sub_companies.
GET /api/v1/incidents/statusesThe accepted status values, and which one a new report starts in.
GET /api/v1/incidents/{id}One incident report.
PATCH /api/v1/incidents/{id}Update the message, or close / reopen it. Closing records who did it. Needs a company login.
GET /health/storageMinIO readiness probe.

Notes worth knowing

  1. A user is identified by their cell number, unique within their company. The same number may be registered under a different company — one person, two employers.
  2. Numbers are normalized to E.164 before storage and before any comparison, so +27 82 123 4567, (+27) 82-123-4567 and 27821234567 are one and the same. A number in national format (leading 0) is rejected with a 422, because it cannot be resolved without knowing the country.
  3. email is optional and carries no uniqueness constraint — two users may share one, or have none at all.
  4. A company is either standalone, a main company, or one level beneath a main company. Pass parent_id when creating one to put it under a main company. The tree stops at two levels, enforced by a composite foreign key in Postgres — the same constraint blocks a company becoming its own parent, and blocks demoting a main company that still has branches.
  5. Every user belongs to exactly one company, main or branch, and responses embed which one. Cell numbers are unique per company, so the same person may be registered at head office and at a branch.
  6. A main company's users and attendance table cover only that company by default; add include_sub_companies=true for a whole-group view.
  7. Deleting a main company is refused with a 409 while it still has branches — a whole group is never removed by one call.
  8. A check-in and its check-out are one row, not two. Check-in creates the row with checked_out_at NULL; check-out fills in the closing half. So is_open means "on site", and duration_seconds is available the moment the shift closes.
  9. Coordinates and photo are optional on both ends and sent separately each time — an empty {} is a valid check-in. Supplying a latitude without a longitude is a 422.
  10. Check-in and check-out are multipart/form-data, not JSON, because they carry a file.
  11. Photos go to MinIO, one bucket per company, named <MINIO_BUCKET_PREFIX>-<company slug> — by default checkin-checkout-acme-industries. The bucket is created on first upload. The record stores the bucket and object key; the bucket itself is recorded per row, so renaming a company cannot orphan its old photos.
  12. Buckets are private. Responses carry a freshly-signed download link that expires (MINIO_URL_EXPIRY_SECONDS, 15 minutes by default) — it is regenerated on every read, so do not store it. An unsigned request for the same object gets a 403.
  13. The image format is sniffed from the bytes, not taken from the upload's Content-Type, so a text file renamed .png is still rejected. JPEG, PNG, GIF, WebP and HEIC are accepted, up to MAX_PHOTO_BYTES.
  14. A user can have only one shift open at a time, enforced by a partial unique index in Postgres — eight simultaneous check-ins create exactly one row.
  15. Passwords are bcrypt-hashed on write and never appear in any response.
  16. Roles are owner, admin, member. Default is member.
  17. An incident is open the moment it is reported, and stays open until someone closes it with PATCH /api/v1/incidents/{id}. Closing stamps closed_at, records the closing company as closed_by_company_id + closed_by_name, and can carry a resolution; it never removes the message, photo or reporter. Reopening clears all of it again. status and closed_at are kept in agreement by a check constraint, so a closed report always has a closing time and an open one never does.
  18. closed_by_name is a copy, not a join. It is the company's name as it read at the moment of closing, so renaming the company does not rewrite old log entries, and deleting it nulls closed_by_company_id while the name stays on record.
  19. Deleting a company cascades to its users and their attendance records and incident reports — there is no confirmation step.
  20. A company must log in before it can create anything under it. Registering a standalone company is open; creating a branch, registering users, and updating or deleting companies and users all need Authorization: Bearer <token> from /auth/login. No token is a 401; a token for a company that does not own the target is a 403.
  21. A logged-in company manages itself and, if it is a main company, its branches. Branches get their own password and can log in to manage themselves, but never their main company.
  22. Reads, check-in and check-out are still open — see "Not built yet" in the README.