{"record":{"id":"c950a18a12c4872f","repo":"bytebase/bytebase","slug":"failed-to-construct-webhook-post-request-to-s-c950a1","errorCode":null,"errorMessage":"failed to construct webhook POST request to %s","messagePattern":"failed to construct webhook POST request to (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/plugin/webhook/teams/teams.go","lineNumber":124,"sourceCode":"func postPowerAutomateMessage(context webhook.Context) error {\n\tcard := getAdaptiveCard(context)\n\tmsg := activity{\n\t\tType: \"message\",\n\t\tAttachments: []attachment{\n\t\t\t{\n\t\t\t\tContentType: \"application/vnd.microsoft.card.adaptive\",\n\t\t\t\tContent:     card,\n\t\t\t},\n\t\t},\n\t}\n\n\tbody, err := json.Marshal(msg)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to marshal webhook POST request to %s\", context.URL)\n\t}\n\treq, err := http.NewRequest(\"POST\", context.URL, bytes.NewBuffer(body))\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to construct webhook POST request to %s\", context.URL)\n\t}\n\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\tclient := &http.Client{\n\t\tTimeout: webhook.Timeout,\n\t}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to POST webhook to %s\", context.URL)\n\t}\n\n\tb, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to read POST webhook response from %s\", context.URL)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode < 200 || resp.StatusCode >= 300 {","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/bytebase/bytebase/blob/1870550677fe08f0d2a78c07acd27541464eb945/backend/plugin/webhook/teams/teams.go#L106-L142","documentation":"http.NewRequest failed while building the POST request to the Power Automate workflow URL, and the plugin wraps it as 'failed to construct webhook POST request to %s'. NewRequest errors when the URL fails to parse (net/url.Parse error) or when a protocol other than http/https is given. This is almost always a malformed or misconfigured webhook URL stored in the Teams webhook setting.","triggerScenarios":"Receiver.Post detects a Power Automate URL and calls postPowerAutomateMessage; http.NewRequest(\"POST\", context.URL, ...) returns an error because context.URL is unparseable (spaces, missing scheme, control characters) or uses an unsupported scheme (ftp://, no scheme at all).","commonSituations":"Admin pasted a workflow URL with a trailing space or newline when configuring the Teams webhook; URL saved without the https:// scheme; URL truncated by copy/paste; environment proxy or template substitution producing an invalid URL.","solutions":["Open the Teams webhook setting in Bytebase and re-paste the Power Automate workflow URL, ensuring it starts with https:// and has no whitespace.","Validate the stored URL with net/url.ParseRequestURI before saving or calling Post.","Trim whitespace: strings.TrimSpace(rawURL) before storing the webhook URL.","Confirm the URL matches what Power Automate shows in the workflow's HTTP post card (https://*.logic.azure.com/... or https://*.environment.api.powerplatform.com/...)."],"exampleFix":"// before\nwebhookURL := \" logic.azure.com:443/workflows/abc\"\n// after\nwebhookURL := strings.TrimSpace(\"https://prod-xx.logic.azure.com:443/workflows/abc\")\nif _, err := url.ParseRequestURI(webhookURL); err != nil { return fmt.Errorf(\"invalid teams webhook url: %w\", err) }","handlingStrategy":"validation","validationCode":"u, err := url.ParseRequestURI(webhookURL)\nif err != nil || (u.Scheme != \"https\" && u.Scheme != \"http\") {\n    return fmt.Errorf(\"invalid teams webhook URL %q: %w\", webhookURL, err)\n}","typeGuard":null,"tryCatchPattern":"if err := receiver.Post(ctx); err != nil {\n    if strings.Contains(err.Error(), \"failed to construct webhook POST request\") {\n        return fmt.Errorf(\"teams webhook URL is malformed; re-copy it from Power Automate: %w\", err)\n    }\n    return err\n}","preventionTips":["Trim whitespace from webhook URLs at config-entry time","Require https:// scheme when saving Teams webhook settings","Validate the URL with url.ParseRequestURI before persisting"],"tags":["webhook","http","url","configuration"],"backgroundTag":"invalid-url","analyzedSha":"1870550677fe08f0d2a78c07acd27541464eb945","analyzedAt":"2026-09-06T21:16:13.665Z","contentChangedAt":"2026-09-06T21:16:13.665Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}