Skip to content
Start here

Create Workers VPC connectivity service

client.Connectivity.Directory.Services.New(ctx, params) (*DirectoryServiceNewResponse, error)
POST/accounts/{account_id}/connectivity/directory/services

Create Workers VPC connectivity service

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
ParametersExpand Collapse
params DirectoryServiceNewParams
AccountID param.Field[string]

Path param: Account identifier

maxLength32

Body param

type DirectoryServiceNewParamsHostInfraIPv4Host struct{…}
IPV4 string
Network DirectoryServiceNewParamsHostInfraIPv4HostNetwork
TunnelID string
formatuuid
type DirectoryServiceNewParamsHostInfraIPv6Host struct{…}
IPV6 string
Network DirectoryServiceNewParamsHostInfraIPv6HostNetwork
TunnelID string
formatuuid
type DirectoryServiceNewParamsHostInfraDualStackHost struct{…}
IPV4 string
IPV6 string
Network DirectoryServiceNewParamsHostInfraDualStackHostNetwork
TunnelID string
formatuuid
type DirectoryServiceNewParamsHostInfraHostnameHost struct{…}
Hostname string
ResolverNetwork DirectoryServiceNewParamsHostInfraHostnameHostResolverNetwork
TunnelID string
formatuuid
ResolverIPs []stringoptional
Name param.Field[string]

Body param

Body param

const DirectoryServiceNewParamsTypeHTTP DirectoryServiceNewParamsType = "http"
HTTPPort param.Field[int64]optional

Body param

formatint32
minimum1
HTTPSPort param.Field[int64]optional

Body param

formatint32
minimum1
ReturnsExpand Collapse
type DirectoryServiceNewResponse struct{…}
Host DirectoryServiceNewResponseHost
One of the following:
type DirectoryServiceNewResponseHostInfraIPv4Host struct{…}
IPV4 string
Network DirectoryServiceNewResponseHostInfraIPv4HostNetwork
TunnelID string
formatuuid
type DirectoryServiceNewResponseHostInfraIPv6Host struct{…}
IPV6 string
Network DirectoryServiceNewResponseHostInfraIPv6HostNetwork
TunnelID string
formatuuid
type DirectoryServiceNewResponseHostInfraDualStackHost struct{…}
IPV4 string
IPV6 string
Network DirectoryServiceNewResponseHostInfraDualStackHostNetwork
TunnelID string
formatuuid
type DirectoryServiceNewResponseHostInfraHostnameHost struct{…}
Hostname string
ResolverNetwork DirectoryServiceNewResponseHostInfraHostnameHostResolverNetwork
TunnelID string
formatuuid
ResolverIPs []stringoptional
Name string
Type DirectoryServiceNewResponseType
CreatedAt Timeoptional
formatdate-time
HTTPPort int64optional
formatint32
minimum1
HTTPSPort int64optional
formatint32
minimum1
ServiceID stringoptional
formatuuid
UpdatedAt Timeoptional
formatdate-time

Create Workers VPC connectivity service

package main

import (
  "context"
  "fmt"

  "github.com/cloudflare/cloudflare-go"
  "github.com/cloudflare/cloudflare-go/connectivity"
  "github.com/cloudflare/cloudflare-go/option"
)

func main() {
  client := cloudflare.NewClient(
    option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
  )
  service, err := client.Connectivity.Directory.Services.New(context.TODO(), connectivity.DirectoryServiceNewParams{
    AccountID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
    Host: cloudflare.F[connectivity.DirectoryServiceNewParamsHostUnion](connectivity.DirectoryServiceNewParamsHostInfraHostnameHost{
      Hostname: cloudflare.F("api.example.com"),
      ResolverNetwork: cloudflare.F(connectivity.DirectoryServiceNewParamsHostInfraHostnameHostResolverNetwork{
        TunnelID: cloudflare.F("0191dce4-9ab4-7fce-b660-8e5dec5172da"),
      }),
    }),
    Name: cloudflare.F("web-server"),
    Type: cloudflare.F(connectivity.DirectoryServiceNewParamsTypeHTTP),
  })
  if err != nil {
    panic(err.Error())
  }
  fmt.Printf("%+v\n", service.ServiceID)
}
{
  "errors": [],
  "messages": [],
  "result": {
    "created_at": "2024-01-15T09:30:00Z",
    "host": {
      "hostname": "api.example.com",
      "resolver_network": {
        "tunnel_id": "0191dce4-9ab4-7fce-b660-8e5dec5172da"
      }
    },
    "name": "web-server",
    "service_id": "550e8400-e29b-41d4-a716-446655440000",
    "type": "http",
    "updated_at": "2024-01-15T09:30:00Z"
  },
  "success": true
}
Returns Examples
{
  "errors": [],
  "messages": [],
  "result": {
    "created_at": "2024-01-15T09:30:00Z",
    "host": {
      "hostname": "api.example.com",
      "resolver_network": {
        "tunnel_id": "0191dce4-9ab4-7fce-b660-8e5dec5172da"
      }
    },
    "name": "web-server",
    "service_id": "550e8400-e29b-41d4-a716-446655440000",
    "type": "http",
    "updated_at": "2024-01-15T09:30:00Z"
  },
  "success": true
}