# Attach a firewall to a Kafka cluster

Attach a firewall to every broker of a cluster. The firewall must be in the cluster's team. We apply its rules in the background.

[endpoint]
method = "POST"
base_url = "https://{availability_zone}.betterstackcloud.com"
path = "/v1/kafka/{id}/firewalls"

[[path_param]]
name = "id"
required = true
type = "string"
description = "The ID of the Kafka cluster to attach."

[[body_param]]
name = "firewall_id"
required = true
type = "string"
description = "The ID of the firewall to attach. A cluster can have one firewall."

[[header]]
name = "Authorization"
description = "Bearer `$TOKEN`"
required = true
type = "string"

[[header]]
name = "Content-Type"
description = "application/json"
required = false
type = "string"
[/endpoint]

[responses]
[[response]]
status = 202
description = "Returns the Kafka cluster."
body = '''
{
  "id": "example",
  "name": "Example Kafka cluster",
  "type": "KA1",
  "broker_count": 50,
  "replication_factor": 1,
  "min_insync_replicas": 1,
  "usable_storage_gb": 1,
  "max_partitions": 1,
  "storage_budget_bytes": 1,
  "storage_budget_used_bytes": 1,
  "partition_count": 50,
  "engine_version": "1.4.2",
  "engine_patch_version": "1.4.2",
  "available_engine_versions": [
    "1.4.2"
  ],
  "status": "provisioning",
  "status_message": "example",
  "public_access": false,
  "endpoint": {
    "bootstrap_servers": "example",
    "hostname": "proxy.example.com",
    "port": 443,
    "security_protocol": "example",
    "sasl_mechanism": "example",
    "brokers": [
      {
        "node_id": 123456789,
        "hostname": "proxy.example.com"
      }
    ],
    "public_bootstrap_servers": "example",
    "public_hostname": "proxy.example.com",
    "public_port": 443,
    "public_brokers": [
      {
        "node_id": 123456789,
        "hostname": "proxy.example.com"
      }
    ]
  },
  "brokers": [
    {
      "id": "example",
      "node_id": 123456789,
      "status": "provisioning",
      "hostname": "proxy.example.com",
      "disk_used_bytes": 1,
      "under_replicated_partitions": 1,
      "private_ips": [
        {
          "network_id": "123456789",
          "ip_address": "example"
        }
      ],
      "last_seen_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "topics": [
    {
      "id": "example",
      "name": "Example",
      "partitions": 1,
      "replication_factor": 1,
      "retention_bytes": 1,
      "retention_ms": 1,
      "cleanup_policy": "delete",
      "max_message_bytes": 1,
      "budget_bytes": 1,
      "created_at": "2026-07-01T12:00:00.000Z",
      "updated_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "users": [
    {
      "id": "example",
      "username": "example",
      "default_user": false,
      "privileges": [
        {
          "topic_pattern": "example",
          "permission": "consume"
        }
      ],
      "created_at": "2026-07-01T12:00:00.000Z",
      "updated_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "network_ids": [
    "123456789"
  ],
  "firewall_ids": [
    "123456789"
  ],
  "term": "monthly",
  "created_at": "2026-07-01T12:00:00.000Z",
  "updated_at": "2026-07-01T12:00:00.000Z",
  "team_id": "t123",
  "metadata": {
    "example": "value"
  }
}
'''

[[response]]
status = 400
description = "The body isn't valid JSON."
body = '''
{
  "error": {
    "message": "Malformed JSON body.",
    "code": "bad_request"
  }
}
'''

[[response]]
status = 401
description = "The API token is missing or invalid."
body = '''
{
  "error": {
    "message": "Missing or invalid token.",
    "code": "unauthorized"
  }
}
'''

[[response]]
status = 402
description = "The organization hasn't made its first payment yet, and the request creates a resource we charge for. The code is `payment_required`. A request that creates a server, load balancer, object cache, database, reserved IP or volume can also return `first_purchase`. The `url` in `first_purchase` opens a page where you make the payment. The resource is created after the payment. The page works until `expires_at`, 24 hours after the response."
body = '''
{
  "error": {
    "message": "We require at least one successful credit card transaction before allowing billable actions via the API. This significantly helps us to prevent fraud. Once your first transaction is processed, you will be able to use the API unrestricted. Please add credit to your account at https://betterstack.com/settings/billing/card/new?credits=10&activate_api=true. Need help? We're here for you at hello@betterstack.com.",
    "code": "payment_required"
  }
}
'''

[[response]]
status = 403
description = "The request would go over a quota, with the code `quota_exceeded`. Or a read-only token tried to make a change, with the code `read_only_token`. Or a rule of the resource forbids it."
body = '''
{
  "error": {
    "message": "This token is read-only and cannot be used for write operations.",
    "code": "read_only_token"
  }
}
'''

[[response]]
status = 404
description = "The cluster's team has no firewall with this ID."

[[response]]
status = 409
description = "The cluster already has a firewall, with the code `firewall_limit_reached`. Or it has no brokers, with the code `kafka_unavailable`."

[[response]]
status = 422
description = "A value isn't valid, with the code `validation_failed`. The error's `details` list the messages for each field. A create or rescale that names a deprecated type with a replacement returns the code `type_deprecated`. The error's `details` then name the field, the deprecated type and its `replacement`."

[[response]]
status = 423
description = "We've locked the resource, with the code `locked`. Every change to a locked resource is refused, and so is a change that involves one."

[[response]]
status = 429
description = "Too many requests, with the code `rate_limited`. We limit requests per client IP and per organization, and some costly endpoints have a stricter limit. Wait as long as the `Retry-After` header says."

[[response]]
status = 500
description = "An unexpected, temporary error on our side, with the code `internal_error`. Try again."
body = '''
{
  "error": {
    "message": "The request could not be completed right now. Please try again in a few moments.",
    "code": "internal_error"
  }
}
'''

[[response]]
status = 503
description = "The zone has no capacity, with the code `no_capacity`. Or we couldn't set up or change the resource, with the code `orchestration_failed`. Or the organization is creating too many resources at the same time, with the code `concurrent_create_limit`. Try again after a short wait."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "id"
type = "string"
description = "The cluster's ID, a UUID."

[[param]]
name = "name"
type = "string"
description = "The cluster's name, at most 255 characters, unique among your organization's clusters that aren't destroyed or failed."

[[param]]
name = "type"
type = "string"
description = "The cluster's type, such as `KA1`."

[[param]]
name = "broker_count"
type = "integer"
description = "The number of brokers, `1` for development or `3` to survive the loss of a broker. Can't be changed after the cluster is created."

[[param]]
name = "replication_factor"
type = "integer"
description = "The number of copies of each partition, always equal to `broker_count`. Every broker stores every partition."

[[param]]
name = "min_insync_replicas"
type = "integer"
description = "The number of copies that must confirm a write, `1` with one broker and `2` with three."

[[param]]
name = "usable_storage_gb"
type = "integer"
description = "The storage for your topics on each broker, in GiB."

[[param]]
name = "max_partitions"
type = "integer"
description = "The most partitions the cluster's type allows across all topics."

[[param]]
name = "storage_budget_bytes"
type = "integer"
description = "The storage budget of each broker, in bytes. Every topic must fit in it."

[[param]]
name = "storage_budget_used_bytes"
type = "integer"
description = "The storage your topics reserve, in bytes. Each topic reserves its `retention_bytes` times its number of partitions, plus one segment for each partition."

[[param]]
name = "partition_count"
type = "integer"
description = "The number of partitions across all topics."

[[param]]
name = "engine_version"
type = "string"
description = "The Kafka version as major and minor, such as `4.4`."

[[param]]
name = "engine_patch_version"
type = "string or null"
description = "The exact Kafka release installed, such as `4.4.0`."

[[param]]
name = "available_engine_versions"
type = "array of strings"
description = "The version you can upgrade the cluster to, the next one we offer. The list is empty when the cluster runs the newest version."

[[param]]
name = "status"
type = "string"
description = "The cluster's state.<br/>Valid values:<br/>`provisioning`: We're starting the brokers and installing Kafka.<br/>`running`: The cluster is ready. Right after it's created, brokers can still be starting.<br/>`degraded`: A broker is down, partitions are missing copies or a disk is almost full. `status_message` says which.<br/>`rescaling`: We're changing the cluster's type.<br/>`upgrading`: We're upgrading the cluster to a newer Kafka version.<br/>`failed`: We couldn't create the cluster. `status_message` says why.<br/>`destroyed`: The cluster is destroyed."

[[param]]
name = "status_message"
type = "string or null"
description = "Why the cluster is in its current state, such as which broker is down, or `null` when there's nothing to report."

[[param]]
name = "public_access"
type = "boolean"
description = "Whether the cluster also has public endpoints. Clients connect with TLS and SCRAM on both the private and the public endpoints."

[[param]]
name = "endpoint"
type = "object"
description = "The addresses clients connect to, the bootstrap address and one for each broker. The fields that start with `public_` are only present when `public_access` is on. Clients must reach every broker, not only the bootstrap address."

[[param]]
name = "endpoint.bootstrap_servers"
type = "string"
description = "The bootstrap servers."

[[param]]
name = "endpoint.hostname"
type = "string or null"
description = "The hostname."

[[param]]
name = "endpoint.port"
type = "integer"
description = "The port."

[[param]]
name = "endpoint.security_protocol"
type = "string"
description = "The security protocol."

[[param]]
name = "endpoint.sasl_mechanism"
type = "string"
description = "The sasl mechanism."

[[param]]
name = "endpoint.brokers"
type = "array of objects"
description = "The brokers."

[[param]]
name = "endpoint.brokers[].node_id"
type = "integer"
description = "The node id."

[[param]]
name = "endpoint.brokers[].hostname"
type = "string or null"
description = "The hostname."

[[param]]
name = "endpoint.public_bootstrap_servers"
type = "string"
description = "The public bootstrap servers."

[[param]]
name = "endpoint.public_hostname"
type = "string"
description = "The public hostname."

[[param]]
name = "endpoint.public_port"
type = "integer"
description = "The public port."

[[param]]
name = "endpoint.public_brokers"
type = "array of objects"
description = "The public brokers."

[[param]]
name = "endpoint.public_brokers[].node_id"
type = "integer"
description = "The node id."

[[param]]
name = "endpoint.public_brokers[].hostname"
type = "string"
description = "The hostname."

[[param]]
name = "brokers"
type = "array of objects"
description = "The cluster's brokers, with their addresses on your networks and their last reported health. All brokers have the same role."

[[param]]
name = "brokers[].id"
type = "string"
description = "The id."

[[param]]
name = "brokers[].node_id"
type = "integer"
description = "The node id."

[[param]]
name = "brokers[].status"
type = "string"
description = "Possible values: `provisioning`, `starting`, `running`, `down`."

[[param]]
name = "brokers[].hostname"
type = "string or null"
description = "The hostname."

[[param]]
name = "brokers[].disk_used_bytes"
type = "integer or null"
description = "The disk used bytes."

[[param]]
name = "brokers[].under_replicated_partitions"
type = "integer or null"
description = "The under replicated partitions."

[[param]]
name = "brokers[].private_ips"
type = "array of objects"
description = "The private ips."

[[param]]
name = "brokers[].private_ips[].network_id"
type = "string"
description = "The network id."

[[param]]
name = "brokers[].private_ips[].ip_address"
type = "string"
description = "The ip address."

[[param]]
name = "brokers[].last_seen_at"
type = "datetime or null"
description = "In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "topics"
type = "array of objects"
description = "The cluster's topics, ordered by name. Add, update or remove them with `betterstack kafka-topic`."

[[param]]
name = "topics[].id"
type = "string"
description = "The id."

[[param]]
name = "topics[].name"
type = "string"
description = "The name."

[[param]]
name = "topics[].partitions"
type = "integer"
description = "The partitions."

[[param]]
name = "topics[].replication_factor"
type = "integer"
description = "The replication factor."

[[param]]
name = "topics[].retention_bytes"
type = "integer"
description = "The retention bytes."

[[param]]
name = "topics[].retention_ms"
type = "integer"
description = "The retention ms."

[[param]]
name = "topics[].cleanup_policy"
type = "string"
description = "Possible values: `delete`, `compact`, `compact_delete`."

[[param]]
name = "topics[].max_message_bytes"
type = "integer"
description = "The max message bytes."

[[param]]
name = "topics[].budget_bytes"
type = "integer"
description = "The budget bytes."

[[param]]
name = "topics[].created_at"
type = "datetime or null"
description = "In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "topics[].updated_at"
type = "datetime or null"
description = "In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "users"
type = "array of objects"
description = "The cluster's users, ordered by username. Add, update or remove them with `betterstack kafka-user`, which also gets their passwords."

[[param]]
name = "users[].id"
type = "string"
description = "The id."

[[param]]
name = "users[].username"
type = "string"
description = "The username."

[[param]]
name = "users[].default_user"
type = "boolean"
description = "The default user."

[[param]]
name = "users[].privileges"
type = "array of objects"
description = "The privileges."

[[param]]
name = "users[].privileges[].topic_pattern"
type = "string"
description = "The topic pattern."

[[param]]
name = "users[].privileges[].permission"
type = "string"
description = "Possible values: `consume`, `produce`, `produce_consume`."

[[param]]
name = "users[].created_at"
type = "datetime or null"
description = "In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "users[].updated_at"
type = "datetime or null"
description = "In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "network_ids"
type = "array of strings"
description = "The IDs of your networks attached to every broker. Order doesn't matter."

[[param]]
name = "firewall_ids"
type = "array of strings"
description = "The ID of the firewall attached to every broker, at most one. Order doesn't matter."

[[param]]
name = "term"
type = "string"
description = "The billing term. Defaults to `monthly`.<br/>Valid values:<br/>`monthly`: Billed every month.<br/>`annual`: Paid for a year."

[[param]]
name = "created_at"
type = "datetime"
description = "When the cluster was created. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "updated_at"
type = "datetime"
description = "When the cluster was last updated. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

[[param]]
name = "team_id"
type = "string"
description = "The ID of the team that owns the cluster."

[[param]]
name = "metadata"
type = "object"
description = "Your tags, as an object of string keys and values."
[/params]
