Skip to content
Start here

Create Service Binding

addressing.prefixes.service_bindings.create(strprefix_id, ServiceBindingCreateParams**kwargs) -> ServiceBinding
POST/accounts/{account_id}/addressing/prefixes/{prefix_id}/bindings

Creates a new Service Binding, routing traffic to IPs within the given CIDR to a service running on Cloudflare’s network. NOTE: The first Service Binding created for an IP Prefix must exactly match the IP Prefix’s CIDR. Subsequent Service Bindings may be created with a more-specific CIDR. Refer to the Service Bindings Documentation for compatibility details.

Security

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
Accepted Permissions (at least one required)
IP Prefixes: Write
ParametersExpand Collapse
account_id: str

Identifier of a Cloudflare account.

maxLength32
prefix_id: str

Identifier of an IP Prefix.

maxLength32
cidr: str

IP Prefix in Classless Inter-Domain Routing format.

service_id: str

Identifier of a Service on the Cloudflare network. Available services and their IDs may be found in the List Services endpoint.

maxLength32
ReturnsExpand Collapse
class ServiceBinding:
id: Optional[str]

Identifier of a Service Binding.

maxLength32
cidr: Optional[str]

IP Prefix in Classless Inter-Domain Routing format.

provisioning: Optional[Provisioning]

Status of a Service Binding’s deployment to the Cloudflare network

state: Optional[Literal["provisioning", "active"]]

When a binding has been deployed to a majority of Cloudflare datacenters, the binding will become active and can be used with its associated service.

One of the following:
"provisioning"
"active"
service_id: Optional[str]

Identifier of a Service on the Cloudflare network. Available services and their IDs may be found in the List Services endpoint.

maxLength32
service_name: Optional[str]

Name of a service running on the Cloudflare network

Create Service Binding

import os
from cloudflare import Cloudflare

client = Cloudflare(
    api_email=os.environ.get("CLOUDFLARE_EMAIL"),  # This is the default and can be omitted
    api_key=os.environ.get("CLOUDFLARE_API_KEY"),  # This is the default and can be omitted
)
service_binding = client.addressing.prefixes.service_bindings.create(
    prefix_id="2af39739cc4e3b5910c918468bb89828",
    account_id="258def64c72dae45f3e4c8516e2111f2",
    cidr="192.0.2.0/24",
    service_id="2db684ee7ca04e159946fd05b99e1bcd",
)
print(service_binding.id)
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "id": "0429b49b6a5155297b78e75a44b09e14",
    "cidr": "192.0.2.0/24",
    "provisioning": {
      "state": "provisioning"
    },
    "service_id": "2db684ee7ca04e159946fd05b99e1bcd",
    "service_name": "Magic Transit"
  }
}
Returns Examples
{
  "errors": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "messages": [
    {
      "code": 1000,
      "message": "message",
      "documentation_url": "documentation_url",
      "source": {
        "pointer": "pointer"
      }
    }
  ],
  "success": true,
  "result": {
    "id": "0429b49b6a5155297b78e75a44b09e14",
    "cidr": "192.0.2.0/24",
    "provisioning": {
      "state": "provisioning"
    },
    "service_id": "2db684ee7ca04e159946fd05b99e1bcd",
    "service_name": "Magic Transit"
  }
}