Attach an SSH key
Add the key to the root user's authorized_keys on running servers in this zone. We add it in the background, usually within seconds. Each server records ssh_key_attached or ssh_key_attach_failed in its events. The key shows in the server's ssh_keys at once, and a later restore or rescue keeps it. Attaching a key a server already has adds it again.
The slug of the key. Dots are part of the slug.
The ID of the team that owns the key. Send it when more than one of your teams has a key with this slug.
Bearer $TOKEN
application/json
The IDs of the servers to attach the key to. When one of them doesn't exist or can't get the key now, the request is refused and nothing changes. A repeated ID counts once.
Whether to attach the key to every server in this zone. A server that can't get the key now is skipped and listed with a reason. Send either all or server_ids, never both.
{
"servers": {
"queued": [
"example"
],
"skipped": [
{
"server_id": "123456789",
"reason": "kubernetes_managed"
}
]
}
}
{
"error": {
"message": "Malformed JSON body.",
"code": "bad_request"
}
}
{
"error": {
"message": "Missing or invalid token.",
"code": "unauthorized"
}
}
{
"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"
}
}
{
"error": {
"message": "This token is read-only and cannot be used for write operations.",
"code": "read_only_token"
}
}
{
"error": {
"message": "The request could not be completed right now. Please try again in a few moments.",
"code": "internal_error"
}
}
Returns the SSH key.
The body isn't valid JSON.
The API token is missing or invalid.
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.
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.
No key with this slug exists in your teams, or a server in server_ids doesn't exist or your token can't access it. The code is not_found.
A server in server_ids isn't running, with the code server_not_running. Or it's a Kubernetes worker node, with the code kubernetes_managed.
The request has neither or both of server_ids and all, or server_ids isn't a list of server IDs with at least one, with the code validation_failed. Or more than one of your teams has a key with this slug and the request has no team_id, with the code team_required.
A server in server_ids is locked. The code is locked.
Attach and detach share a limit of 30 requests per organization per minute. The code is rate_limited.
An unexpected, temporary error on our side, with the code internal_error. Try again.
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.
What we did with each server.
The IDs of the servers we're changing.
The servers we skipped with all, each with a reason, empty when you send server_ids.
The ID of the skipped server.
Why we skipped the server.
Valid values:kubernetes_managed: The server is a Kubernetes worker node.locked: The server is locked.server_not_running: The server isn't running.