bytebase/bytebase · error
failed to construct webhook POST request to
Error message
failed to construct webhook POST request to %s
What it means
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.
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/...).
Example fix
// before
webhookURL := " logic.azure.com:443/workflows/abc"
// after
webhookURL := strings.TrimSpace("https://prod-xx.logic.azure.com:443/workflows/abc")
if _, err := url.ParseRequestURI(webhookURL); err != nil { return fmt.Errorf("invalid teams webhook url: %w", err) } Defensive patterns
Strategy: validation
Validate before calling
u, err := url.ParseRequestURI(webhookURL)
if err != nil || (u.Scheme != "https" && u.Scheme != "http") {
return fmt.Errorf("invalid teams webhook URL %q: %w", webhookURL, err)
} Try / catch
if err := receiver.Post(ctx); err != nil {
if strings.Contains(err.Error(), "failed to construct webhook POST request") {
return fmt.Errorf("teams webhook URL is malformed; re-copy it from Power Automate: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- failed to construct webhook POST request to
- construct GET request
- failed to construct Google Chat webhook POST request
- failed to construct
- failed to construct webhook POST request to
AI-assisted analysis of bytebase/bytebase@1870550677 (2026-09-06).
Data as JSON: /api/errors/c950a18a12c4872f.
Report an issue: GitHub.
Appendix: source
Thrown at backend/plugin/webhook/teams/teams.go:124
func postPowerAutomateMessage(context webhook.Context) error {
card := getAdaptiveCard(context)
msg := activity{
Type: "message",
Attachments: []attachment{
{
ContentType: "application/vnd.microsoft.card.adaptive",
Content: card,
},
},
}
body, err := json.Marshal(msg)
if err != nil {
return errors.Wrapf(err, "failed to marshal webhook POST request to %s", context.URL)
}
req, err := http.NewRequest("POST", context.URL, bytes.NewBuffer(body))
if err != nil {
return errors.Wrapf(err, "failed to construct webhook POST request to %s", context.URL)
}
req.Header.Set("Content-Type", "application/json")
client := &http.Client{
Timeout: webhook.Timeout,
}
resp, err := client.Do(req)
if err != nil {
return errors.Wrapf(err, "failed to POST webhook to %s", context.URL)
}
b, err := io.ReadAll(resp.Body)
if err != nil {
return errors.Wrapf(err, "failed to read POST webhook response from %s", context.URL)
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {View on GitHub (pinned to 1870550677)