cloudflare/cloudflared · error
REST request failed
Error message
REST request failed
What it means
CreateVirtualNetwork POSTs to the account-level virtual network endpoint; "REST request failed" wraps any failure of sendRequest before an HTTP response is obtained. The chained cause explains the real problem (connectivity, TLS, serialization of the NewVirtualNetwork payload). It never indicates an API-level rejection (those come later via statusCodeToError/parseVnet).
Source
Thrown at cfapi/virtual_network.go:56
deletedColumn := "-"
if !virtualNetwork.DeletedAt.IsZero() {
deletedColumn = virtualNetwork.DeletedAt.Format(time.RFC3339)
}
return fmt.Sprintf(
"%s\t%s\t%s\t%s\t%s\t%s\t",
virtualNetwork.ID,
virtualNetwork.Name,
strconv.FormatBool(virtualNetwork.IsDefault),
virtualNetwork.Comment,
virtualNetwork.CreatedAt.Format(time.RFC3339),
deletedColumn,
)
}
func (r *RESTClient) CreateVirtualNetwork(newVnet NewVirtualNetwork) (VirtualNetwork, error) {
resp, err := r.sendRequest("POST", r.baseEndpoints.accountVnets, newVnet)
if err != nil {
return VirtualNetwork{}, errors.Wrap(err, "REST request failed")
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
return parseVnet(resp.Body)
}
return VirtualNetwork{}, r.statusCodeToError("add virtual network", resp)
}
func (r *RESTClient) ListVirtualNetworks(filter *VnetFilter) ([]*VirtualNetwork, error) {
endpoint := r.baseEndpoints.accountVnets
endpoint.RawQuery = filter.Encode()
resp, err := r.sendRequest("GET", endpoint, nil)
if err != nil {
return nil, errors.Wrap(err, "REST request failed")
}
defer resp.Body.Close()View on GitHub (pinned to 2253eeeb25)
Solutions
- Verify connectivity: curl https://api.cloudflare.com/client/v4 from the same host.
- Inspect the wrapped cause with %+v to identify DNS/TLS/timeout vs marshaling.
- Validate the vnet name/comment/IP CIDRs before calling so the request body serializes cleanly.
- Retry after confirming the network path and any proxy settings (HTTPS_PROXY) are correct.
Example fix
null
Defensive patterns
Strategy: validation
Validate before calling
if newVnet.Name == "" || newVnet.IPv4CIDRs == nil {
return errors.New("vnet name and CIDRs are required")
} Try / catch
vnet, err := client.CreateVirtualNetwork(newVnet)
if err != nil {
log.Err(err).Msgf("create vnet failed: %+v", err)
return err
} Prevention
- Validate vnet fields (name, CIDRs) client-side before the POST
- Check network/proxy availability in CI before API calls
- Retry transient transport failures with backoff
When it happens
Trigger: Calling RESTClient.CreateVirtualNetwork(newVnet) when the HTTP request cannot be sent: unreachable API host, TLS errors, request timeouts, or failure marshaling the NewVirtualNetwork body.
Common situations: `cloudflared tunnel vnet create` run offline or with a stale proxy; API endpoint misconfigured via flags/env; request body serialization issues from a malformed NewVirtualNetwork struct.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- quick tunnel provisioning failed
- You must supply at least 1 argument, the name of the virtual
- You must supply exactly one argument, either the ID or name
- You must supply exactly one argument, either the ID or (cur
- funnel not found
AI-assisted analysis of cloudflare/cloudflared@2253eeeb25 (2026-09-06).
Data as JSON: /api/errors/3daf5d670c708f6c.
Report an issue: GitHub.