{"record":{"id":"8c3fed515529a5f1","repo":"apereo/cas","slug":"could-not-locate-service-definition-by-id","errorCode":null,"errorMessage":"Could not locate service definition by id [{}]","messagePattern":"Could not locate service definition by id \\[(.+?)\\]","errorType":"http","errorClass":null,"httpStatus":404,"severity":"warning","filePath":"support/cas-server-support-reports-core/src/main/java/org/apereo/cas/web/report/RegisteredServicesEndpoint.java","lineNumber":219,"sourceCode":"            MEDIA_TYPE_SPRING_BOOT_V2_JSON,\n            MEDIA_TYPE_SPRING_BOOT_V3_JSON,\n            MEDIA_TYPE_CAS_YAML\n        })\n    public ResponseEntity<String> deleteService(@PathVariable final String id) {\n        if (NumberUtils.isDigits(id)) {\n            val svc = servicesManager.getObject().findServiceBy(Long.parseLong(id));\n            if (svc != null) {\n                return ResponseEntity.ok(MAPPER.writeValueAsString(servicesManager.getObject().delete(svc)));\n            }\n        } else {\n            val svc = servicesManager.getObject().findServiceBy(\n                configurationContext.getObject().getServiceFactory().createService(id));\n            if (svc != null) {\n                return ResponseEntity.ok(MAPPER.writeValueAsString(\n                    servicesManager.getObject().delete(svc)));\n            }\n        }\n        LOGGER.warn(\"Could not locate service definition by id [{}]\", id);\n        return ResponseEntity.notFound().build();\n    }\n\n    /**\n     * Import services.\n     *\n     * @param request the request\n     * @return the http status\n     * @throws Exception the exception\n     */\n    @PostMapping(path = \"/import\", consumes = {\n        MediaType.APPLICATION_OCTET_STREAM_VALUE,\n        MediaType.APPLICATION_JSON_VALUE,\n        MediaType.APPLICATION_YAML_VALUE,\n        MEDIA_TYPE_SPRING_BOOT_V2_JSON,\n        MEDIA_TYPE_SPRING_BOOT_V3_JSON,\n        MEDIA_TYPE_CAS_YAML\n    }, produces = {","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-reports-core/src/main/java/org/apereo/cas/web/report/RegisteredServicesEndpoint.java#L201-L237","documentation":"RegisteredServicesEndpoint.deleteService() attempts to resolve the requested service id into a Service via the service factory and look it up in the ServicesManager. When no registered service matches, it logs this warning and returns HTTP 404 (notFound) instead of deleting anything. It signals that the delete target simply does not exist in the registry.","triggerScenarios":"DELETE request to the CAS services management REST endpoint with an id (or service-id string) that does not match any service currently loaded in ServicesManager; also when the id cannot be converted into a Service by the configured ServiceFactory.","commonSituations":"Deleting a service that was already removed or never imported; using the numeric CAS id vs the serviceId URL interchangeably; multiple CAS nodes with divergent service registries (one node deleted it first); typo or stale bookmarked id.","solutions":["List existing services (GET on the services endpoint) and confirm the id before deleting","Use the exact numeric id assigned by CAS, not the serviceId URL pattern","Check whether the service was deleted by another admin or another node in the cluster","Verify the service registry storage (JSON/JDBC/etc.) is reachable and not reset between calls"],"exampleFix":"// before\ndelete(\"/cas/v1/services/1234\");\n// after: verify existence first\nval all = get(\"/cas/v1/services\");\nif (containsId(all, 1234)) delete(\"/cas/v1/services/1234\");","handlingStrategy":"validation","validationCode":"// GET /cas/v1/services first and assert the id exists before DELETE\nval exists = listServiceIds().contains(targetId);\nif (!exists) throw new Error('service ' + targetId + ' not found');","typeGuard":"function isDeleted(resp) { return resp.status === 404; }","tryCatchPattern":"val resp = delete(url);\nif (resp.status === 404) { /* treat as already-deleted / stale id */ }","preventionTips":["Always list services before deleting","Use the numeric CAS service id, not the serviceId URL","In clusters, route management calls to one node or use a shared registry"],"tags":["rest","http-404","services-management","delete"],"backgroundTag":"record-not-found","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}