---
type: api
title: Create a service token
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v9/operation/operation-post-fleet-service-tokens
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/kibana/v9/operation/operation-post-fleet-service-tokens
products:
  - Kibana
---

# Create a service token

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/fleet/service_tokens`
- `POST` `/s/{space_id}/api/fleet/service_tokens`

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Create a Fleet Server service token. The token is used to enroll Fleet Server instances with Kibana.

## Required authorization

- Privileges: `fleet-agents-all`

## Authentication

- Api key: `Authorization: <value>`
  These APIs use key-based authentication. You must create an API key and use the encoded value in the request header. For example: `Authorization: ApiKey base64AccessApiKey`
- Basic: `Authorization: Basic <credentials>`

## Header parameters

- `kbn-xsrf` (string) — required
  A required header to protect against CSRF attacks

## Request body

`application/json`

- `remote` (boolean · default: false) — optional

## Responses

#### `200`

Successful response

`application/json`

- `name` (string)
- `value` (string)
#### `400`

Bad Request

`application/json`

- `attributes` (object)
- `error` (string)
- `errorType` (string)
- `message` (string)
- `statusCode` (number)
## Code examples

#### Console

```console
POST kbn:/api/fleet/service_tokens
{
  "remote": true
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/fleet/service_tokens" \
  -H "kbn-xsrf: true" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "remote": true
  }'
```

## Response examples

#### Post generate service token

The generated Fleet Server service token

```json
{
  "name": "elastic/fleet-server/token-1234567890",
  "value": "AAEAAWVsYXN0aWMvZmxlZXQtc2VydmVyL3Rva2VuLTEyMzQ1Njc4OTA6QUJDREVGR0hJSktMTU5P"
}
```

#### Generic error response

Example of a generic error response

```json
{
  "error": "Bad Request",
  "message": "An error message describing what went wrong",
  "statusCode": 400
}
```

