{"record":{"id":"9ea26d1ac193951a","repo":"cloudflare/cloudflared","slug":"failed-to-create-account-level-endpoint","errorCode":null,"errorMessage":"failed to create account level endpoint","messagePattern":"failed to create account level endpoint","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cfapi/base_client.go","lineNumber":51,"sourceCode":"\tuserAgent     string\n\tclient        http.Client\n\tlog           *zerolog.Logger\n}\n\ntype baseEndpoints struct {\n\taccountLevel  url.URL\n\tzoneLevel     url.URL\n\taccountRoutes url.URL\n\taccountVnets  url.URL\n}\n\nvar _ Client = (*RESTClient)(nil)\n\nfunc NewRESTClient(baseURL, accountTag, zoneTag, authToken, userAgent string, log *zerolog.Logger) (*RESTClient, error) {\n\tbaseURL = strings.TrimSuffix(baseURL, \"/\")\n\taccountLevelEndpoint, err := url.Parse(fmt.Sprintf(\"%s/accounts/%s/cfd_tunnel\", baseURL, accountTag))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to create account level endpoint\")\n\t}\n\taccountRoutesEndpoint, err := url.Parse(fmt.Sprintf(\"%s/accounts/%s/teamnet/routes\", baseURL, accountTag))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to create route account-level endpoint\")\n\t}\n\taccountVnetsEndpoint, err := url.Parse(fmt.Sprintf(\"%s/accounts/%s/teamnet/virtual_networks\", baseURL, accountTag))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to create virtual network account-level endpoint\")\n\t}\n\tzoneLevelEndpoint, err := url.Parse(fmt.Sprintf(\"%s/zones/%s/tunnels\", baseURL, zoneTag))\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to create account level endpoint\")\n\t}\n\thttpTransport := http.Transport{\n\t\tTLSHandshakeTimeout:   defaultTimeout,\n\t\tResponseHeaderTimeout: defaultTimeout,\n\t}\n\t_ = http2.ConfigureTransport(&httpTransport)","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/cloudflare/cloudflared/blob/2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f/cfapi/base_client.go#L33-L69","documentation":"NewRESTClient builds the Cloudflare API account-level cfd_tunnel endpoint URL with url.Parse and wraps any parse failure with this message. It means the constructed URL string (baseURL + /accounts/<accountTag>/cfd_tunnel) was not a valid URL. This happens almost exclusively when baseURL or accountTag contain characters illegal in a URL.","triggerScenarios":"Calling NewRESTClient with a baseURL containing spaces or control characters, or an accountTag with unencoded special characters (spaces, '%', non-ASCII).","commonSituations":"A typo or trailing whitespace in the API base URL config, copying the account tag with extra characters from a shell/JSON output, or overriding the default API host with a malformed custom value (e.g. in a test or proxy setup).","solutions":["Print/inspect baseURL and accountTag; trim whitespace and remove illegal characters.","Use the default Cloudflare API URL (https://api.cloudflare.com) unless you specifically need a proxy.","URL-escape the account tag if it can contain special characters.","Validate the account tag matches the expected hex-ID format before constructing the client."],"exampleFix":"// before\nNewRESTClient(\"https://api.cloudflare.com \", accountTag, ...)\n// after\nNewRESTClient(strings.TrimSpace(baseURL), strings.TrimSpace(accountTag), ...)","handlingStrategy":"validation","validationCode":"if u, err := url.Parse(strings.TrimSpace(baseURL)); err != nil || u.Scheme == \"\" || u.Host == \"\" {\n\treturn fmt.Errorf(\"invalid API base URL: %q\", baseURL)\n}\nif strings.TrimSpace(accountTag) == \"\" {\n\treturn errors.New(\"account tag must not be empty\")\n}","typeGuard":null,"tryCatchPattern":"client, err := cfapi.NewRESTClient(baseURL, accountTag, zoneTag, token, ua, log)\nif err != nil {\n\treturn fmt.Errorf(\"failed to init cfapi client (check baseURL/accountTag): %w\", err)\n}","preventionTips":["Trim whitespace from baseURL and tags read from config/env.","Validate URL components with url.Parse before constructing clients.","Keep account/zone tags in dedicated config fields, never interpolated from shell strings."],"tags":["go","url","api-client","configuration"],"backgroundTag":"invalid-url-format","analyzedSha":"2253eeeb25a44a713a4b60b8ba1e1b3f377d1a0f","analyzedAt":"2026-09-06T04:14:33.757Z","contentChangedAt":"2026-09-06T04:14:33.757Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}