# Attach a firewall to a load balancer

Attach a firewall to a load balancer. The firewall must be in the load balancer's team. A load balancer can have one firewall. The firewall's rules apply shortly after the response.

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

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

[[body_param]]
name = "firewall_id"
required = true
type = "string"
description = "The ID of the firewall to attach. Get it via `betterstack firewall list`."

[[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 load balancer."
body = '''
{
  "id": "example",
  "name": "Example load balancer",
  "type": "LB1",
  "algorithm": "round_robin",
  "status": "provisioning",
  "status_message": "example",
  "public_ips": [
    {
      "ip": "example",
      "type": "example"
    }
  ],
  "private_ips": [
    {
      "network_id": "123456789",
      "ip_address": "example"
    }
  ],
  "network_ids": [
    "123456789"
  ],
  "firewall_ids": [
    "123456789"
  ],
  "services": [
    {
      "id": 1,
      "protocol": "tcp",
      "listen_port": 443,
      "destination_port": 443,
      "redirect_http": false,
      "http_timeout_seconds": 180,
      "sticky_sessions": false,
      "sticky_cookie_name": "Example",
      "sticky_cookie_lifetime_seconds": 1,
      "proxy_protocol": "disabled",
      "certificate_ids": [
        "123456789"
      ],
      "target_health": [
        {
          "service_id": 123456789,
          "server_id": "123456789",
          "state": "up",
          "state_changed_at": "2026-07-01T12:00:00.000Z",
          "status_message": "example"
        }
      ],
      "health_check": {
        "protocol": "tcp",
        "port": 443,
        "interval_seconds": 180,
        "timeout_seconds": 180,
        "retries": 1,
        "domain": "example",
        "path": "example",
        "response": "example",
        "status_codes": "example",
        "tls": false
      },
      "created_at": "2026-07-01T12:00:00.000Z",
      "updated_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "targets": [
    {
      "id": 1,
      "type": "server",
      "server_id": "123456789",
      "selector": {
        "example": "value"
      },
      "use_private_ip": false,
      "created_at": "2026-07-01T12:00:00.000Z",
      "updated_at": "2026-07-01T12:00:00.000Z"
    }
  ],
  "config_applied_at": "2026-07-01T12:00:00.000Z",
  "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 resource doesn't exist, it's in another zone, or your token can't access it."
body = '''
{
  "error": {
    "message": "Resource not found.",
    "code": "not_found"
  }
}
'''

[[response]]
status = 409
description = "The resource's state doesn't allow the request, such as starting a running server or removing a placement group that still has servers."

[[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 load balancer's ID, a UUID."

[[param]]
name = "name"
type = "string"
description = "The load balancer's name."

[[param]]
name = "type"
type = "string"
description = "The load balancer's type, such as `LB1`."

[[param]]
name = "algorithm"
type = "string"
description = "How the load balancer picks a target for each connection.<br/>Valid values:<br/>`round_robin`: Sends each new connection to the next target in turn.<br/>`least_connections`: Sends each new connection to the target with the fewest open connections.<br/>`source_ip`: Sends all connections from one client IP to the same target."

[[param]]
name = "status"
type = "string"
description = "The load balancer's state.<br/>Valid values:<br/>`provisioning`: We're starting the load balancer.<br/>`running`: The load balancer is ready. `status_message` reports any problem. `config_applied_at` says when we last applied your configuration.<br/>`rescaling`: We're changing the load balancer's type. The load balancer returns to `running` even when the change didn't finish. The load balancer's events say how the change went.<br/>`failed`: We couldn't create the load balancer. `status_message` says why.<br/>`destroyed`: The load balancer is deleted."

[[param]]
name = "status_message"
type = "string or null"
description = "What went wrong while we created or configured the load balancer, or what's wrong with it now. Is `null` when there's nothing to report."

[[param]]
name = "public_ips"
type = "array of objects"
description = "The load balancer's public IP addresses, one IPv4 and one IPv6."

[[param]]
name = "public_ips[].ip"
type = "string"
description = "The ip."

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

[[param]]
name = "private_ips"
type = "array of objects"
description = "The load balancer's private IP in each attached network."

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

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

[[param]]
name = "network_ids"
type = "array of strings"
description = "The IDs of the networks attached to the load balancer. Order doesn't matter."

[[param]]
name = "firewall_ids"
type = "array of strings"
description = "The IDs of the firewalls attached to the load balancer, at most one. Order doesn't matter."

[[param]]
name = "services"
type = "array of objects"
description = "The services that listen for traffic, with their settings and the latest health of each target. Add, update or remove them with `betterstack load-balancer-service`."

[[param]]
name = "services[].id"
type = "integer"
description = "The id."

[[param]]
name = "services[].protocol"
type = "string"
description = "Possible values: `tcp`, `http`, `https`, `udp`."

[[param]]
name = "services[].listen_port"
type = "integer"
description = "The listen port."

[[param]]
name = "services[].destination_port"
type = "integer"
description = "The destination port."

[[param]]
name = "services[].redirect_http"
type = "boolean"
description = "The redirect http."

[[param]]
name = "services[].http_timeout_seconds"
type = "integer"
description = "The http timeout seconds."

[[param]]
name = "services[].sticky_sessions"
type = "boolean"
description = "The sticky sessions."

[[param]]
name = "services[].sticky_cookie_name"
type = "string"
description = "The sticky cookie name."

[[param]]
name = "services[].sticky_cookie_lifetime_seconds"
type = "integer"
description = "The sticky cookie lifetime seconds."

[[param]]
name = "services[].proxy_protocol"
type = "string"
description = "Possible values: `disabled`, `v1`, `v2`."

[[param]]
name = "services[].certificate_ids"
type = "array of strings"
description = "The certificate ids."

[[param]]
name = "services[].target_health"
type = "array of objects"
description = "The target health."

[[param]]
name = "services[].target_health[].service_id"
type = "integer"
description = "The service id."

[[param]]
name = "services[].target_health[].server_id"
type = "string"
description = "The server id."

[[param]]
name = "services[].target_health[].state"
type = "string"
description = "Possible values: `up`, `down`, `unknown`."

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

[[param]]
name = "services[].target_health[].status_message"
type = "string or null"
description = "The status message."

[[param]]
name = "services[].health_check"
type = "object"
description = "The health check."

[[param]]
name = "services[].health_check.protocol"
type = "string"
description = "Possible values: `tcp`, `http`."

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

[[param]]
name = "services[].health_check.interval_seconds"
type = "integer"
description = "The interval seconds."

[[param]]
name = "services[].health_check.timeout_seconds"
type = "integer"
description = "The timeout seconds."

[[param]]
name = "services[].health_check.retries"
type = "integer"
description = "The retries."

[[param]]
name = "services[].health_check.domain"
type = "string or null"
description = "The domain."

[[param]]
name = "services[].health_check.path"
type = "string"
description = "The path."

[[param]]
name = "services[].health_check.response"
type = "string or null"
description = "The response."

[[param]]
name = "services[].health_check.status_codes"
type = "string"
description = "The status codes."

[[param]]
name = "services[].health_check.tls"
type = "boolean"
description = "The tls."

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

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

[[param]]
name = "targets"
type = "array of objects"
description = "The targets you added. A `label_selector` target shows as one entry, not one per matching server."

[[param]]
name = "targets[].id"
type = "integer"
description = "The id."

[[param]]
name = "targets[].type"
type = "string"
description = "Possible values: `server`, `label_selector`."

[[param]]
name = "targets[].server_id"
type = "string or null"
description = "The server id."

[[param]]
name = "targets[].selector"
type = "object or null"
description = "The selector."

[[param]]
name = "targets[].use_private_ip"
type = "boolean"
description = "The use private ip."

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

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

[[param]]
name = "config_applied_at"
type = "datetime or null"
description = "When we last applied the configuration to the load balancer, or `null` until we first apply it. In ISO 8601 format, such as `2026-07-01T12:00:00Z`."

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

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

[[param]]
name = "updated_at"
type = "datetime"
description = "When the load balancer 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 load balancer."

[[param]]
name = "metadata"
type = "object"
description = "Your own tags as string pairs."
[/params]
