Black Friday: 40% off for life · BLACKFRIDAY40Claim →
crabsmith Get started
Browse documentation
← All documentation

API

On this page

Everything you can do in the Crabsmith dashboard is also available through the REST API—handy for CI/CD scripts, custom automations, or provisioning servers in bulk.

Tokens

  1. Open Account settings from the account menu at the bottom of the sidebar (or More → Account on a phone) and create a named API token.
  2. Copy the token right away (it's only shown once) and keep it secret—it has the same permissions as your account.
  3. Revoke tokens anytime from Account settings. Changing your account password signs out other browsers, not your API tokens.

Send your token as a Bearer header against https://app.crabsmith.com/api/v1:

sh
export CRAB_URL="https://app.crabsmith.com"
export CRAB_TOKEN="your-api-token"

curl -fsS "$CRAB_URL/api/v1/me" -H "Authorization: Bearer $CRAB_TOKEN"

OpenAPI specification

Download the full OpenAPI 3.1 schema for your API client or code generator:

sh
curl -fsS "$CRAB_URL/api/v1/openapi.json" -H "Authorization: Bearer $CRAB_TOKEN"

Conventions

  • All JSON fields use snake_case, and timestamps are UTC.
  • Changes to a server return 202 Accepted with an operation.id—poll /api/v1/operations/{id}/wait?timeout=20 until its status is succeeded, failed, or cancelled.
  • Error responses use {"error":{"status":422,"message":"...","fields":{...}}}.

Example: server to live site

This Bash script (requires curl and jq) registers an existing Ubuntu server, runs setup, installs Caddy, creates an HTTP-only static site (https: "off"), and deploys a sample Hello from Crabsmith page.

Before running it:

  1. Authorize Crabsmith's SSH key on the server first: fetch the panel's public key from GET /api/v1/ssh-key and add it to ~/.ssh/authorized_keys for your login user (root or a passwordless sudo user).
  2. Pick your workspace: list workspaces with GET /api/v1/workspaces and set WORKSPACE_ID (if omitted, the script uses your last-used workspace from /api/v1/me).
bash
set -euo pipefail
: "${CRAB_URL:?Set the panel origin (e.g. https://app.crabsmith.com)}"
: "${CRAB_TOKEN:?Set an API token}"
: "${CRAB_HOST:?Set the server IP or hostname}"
: "${SERVER_NAME:?Set a server name}"
: "${SITE_DOMAIN:?Set a site domain}"

api() {
  curl -fsS "$CRAB_URL/api/v1$1" -H "Authorization: Bearer $CRAB_TOKEN" -H 'Content-Type: application/json' "${@:2}"
}

wait_operation() {
  local id state result
  id=$(jq -er '.operation.id')
  while :; do
    result=$(api "/operations/$id/wait?timeout=20")
    state=$(jq -r '.status' <<<"$result")
    case "$state" in
      succeeded) return ;;
      failed|cancelled)
        jq -r '.error // .status' <<<"$result" >&2
        api "/operations/$id/output?after=0" >&2
        return 1 ;;
    esac
  done
}

workspace=${WORKSPACE_ID:-$(api /me | jq -er '.workspace.id')}
body=$(jq -n --arg name "$SERVER_NAME" --arg host "$CRAB_HOST" --arg user "${CRAB_SSH_USER:-root}" --argjson port "${CRAB_SSH_PORT:-22}" '{name:$name,host:$host,user:$user,port:$port}')
server=$(api "/workspaces/$workspace/servers" -d "$body" | jq -er '.id')
api "/servers/$server/setup" -X POST | wait_operation
api "/servers/$server/services" -d '{"slug":"caddy"}' | wait_operation
body=$(jq -n --arg domain "$SITE_DOMAIN" '{preset:"static",domain:$domain,https:"off",deploy:false,deploy_script:"printf \"Hello from Crabsmith\\n\" > index.html"}')
created=$(api "/servers/$server/sites" -d "$body")
wait_operation <<<"$created"
site=$(jq -er '.site.id' <<<"$created")
api "/sites/$site/deploys" -X POST | wait_operation
curl -fsS "${SITE_URL:-http://$SITE_DOMAIN/}" -H "Host: $SITE_DOMAIN"

When the script finishes, it prints Hello from Crabsmith (and visiting http://$SITE_DOMAIN/ in a browser shows the same page). Switch the site's HTTPS mode to Auto in Settings once DNS points to your server.