# Invite a person to Praecise, once, for one of the caller's own people

`POST /api/invitations` · Praecise account · Account

For the server of a Praecise product that adds someone to an organisation or a project by address. When the address has no Praecise account, the account service mints a single-use invite code bound to that address, valid 30 days, and mails it itself, saying who invited them and to what; the code is never returned to the caller. Only the products the account service lists in ACCOUNT_INVITERS may call; with none listed, the call answers 503. Keep the person as pending under the address, and make them a member when that address first signs in to you (the `email` claim is confirmed). Limited to 60 calls a minute for each product and 100 invitations a day for each inviting person.

- Callers: The servers of the products listed in ACCOUNT_INVITERS (first: Praecise Spaces).

## Request body

`application/json`

```json
{
  "type": "object",
  "required": [
    "email",
    "invited_by"
  ],
  "additionalProperties": false,
  "properties": {
    "email": {
      "type": "string",
      "format": "email",
      "description": "The person to invite."
    },
    "invited_by": {
      "type": "string",
      "format": "uuid",
      "description": "The account id (`sub`) of the person inviting. They must have signed in to the caller."
    },
    "organisation": {
      "type": "string",
      "maxLength": 120,
      "description": "What they are invited to, by its display name, on one line. Shown in the mail."
    },
    "organisation_id": {
      "type": "string",
      "pattern": "^[A-Za-z0-9._:-]{1,120}$",
      "description": "The caller's own id for it. Kept with the invitation, never shown."
    }
  }
}
```

## Responses

- `200`: Nothing was sent: the address already has a Praecise account (`has-account`: add them), or this product invited it within the last day (`already-invited`).
- `201`: The invitation was sent.
- `400`: A field is missing or malformed.
- `401`: No valid client id and secret.
- `403`: This client may not invite people, or `invited_by` has not signed in to it.
- `429`: Over 60 a minute for the product, or 100 a day for the inviting person. `Retry-After` says when to try again.
- `502`: The mail could not be sent. Nothing was kept; try again later.
- `503`: Invitations by products are not switched on.

## Example

```sh
curl -X POST 'https://accounts.praecise.com/api/invitations' \
  -H 'Authorization: Basic $KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "email": "name@example.com",
  "invited_by": "string"
}'
```
