# Create an invite

`POST /invites.json`

Authentication: no security requirement declared for this operation.

Parameters:

- `Api-Key` (header, string, required)
  Type: string

- `Api-Username` (header, string, required)
  Type: string

Request body: application/json

Type: object

- `email` (optional)
  Type: string
  
  required for email invites only
  
  Example:
  
  ```json
  "not-a-user-yet@example.com"
  ```

- `skip_email` (optional)
  Type: boolean
  
  default: false

- `custom_message` (optional)
  Type: string
  
  optional, for email invites

- `max_redemptions_allowed` (optional)
  Type: integer
  
  optional, for link invites
  
  default: 1
  
  Example:
  
  ```json
  5
  ```

- `topic_id` (optional)
  Type: integer

- `group_ids` (optional)
  Type: string
  
  Optional, either this or `group_names`. Comma separated
  list for multiple ids.
  
  Example:
  
  ```json
  "42,43"
  ```

- `group_names` (optional)
  Type: string
  
  Optional, either this or `group_ids`. Comma separated
  list for multiple names.
  
  Example:
  
  ```json
  "foo,bar"
  ```

- `expires_at` (optional)
  Type: string
  
  optional, if not supplied, the invite_expiry_days site
  setting is used

Additional properties: false

Responses:

- 200: success response

Content type: application/json

Type: object

- `id` (required)
  Type: integer
  
  Example:
  
  ```json
  42
  ```

- `invite_key` (required)
  Type: string

- `link` (required)
  Type: string
  
  Example:
  
  ```json
  "http://example.com/invites/9045fd767efe201ca60c6658bcf14158"
  ```

- `description` (required)
  Type: string; nullable

- `email` (required)
  Type: string
  
  Example:
  
  ```json
  "not-a-user-yet@example.com"
  ```

- `domain` (required)
  Type: string; nullable

- `emailed` (required)
  Type: boolean
  
  Example:
  
  ```json
  false
  ```

- `can_delete_invite` (required)
  Type: boolean

- `custom_message` (required)
  Type: string; nullable
  
  Example:
  
  ```json
  "Hello world!"
  ```

- `created_at` (required)
  Type: string
  
  Example:
  
  ```json
  "2021-01-01T12:00:00.000Z"
  ```

- `updated_at` (required)
  Type: string
  
  Example:
  
  ```json
  "2021-01-01T12:00:00.000Z"
  ```

- `expires_at` (required)
  Type: string
  
  Example:
  
  ```json
  "2021-02-01T12:00:00.000Z"
  ```

- `expired` (required)
  Type: boolean
  
  Example:
  
  ```json
  false
  ```

- `grants_admin` (required)
  Type: boolean
  
  Example:
  
  ```json
  false
  ```

- `grants_moderator` (required)
  Type: boolean
  
  Example:
  
  ```json
  false
  ```

- `topics` (required)
  Type: Array<object>
  
  Example:
  
  ```json
  []
  ```
  
  Items:
    Type: object

- `groups` (required)
  Type: Array<object>
  
  Example:
  
  ```json
  []
  ```
  
  Items:
    Type: object

Additional properties: false

## Examples

### cURL

```bash
curl -X POST 'https://discourse.example.com/invites.json' \
  -H 'Api-Key: string' \
  -H 'Api-Username: string' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "email": "not-a-user-yet@example.com",
  "skip_email": false,
  "custom_message": "string",
  "max_redemptions_allowed": 5,
  "topic_id": 0,
  "group_ids": "42,43",
  "group_names": "foo,bar",
  "expires_at": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "email": "not-a-user-yet@example.com",
  "skip_email": false,
  "custom_message": "string",
  "max_redemptions_allowed": 5,
  "topic_id": 0,
  "group_ids": "42,43",
  "group_names": "foo,bar",
  "expires_at": "string"
}`;

const response = await fetch('https://discourse.example.com/invites.json', {
  method: 'POST',
  headers: {
    'Api-Key': 'string',
    'Api-Username': 'string',
    'Content-Type': 'application/json',
  },
  body,
});

const data = await response.text();
```

### Python

```python
import requests

body = '''{
  "email": "not-a-user-yet@example.com",
  "skip_email": false,
  "custom_message": "string",
  "max_redemptions_allowed": 5,
  "topic_id": 0,
  "group_ids": "42,43",
  "group_names": "foo,bar",
  "expires_at": "string"
}'''

response = requests.post(
    'https://discourse.example.com/invites.json',
    data=body.encode('utf-8'),
    headers={
        'Api-Key': 'string',
        'Api-Username': 'string',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
