# Create a new role.

`POST /admin/roles`

Authentication (security requirement alternatives):

```json
[
  {
    "ApiKey": []
  }
]
```

- ApiKey: apiKey, header X-API-Key

Request body: application/json

Type: object

Schema: [Api_Admin_Role](https://sourcey-azuracast.pages.dev/docs/api/models/api-admin-role/index.md)

allOf:
  Reference: [HasLinks](https://sourcey-azuracast.pages.dev/docs/api/models/haslinks/index.md); Type: object

  Type: object
  
  - `id` (optional)
    Type: integer
    
    readOnly: true
  
  - `name` (optional)
    Type: string
    
    Example:
    
    ```json
    "Super Administrator"
    ```
  
  - `permissions` (optional)
    Reference: [Api_Admin_RolePermissions](https://sourcey-azuracast.pages.dev/docs/api/models/api-admin-rolepermissions/index.md); Type: object
  
  - `is_super_admin` (optional)
    Type: boolean
    
    Whether this role is the protected "Super Administrator" role.
    
    readOnly: true

Responses:

- 200: Success

Content type: application/json

Type: object

Schema: [Api_Admin_Role](https://sourcey-azuracast.pages.dev/docs/api/models/api-admin-role/index.md)

allOf:
  Reference: [HasLinks](https://sourcey-azuracast.pages.dev/docs/api/models/haslinks/index.md); Type: object

  Type: object
  
  - `id` (optional)
    Type: integer
    
    readOnly: true
  
  - `name` (optional)
    Type: string
    
    Example:
    
    ```json
    "Super Administrator"
    ```
  
  - `permissions` (optional)
    Reference: [Api_Admin_RolePermissions](https://sourcey-azuracast.pages.dev/docs/api/models/api-admin-rolepermissions/index.md); Type: object
  
  - `is_super_admin` (optional)
    Type: boolean
    
    Whether this role is the protected "Super Administrator" role.
    
    readOnly: true

- 404: Record not found.

Content type: application/json

Type: object

Schema: [Api_Error](https://sourcey-azuracast.pages.dev/docs/api/models/api-error/index.md)

- `code` (required)
  Type: integer
  
  The numeric code of the error.
  
  Example:
  
  ```json
  500
  ```

- `type` (required)
  Type: string
  
  The programmatic class of error.
  
  Example:
  
  ```json
  "NotLoggedInException"
  ```

- `message` (required)
  Type: string
  
  The text description of the error.
  
  Example:
  
  ```json
  "Error description."
  ```

- `formatted_message` (required)
  Type: string; nullable
  
  The HTML-formatted text description of the error.
  
  Example:
  
  ```json
  "<b>Error description.</b><br>Detailed error text."
  ```

- `extra_data` (required)
  Type: array
  
  Stack traces and other supplemental data.
  
  Items:
    Type: any

- `success` (required)
  Type: boolean
  
  Used for API calls that expect an \Entity\Api\Status type response.
  
  Example:
  
  ```json
  false
  ```

- 500: A generic exception has occurred.

Content type: application/json

Type: object

Schema: [Api_Error](https://sourcey-azuracast.pages.dev/docs/api/models/api-error/index.md)

- `code` (required)
  Type: integer
  
  The numeric code of the error.
  
  Example:
  
  ```json
  500
  ```

- `type` (required)
  Type: string
  
  The programmatic class of error.
  
  Example:
  
  ```json
  "NotLoggedInException"
  ```

- `message` (required)
  Type: string
  
  The text description of the error.
  
  Example:
  
  ```json
  "Error description."
  ```

- `formatted_message` (required)
  Type: string; nullable
  
  The HTML-formatted text description of the error.
  
  Example:
  
  ```json
  "<b>Error description.</b><br>Detailed error text."
  ```

- `extra_data` (required)
  Type: array
  
  Stack traces and other supplemental data.
  
  Items:
    Type: any

- `success` (required)
  Type: boolean
  
  Used for API calls that expect an \Entity\Api\Status type response.
  
  Example:
  
  ```json
  false
  ```

## Examples

### cURL

```bash
curl -X POST 'https://demo.azuracast.com/api/admin/roles' \
  -H 'X-API-Key: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "name": "Super Administrator",
  "permissions": {
    "global": [
      "administer all"
    ],
    "station": [
      {
        "id": 0,
        "permissions": [
          "administer all"
        ]
      }
    ]
  }
}'
```

### JavaScript

```javascript
const body = `{
  "name": "Super Administrator",
  "permissions": {
    "global": [
      "administer all"
    ],
    "station": [
      {
        "id": 0,
        "permissions": [
          "administer all"
        ]
      }
    ]
  }
}`;

const response = await fetch('https://demo.azuracast.com/api/admin/roles', {
  method: 'POST',
  headers: {
    'X-API-Key': 'YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "name": "Super Administrator",
  "permissions": {
    "global": [
      "administer all"
    ],
    "station": [
      {
        "id": 0,
        "permissions": [
          "administer all"
        ]
      }
    ]
  }
}'''

response = requests.post(
    'https://demo.azuracast.com/api/admin/roles',
    data=body.encode('utf-8'),
    headers={
        'X-API-Key': 'YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
