Skip to content

REST API

Defthand’s public REST API opens Inspections data to the outside: inspections, published reports, findings, corrective actions, locations and visitor feedback. The list of all endpoints is on the API reference page.

All endpoints have this form:

https://<api-address>/api/v1/<module>/...

The version is in the address (v1). An incompatible change comes with a new version number. Request and response bodies are JSON, field names are camelCase; ids are GUIDs, times are ISO 8601, fixed values are text codes ("Published", "DueDate").

For integrations, use an API key (see API keys):

Terminal window
curl https://<api-address>/api/v1/inspections?pageSize=20 \
-H "Authorization: ApiKey $DEFTHAND_API_KEY" \
-H "Accept-Language: en-US"
  • The key carries your company itself; no separate company (tenant) header is needed. A tenant header naming another company gets the request refused.
  • The key works as a service user: it is a member of no team, location or position. Its scope is only its permissions; to read the whole company’s inspections, give the View all inspections permission.
  • The key reaches only the public API endpoints. Portal endpoints and user, role or key management endpoints return 403 with code Identity.ApiKeyForbidden.
  • An unknown, malformed, revoked or expired key returns 401 on every endpoint.
  • All public endpoints also work, with the same permissions, with the token of a person signed in to the panel.

The Accept-Language header (tr-TR, en-US) sets the language of error messages. The machine-readable code field does not depend on the language.

List endpoints are paged. Query parameters:

Parameter Meaning
pageNumber The page number starting at 1 (anything below 1 counts as 1).
pageSize Records per page; each endpoint applies its own upper limit.
sort Sorting (on endpoints that support it).

Response:

{
"items": [ { "...": "..." } ],
"pageNumber": 1,
"pageSize": 20,
"totalCount": 134,
"totalPages": 7,
"hasNext": true,
"hasPrevious": false
}

To get all records, increase pageNumber until hasNext is false.

Errors use the RFC 9457 Problem Details format (application/problem+json):

{
"title": "Forbidden",
"status": 403,
"detail": "API keys cannot use this endpoint.",
"instance": "/api/v1/identity/users",
"code": "Identity.ApiKeyForbidden"
}
  • detail is for people, in the request’s language; do not decide on its text.
  • code (when present) is stable; branch your program on it.
  • On validation errors (400), per-field messages come in errors.
Status Meaning
400 The request is invalid (validation).
401 The key is missing, invalid, revoked or expired.
403 The key has no permission for this, the endpoint is closed to keys, or your company does not have this module (code Module.NotEnabled).
404 The record does not exist or is outside the key’s scope (both give the same response).
409 The record’s state does not allow it (for example there is no published report yet).
429 A rate limit or quota was passed; wait for the time in the Retry-After header.

Requests count against a per-minute rate limit per company, user and address, and against the company’s monthly API call quota. Calls made with a key also count against your company’s budget. When a limit is passed, 429 and Retry-After are returned. Write your system to wait for Retry-After and try again, and use webhooks instead of polling needlessly often.

Writing endpoints (POST) accept an optional Idempotency-Key header. A request repeated with the same key does not do the work twice; the first response is returned as it was, with the header Idempotency-Replayed: true.

Terminal window
curl -X POST https://<api-address>/api/v1/inspections/actions/<action-id>/reject \
-H "Authorization: ApiKey $DEFTHAND_API_KEY" \
-H "Idempotency-Key: 7c1d2f0e-erp-reject-001" \
-H "Content-Type: application/json" \
-d '{"reason":"Fotoğraf eksik, yeniden yükleyin."}'
  • The key is at most 128 characters; generate a new value (a GUID, say) for each new piece of work.
  • The response is kept for 24 hours.
  • If a second request with the same key arrives while the first is still being processed, 409 and Retry-After: 1 are returned.
  1. Learn about new records through webhook events (for example InspectionPublished).
  2. Read the details from the API with the id in the event (GET /api/v1/inspections/{id}).
  3. Download the report from a short-lived link with GET /api/v1/inspections/{id}/report.