# Shako API

> The REST API of Shako for programs: VMs, ports, backups, secrets, devices, credit and tenants, with an API key.

Each page also has its markdown: add .md to its URL. The errors: https://shako.dev/api/errors.md.

## Rules

| Rule | Value |
|---|---|
| Base URL | https://api.shako.dev. JSON in the body of a request, JSON in each answer. |
| Key | Authorization: Bearer <API key> on each request. |
| Tenant | The path of a VM, a secret, a device or the credit names its tenant: /v1/tenants/{tenant}/... |
| Create | 201 with the new object. |
| List | 200 with {"data": [...]}. |
| Delete | 200 with the names of the path and "deleted": true. |
| Error | The HTTP status and {"error": {"code": "...", "message": "..."}}. Branch on the code. |
| Time | A time is a Unix time in seconds. Money is US dollars. |

## API key

```sh
# A key for the tenant acme, for 90 days. Shako shows the key only once.
shako api-key create ci --role contributor --tenant acme --days 90

# A key for each tenant that you own, with the credit and the invoices.
shako api-key create ops --role owner --account

# Your keys.
shako api-key ls

# The key stops at once.
shako api-key rm <id>
```

In the workspace: Account settings › API keys (https://workspace.shako.dev). The roles: https://shako.dev/docs/access-control.md.

## SDK

```sh
# Python
pip install shako-sdk

# JavaScript
npm install shako-sdk
```

A method for each endpoint: https://shako.dev/sdk.md.

## Example

```sh
# The VMs of the tenant acme.
curl "https://api.shako.dev/v1/tenants/acme/vms" -H "Authorization: Bearer $SHAKO_API_KEY"
```

## Resources

| Resource | Endpoints |
|---|---|
| [VMs](https://shako.dev/api/vms.md) | [Create a VM](https://shako.dev/api/vms/create.md), [List VMs](https://shako.dev/api/vms/list.md), [Get a VM](https://shako.dev/api/vms/get.md), [Update a VM](https://shako.dev/api/vms/update.md), [Delete a VM](https://shako.dev/api/vms/delete.md), [Put a VM to sleep](https://shako.dev/api/vms/sleep.md), [Wake a VM](https://shako.dev/api/vms/wake.md), [Restart a VM](https://shako.dev/api/vms/restart.md), [Resize a VM](https://shako.dev/api/vms/resize.md), [Rename a VM](https://shako.dev/api/vms/rename.md), [Copy a VM](https://shako.dev/api/vms/copy.md), [Read the console](https://shako.dev/api/vms/logs.md), [List the crons](https://shako.dev/api/vms/crons.md) |
| [Ports](https://shako.dev/api/ports.md) | [List ports](https://shako.dev/api/ports/list.md), [Share a port](https://shako.dev/api/ports/create.md), [Stop sharing a port](https://shako.dev/api/ports/delete.md) |
| [Backups](https://shako.dev/api/backups.md) | [List backups](https://shako.dev/api/backups/list.md), [Back up now](https://shako.dev/api/backups/create.md), [Restore a backup](https://shako.dev/api/backups/restore.md), [Erase the backups](https://shako.dev/api/backups/delete.md) |
| [Screen links](https://shako.dev/api/screen-links.md) | [Create a screen link](https://shako.dev/api/screen-links/create.md), [Stop the screen links](https://shako.dev/api/screen-links/delete.md) |
| [Secrets](https://shako.dev/api/secrets.md) | [List secrets](https://shako.dev/api/secrets/list.md), [Set a secret](https://shako.dev/api/secrets/set.md), [Delete a secret](https://shako.dev/api/secrets/delete.md) |
| [Devices](https://shako.dev/api/devices.md) | [List devices](https://shako.dev/api/devices/list.md), [Add a device](https://shako.dev/api/devices/create.md), [Remove a device](https://shako.dev/api/devices/delete.md) |
| [Agent memory](https://shako.dev/api/memory.md) | [Get the agent memory](https://shako.dev/api/memory/get.md), [Update the agent memory](https://shako.dev/api/memory/update.md) |
| [Billing](https://shako.dev/api/billing.md) | [Read the usage](https://shako.dev/api/billing/usage.md), [Read the credit](https://shako.dev/api/billing/credit.md), [Top up the credit](https://shako.dev/api/billing/top-up.md), [Get an invoice](https://shako.dev/api/billing/invoice.md) |
| [Access](https://shako.dev/api/access.md) | [List access](https://shako.dev/api/access/list.md), [Take a VM's access away](https://shako.dev/api/access/revoke-vm.md) |
| [Tenants](https://shako.dev/api/tenants.md) | [List tenants](https://shako.dev/api/tenants/list.md), [Create a tenant](https://shako.dev/api/tenants/create.md), [Delete a tenant](https://shako.dev/api/tenants/delete.md) |
| [Caller](https://shako.dev/api/caller.md) | [Who am I](https://shako.dev/api/caller/whoami.md), [List SSH keys](https://shako.dev/api/caller/ssh-keys.md) |
