# Example - REST session

Prerequisite: an account key with scope `manage`, created in the cabinet under Agents.

## Create a subscription

```
curl -sS -X POST https://api.plsk.org/v1/subscriptions \
  -H "X-API-Key: $PLSA" \
  -H "Idempotency-Key: demo-1" \
  -H "content-type: application/json" \
  -d '{"name": "demo"}'
```

Status 201. The response contains `id`, `hostname` and `status`. Poll `GET /v1/subscriptions/{id}` until `status` is `ready`.

## Issue a subscription key

```
curl -sS -X POST https://api.plsk.org/v1/subscriptions/{id}/keys \
  -H "X-API-Key: $PLSA" \
  -H "content-type: application/json" \
  -d '{"lifetime": "1d"}'
```

Status 201. The response contains `token` (`plsk_…`), returned once.

## Call the Plesk REST API

```
curl -sS https://api.plsk.org/api/plesk/v2/domains -H "X-API-Key: $KEY"

curl -sS -X PUT "https://api.plsk.org/api/plesk/v2/domains/{domainId}/fs/content?path=index.html" \
  -H "X-API-Key: $KEY" \
  -H "content-type: application/json" \
  -d '{"encoding": "plain", "content": "<h1>Hello</h1>"}'
```

## Delete

```
curl -sS -X DELETE https://api.plsk.org/v1/subscriptions/{id} -H "X-API-Key: $PLSA"
```

Status 202.
