# API

## Authentication

Create a token under **Settings**, **API tokens**, and send it as a bearer token. A token acts for one team, can never do more than its owner's role allows, and has only the abilities ticked when it was made:

- **read servers**;
- **read apps**;
- **deploy**;
- **change apps**, which covers maintenance mode;
- **read logs**, for deploy logs;
- **read databases**.

Coresmith stores only a hash of each token, so it shows the token once, when you create it.

## Base address

On Coresmith Cloud the API lives at `https://app.coresmith.io/api/v1`. On self-hosted Coresmith, it's `/api/v1` on Coresmith's own address. Send `Accept: application/json`.

## Endpoints

| Method | Path                                  | Does                                                                   |
| ------ | ------------------------------------- | ---------------------------------------------------------------------- |
| GET    | `/servers`, `/servers/{id}`           | Lists servers, or shows one.                                           |
| GET    | `/projects`, `/projects/{id}`         | Lists projects, or shows one.                                          |
| GET    | `/applications`, `/applications/{id}` | Lists apps, or shows one.                                              |
| POST   | `/applications/{id}/deploy`           | Starts a deploy and answers 202 with its ID and status.                |
| PUT    | `/applications/{id}/maintenance`      | Turns maintenance mode on or off, with `{"enabled": true}` or `false`. |
| GET    | `/applications/{id}/deployments`      | Lists an app's deploys.                                                |
| GET    | `/applications/{id}/deployments/{id}` | Shows one deploy.                                                      |

In these paths, a server, project or app can be its `id` or its name from the end of its page's address, such as `shop`.

An app includes its `project_id` and its `tags`, and a server includes its `tags`. A project includes the apps and databases in it that you can see, each with its `id` and `name`.

## Errors and limits

A deploy reuses the packages the live release installed where it safely can. Send `{"fresh": true}` to install every package from scratch.

When Coresmith can't start a deploy, for example because one is already running, it answers 409 with a message that says why. Each person can make 120 requests a minute.
