{"record":{"id":"c75ae5e9035d5142","repo":"caddyserver/caddy","slug":"resource-not-found-v","errorCode":null,"errorMessage":"resource not found: %v","messagePattern":"resource not found: (.+?)","errorType":"http","errorClass":"caddy.APIError","httpStatus":404,"severity":"info","filePath":"modules/caddypki/adminapi.go","lineNumber":86,"sourceCode":"\t\t\tPattern: adminPKIEndpointBase,\n\t\t\tHandler: caddy.AdminHandlerFunc(a.handleAPIEndpoints),\n\t\t},\n\t}\n}\n\n// handleAPIEndpoints routes API requests within adminPKIEndpointBase.\nfunc (a *adminAPI) handleAPIEndpoints(w http.ResponseWriter, r *http.Request) error {\n\turi := strings.TrimPrefix(r.URL.Path, \"/pki/\")\n\tparts := strings.Split(uri, \"/\")\n\tswitch {\n\tcase len(parts) == 2 && parts[0] == \"ca\" && parts[1] != \"\":\n\t\treturn a.handleCAInfo(w, r)\n\tcase len(parts) == 3 && parts[0] == \"ca\" && parts[1] != \"\" && parts[2] == \"certificates\":\n\t\treturn a.handleCACerts(w, r)\n\t}\n\treturn caddy.APIError{\n\t\tHTTPStatus: http.StatusNotFound,\n\t\tErr:        fmt.Errorf(\"resource not found: %v\", r.URL.Path),\n\t}\n}\n\n// handleCAInfo returns information about a particular\n// CA by its ID. If the CA ID is the default, then the CA will be\n// provisioned if it has not already been. Other CA IDs will return an\n// error if they have not been previously provisioned.\nfunc (a *adminAPI) handleCAInfo(w http.ResponseWriter, r *http.Request) error {\n\tif r.Method != http.MethodGet {\n\t\treturn caddy.APIError{\n\t\t\tHTTPStatus: http.StatusMethodNotAllowed,\n\t\t\tErr:        fmt.Errorf(\"method not allowed: %v\", r.Method),\n\t\t}\n\t}\n\n\tca, err := a.getCAFromAPIRequestPath(r)\n\tif err != nil {\n\t\treturn err","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddypki/adminapi.go#L68-L104","documentation":"A 404 caddy.APIError returned by the PKI admin API router when a request under /pki/ does not match the two supported shapes: GET /pki/ca/&lt;id&gt; (CA info) or GET /pki/ca/&lt;id&gt;/certificates (PEM chain). Any other path — wrong segment count, unknown sub-resource, or missing id — lands in the default branch. The error echoes r.URL.Path so the caller sees exactly what was unmatched.","triggerScenarios":"Calling GET /pki/ca, /pki/ca/, /pki/cas/local, /pki/ca/local/chain, or POST /pki/ca/local (path is fine but a later method check is separate — for the router itself, any unmatched path). Reaching this error means the path itself is wrong, independent of HTTP method.","commonSituations":"Scripts written against another ACME/CA admin API assuming /certificates lives at a different path; trailing-slash differences (`/pki/ca/local/` has 3 trailing segments and 404s); typos in automation curl commands.","solutions":["Use exactly GET /pki/ca/&lt;id&gt; for CA metadata or GET /pki/ca/&lt;id&gt;/certificates for the PEM chain","Use the default CA id `local`: GET /pki/ca/local","Check the echoed path in the error response body to spot the typo","Confirm the admin endpoint base (default localhost:2019) is the one being addressed"],"exampleFix":"# before\ncurl http://localhost:2019/pki/ca/local/chain\n\n# after\ncurl http://localhost:2019/pki/ca/local/certificates","handlingStrategy":"validation","validationCode":"// Build only supported PKI admin paths:\nfunc pkiPath(id string, certs bool) (string, error) {\n    if id == \"\" { return \"\", errors.New(\"empty CA id\") }\n    if certs { return \"/pki/ca/\" + id + \"/certificates\", nil }\n    return \"/pki/ca/\" + id, nil\n}","typeGuard":null,"tryCatchPattern":"// Treat 404 from the PKI API as a path bug, not a transient error:\nresp, err := http.Get(base + \"/pki/ca/\" + id)\nif err != nil { return err }\nif resp.StatusCode == 404 {\n    return fmt.Errorf(\"unsupported PKI API path; use /pki/ca/&lt;id&gt; or /pki/ca/&lt;id&gt;/certificates\")\n}","preventionTips":["Centralize admin API path construction in one helper","Avoid trailing slashes after the CA id","Pin automation against one Caddy version's admin API docs"],"tags":["pki","admin-api","http-404","routing"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}