# Networks, servers and people

Source: https://tiltas.openpanel.sh/docs/partner/networks

> Create a Network per organisation, join servers with Join keys, and remove people who leave.

The examples use these shell variables. Take the key from your secret store, never from a file in git.

```sh
TILTAS=https://tiltas.openpanel.sh/api/v1
AUTH="Authorization: Bearer $TILTAS_PARTNER_KEY"
```

## Create or find a Network

`PUT /partner/networks/{external_id}` finds or creates the Network of one organisation. `external_id` is your own id
for it: 1–128 letters, digits and `. _ : -`, starting with a letter or digit. The call is safe to repeat; a different
`name` renames the Network.

```sh
curl -sS -X PUT "$TILTAS/partner/networks/org_123" -H "$AUTH" \
  -H 'Content-Type: application/json' -d '{"name":"Acme"}'
```

```json
{ "account_id": "acc_x4tq9mzr2e", "name": "Acme", "domain": "acme-zr2e.ql.internal", "cidr": "100.64.0.0/11" }
```

- Store `account_id`: every `/accounts/{account_id}/…` route uses it.
- `domain` is the Network's DNS suffix. Devices and Services are `<name>.<domain>`. It never changes.
- `name` is 1–60 **bytes** of UTF-8 after trimming. Cut by bytes, not characters.
- Device addresses come from `cidr`. Addresses are unique within one Network only.

Inside a partner Network, every Device reaches every other Device on every port, as in one office network. Each
Service admits only who its `allowed` names: see [Services and access](/docs/partner/services-and-access).

`DELETE /partner/networks/{external_id}` removes the Network with every Device, Service, rule, Group, person, its
audit log and its undelivered events. It answers `204`, then `404` if you call it again.

## Join a server

A Join key lets a server join without a person. Create one per server, or one reusable key for a fleet:

```sh
curl -sS -X POST "$TILTAS/accounts/acc_x4tq9mzr2e/join-keys" -H "$AUTH" \
  -H 'Content-Type: application/json' \
  -d '{"name":"hel-box-1","expires_in_minutes":60,"groups":["grp_c9r4mwxt2s"]}'
```

| Field | Rule |
|---|---|
| `name` | Required. |
| `reusable` | Default `false`: the key works once. |
| `groups` | Groups the joining server is put in: its project tags. |
| `expires_in_minutes` | 5–129,600 (90 days). |
| `expires_in_days` | 1–90. Without either, the key lasts 7 days. |

The answer carries `secret` and `install_command` once. Run the command on the server; the installer joins it. The
server then appears in `GET /accounts/{account_id}/devices`, and gets its `address` a few seconds later, when it
registers. With a [webhook](/docs/partner/webhooks), you receive `device.joined` at that moment.

Revoke a key you no longer need with `DELETE /accounts/{account_id}/join-keys/{key_id}`. Servers that joined with it
stay.

## Rename, tag or remove a Device

```sh
# rename, and set its project tags (Servers only; a full replacement)
curl -sS -X PATCH "$TILTAS/accounts/acc_x4tq9mzr2e/devices/dev_n3w8kzq5cb" -H "$AUTH" \
  -H 'Content-Type: application/json' -d '{"name":"hel-box-1","groups":["grp_c9r4mwxt2s"]}'

# remove: it leaves the Coordinator at once, with the Services it hosts
curl -sS -X DELETE "$TILTAS/accounts/acc_x4tq9mzr2e/devices/dev_n3w8kzq5cb" -H "$AUTH"
```

## People

People become Members of a Network when you approve a sign-in for them (see
[Connecting people's Devices](/docs/partner/sign-ins)). They are keyed by your own person id and never sign in to
Tiltas.

When someone leaves the organisation:

```sh
curl -sS -X DELETE "$TILTAS/partner/networks/org_123/people/user_123" -H "$AUTH"
```

Their Devices leave the Network at once, together with any Services on them, and Groups and rules forget them. You
receive one `device.removed` event per Device, with `reason: person_removed`. The call answers `204` also when there
was nothing to remove, so you can call it for anyone.

## Audit log

Every action of a Partner key is in the Network's audit log, with actor type `partner`:

```sh
curl -sS "$TILTAS/accounts/acc_x4tq9mzr2e/audit-events?limit=50" -H "$AUTH"
```
