# Create a new project token

`POST /api/v1/projects/{project}/roles/{role}/token`

Authentication (security requirement alternatives):

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

- bearer: apiKey, header Authorization. A token sent as `Authorization: Bearer <token>`. [API Docs](https://sourcey-argocd.pages.dev/developer-guide/api-docs/index.md#authorization) shows how to get one.

Parameters:

- `project` (path, string, required)
  Type: string

- `role` (path, string, required)
  Type: string

Request body: application/json (required)

Type: object

ProjectTokenCreateRequest defines project token creation parameters.

Schema: [projectProjectTokenCreateRequest](https://sourcey-argocd.pages.dev/api/models/projectprojecttokencreaterequest/index.md)

- `description` (optional)
  Type: string

- `expiresIn` (optional)
  Type: integer, int64

- `id` (optional)
  Type: string

- `project` (optional)
  Type: string

- `role` (optional)
  Type: string

Responses:

- 200: A successful response.

Content type: application/json

Type: object

ProjectTokenResponse wraps the created token or returns an empty string if deleted.

Schema: [projectProjectTokenResponse](https://sourcey-argocd.pages.dev/api/models/projectprojecttokenresponse/index.md)

- `token` (optional)
  Type: string

- default: An unexpected error response.

Content type: application/json

Type: object

Schema: [runtimeError](https://sourcey-argocd.pages.dev/api/models/runtimeerror/index.md)

- `code` (optional)
  Type: integer, int32

- `details` (optional)
  Type: array
  
  Items:
    Reference: [protobufAny](https://sourcey-argocd.pages.dev/api/models/protobufany/index.md); Type: object

- `error` (optional)
  Type: string

- `message` (optional)
  Type: string

## Examples

### cURL

```bash
curl -X POST 'https://argocd.example.com/api/v1/projects/string/roles/string/token' \
  -H 'Authorization: YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  --data-raw '{
  "description": "string",
  "expiresIn": 0,
  "id": "string",
  "project": "string",
  "role": "string"
}'
```

### JavaScript

```javascript
const body = `{
  "description": "string",
  "expiresIn": 0,
  "id": "string",
  "project": "string",
  "role": "string"
}`;

const response = await fetch('https://argocd.example.com/api/v1/projects/string/roles/string/token', {
  method: 'POST',
  headers: {
    'Authorization': 'YOUR_TOKEN',
    'Content-Type': 'application/json',
  },
  body,
});

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

### Python

```python
import requests

body = '''{
  "description": "string",
  "expiresIn": 0,
  "id": "string",
  "project": "string",
  "role": "string"
}'''

response = requests.post(
    'https://argocd.example.com/api/v1/projects/string/roles/string/token',
    data=body.encode('utf-8'),
    headers={
        'Authorization': 'YOUR_TOKEN',
        'Content-Type': 'application/json',
    },
)
print(response.text)
```
