REST API – authentication, response envelope and OpenAPI
Common rules of the external JSON endpoints: resolving the API key, merging the input, the error envelope and HTTP statuses, logging and the self-describing OpenAPI document.
Overview
JSON endpoints for external systems (index.php?route=api/group/resource.method). Every resource controller has an openapi(): array method; the aggregated descriptor is built from these.
Authentication
- The key arrives in the
X-Oc-Api-Keyheader or, for backward compatibility, in the POST fieldapi_key; themasterdataandsubscription/orderendpoints do not accept it as a GET parameter, the Explorer does. - Resolution:
api/auth::getUserByApiKey()→user_api_key(status=1) joined with the framework's active user → user, group, user name. If theuser_api_keytable is missing, every key is invalid. - Endpoints check the function permission for the key owner with the admin route keys (
canActionForUser).
Input and response
apiInput(): GET parameters, the raw body (JSON, otherwise urlencoded) and POST fields merged; later ones override earlier ones.apiOut()→dlbtjson->restEnvelope(). On success the endpoint's own JSON with HTTP 200, structure unchanged. On errorsuccess:false,error(one message),error_code, and for field validationerror_fields.- HTTP status from the code (
statusFor()):VALIDATION_ERROR422,BAD_REQUEST400,UNAUTHORIZED401,PERMISSION_DENIED403,NOT_FOUND404,CONFLICT409,DB_QUERY_ERROR,UNCAUGHT_EXCEPTION,PHP_FATAL_ERROR500; without a codeVALIDATION_ERROR. - Every method body is in
try/catch;debug_messagewould be added only with thedebugpermission, which on the catalog side is always false because the permission handler is missing there. - Logging: successful and rejected calls go to the system log (channels
api/company,api/addressmaster,api/bankaccountmaster).
OpenAPI and documentation
| Endpoint | Behaviour | Protection |
|---|---|---|
api/explorer/openapi | an OpenAPI 3.0 document from the openapi() pieces of the catalog/controller/api/*/*.php controllers (server URL, ApiKeyAuth scheme); no manual list and no database; loaded by the /api-explorer/ Swagger UI | valid API key (header, GET or POST api_key), otherwise 403 |
api/explorer/openapi.swagger2 | the same in Swagger 2.0 form (formData, definitions, securityDefinitions) | same |
admin api/swagger | Swagger UI with local assets; not in the menu | basic access right, no function permission |
admin api/swagger.openapi | OpenAPI 3.1.1 JSON | basic access, otherwise 403 |
Known limitations
- The endpoint descriptions of the admin OpenAPI document are documentation placeholders ("Implementation status: Insufficient data to verify").
- The Explorer and admin documentation endpoints are not classified in the permission catalogue seeds.