# Claim a server from a pool

Claim the oldest warm server of the pool. The server is already running on the addresses it booted with, and the pool's default keys work at once. Keys in `ssh_keys` and a `root_password` the claim adds reach the server a few seconds later. The server has already booted, so a claim accepts no `user_data`, reserved IPs, server type or disk.

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

[[path_param]]
name = "id"
required = true
type = "string"
description = "The ID of the server pool to claim."

[[body_param]]
name = "name"
required = true
type = "string"
description = "The server's name, unique among the organization's live servers."

[[body_param]]
name = "ssh_keys"
type = "array of strings"
description = "The slugs of SSH keys of the pool's team to add to the pool's default keys."

[[body_param]]
name = "root_password"
default = "false"
type = "boolean"
description = "Whether to set a root password. The response shows the password once."

[[body_param]]
name = "metadata"
type = "object"
description = "Tags for the server, added to the pool's default tags. Accepts any keys."

[[body_param]]
name = "firewall_ids"
type = "array of strings"
description = "The ID of one firewall of the pool's team to attach. Refused when the pool's `defaults` already attach a firewall."

[[body_param]]
name = "network_ids"
type = "array of strings"
description = "The IDs of private networks of the pool's team to join. Each one gets a private IP and is attached shortly after the response, as when you create a server."

[[body_param]]
name = "subdomain"
default = "true"
type = "boolean"
description = "Whether the server gets its generic subdomain."

[[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 = 200
description = "Returns the server."
body = '''
{
  "root_password": "example"
}
'''

[[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 = "We couldn't find the pool, an SSH key, a firewall or a network. The error code is `not_found`."

[[response]]
status = 409
description = "The pool is disabled. The error code is `pool_disabled`."

[[response]]
status = 422
description = "The `name` is missing or taken, the request names more than one firewall, or the pool's `defaults` already attach a firewall. The error code is `validation_failed`."

[[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 pool has no warm server now. The error code is `pool_empty`. The pool grows its target, so try again shortly, or create a server."
[/responses]

[params]
title = "Response attributes"

[[param]]
name = "root_password"
type = "string"
description = "The root password, shown only this once, when the request sets `root_password` to `true`."
[/params]
