{"record":{"id":"4f3c5ff72fd7a4d8","repo":"crowdsecurity/crowdsec","slug":"failed-to-create-papi-client-w","errorCode":null,"errorMessage":"failed to create PAPI client: %w","messagePattern":"failed to create PAPI client: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/apiserver/papi.go","lineNumber":102,"sourceCode":"\tPlan       string   `json:\"plan\"`\n\tCategories []string `json:\"categories\"`\n}\n\nfunc NewPAPI(apic *apic, dbClient *database.Client, consoleConfig *csconfig.ConsoleConfig, logger logging.ExtLogger) (*Papi, error) {\n\tif logger == nil {\n\t\tlogger = log.StandardLogger()\n\t}\n\n\tpapiURL := *apic.apiClient.PapiURL\n\tpapiURL.Path = fmt.Sprintf(\"%s%s\", PAPIVersion, PAPIPollURL)\n\n\tlongPollClient, err := longpollclient.NewLongPollClient(longpollclient.LongPollClientConfig{\n\t\tUrl:        papiURL,\n\t\tLogger:     logger,\n\t\tHttpClient: apic.apiClient.GetClient(),\n\t})\n\tif err != nil {\n\t\treturn &Papi{}, fmt.Errorf(\"failed to create PAPI client: %w\", err)\n\t}\n\n\tchannels := &OperationChannels{\n\t\tAddAlertChannel:       apic.AlertsAddChan,\n\t\tDeleteDecisionChannel: make(chan []*models.Decision),\n\t}\n\n\tpapi := &Papi{\n\t\tURL:           apic.apiClient.PapiURL.String(),\n\t\tClient:        longPollClient,\n\t\tDBClient:      dbClient,\n\t\tChannels:      channels,\n\t\tSyncInterval:  SyncInterval,\n\t\tmu:            sync.Mutex{},\n\t\tpullTomb:      tomb.Tomb{},\n\t\tsyncTomb:      tomb.Tomb{},\n\t\tapiClient:     apic.apiClient,\n\t\tapic:          apic,","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/apiserver/papi.go#L84-L120","documentation":"NewPAPI builds the Polling API (PAPI) client by constructing a long-poll HTTP client pointed at the CAPI decisions/stream/poll endpoint. This error wraps any failure from longpollclient.NewLongPollClient (typically URL parsing or HTTP client configuration problems) and aborts PAPI subsystem initialization, so the server cannot receive push-style decision/alert orders from the central API.","triggerScenarios":"Called from NewServer during apiserver startup (and by sync/QueryPAPIInfo) when api.client.papi_url is misconfigured or the underlying http client from apic.apiClient.GetClient() cannot be prepared — e.g. the papi URL fails to parse in NewLongPollClient.","commonSituations":"Malformed or missing api.client.papi_url in config.yaml; corrupt api section config after manual edits; network proxy/TLS client misconfiguration (insecure_skip_verify/ca_cert path issues) that makes client construction fail at boot.","solutions":["Read the wrapped error after 'failed to create PAPI client:' — it names the exact cause (usually URL parse failure).","Check config.yaml: api.client.papi_url must be a valid absolute URL (default https://api.crowdsec.net).","Validate the whole api.client section (url, login, password, ca_cert_path, insecure_skip_verify) with `crowdsec -c config.yaml -t` (config test).","Restore the default papi_url if it was hand-edited, then restart crowdsec."],"exampleFix":"// before (config.yaml)\napi:\n  client:\n    papi_url: api.crowdsec.net/v1   # missing scheme\n// after\napi:\n  client:\n    papi_url: https://api.crowdsec.net/","handlingStrategy":"try-catch","validationCode":"u, err := url.Parse(cfg.API.Client.PapiURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid papi_url %q\", cfg.API.Client.PapiURL)\n}","typeGuard":null,"tryCatchPattern":"papi, err := NewPAPI(apic, dbClient, consoleConfig, logger)\nif err != nil {\n    var urlErr *url.Error\n    if errors.As(err, &urlErr) {\n        logger.Errorf(\"PAPI URL misconfigured: %v\", urlErr)\n    }\n    return err\n}","preventionTips":["Run `crowdsec -t` (config test) after any edit to the api.client section.","Never hand-edit papi_url unless instructed; keep the upstream default.","Use `crowdsec config check`-style tooling or cscli to validate YAML before restart.","Validate URL values loaded from env/templating for stray whitespace and missing scheme."],"tags":["config","startup","papi","http-client"],"backgroundTag":"invalid-url-format","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}