# Create a token

`POST https://api-vod-express.syncwords.com/v1/token/create`

Create a token

Exchanges your API key pair for the bearer token every other call carries; it needs no token itself. The token belongs to your organization and works on the SyncWords Live API too, as one from the Live API works here. When a token expires, create another: there is no refresh. Not counted against your rate limit.

**Guide:** [Authentication](/vod-express/authentication)

## Request body

Example:

```json
{
  "username": "YOUR_PUBLIC_KEY",
  "password": "YOUR_SECRET_KEY"
}
```

Schema:

```json
{
  "$ref": "#/components/schemas/TokenRequest"
}
```

## Responses

### 200

OK

Example:

```json
{
  "access_token": "482|kJq8vN3mX2pL7rT5wY9zB4cF6hD1sA0gE8uI2oP",
  "token_type": "Bearer",
  "expires_in": 1800
}
```

Schema:

```json
{
  "$ref": "#/components/schemas/Token"
}
```

### 401

The key pair matches no account: `invalid_credentials`.

Example:

```json
{
  "message": "Invalid login details",
  "code": "invalid_credentials"
}
```

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 413

The body is over 2 MB: `payload_too_large`.

Example:

```json
{
  "message": [
    "The request body is too large."
  ],
  "code": "payload_too_large"
}
```

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 415

The body is neither JSON nor YAML: `unsupported_media_type`.

Example:

```json
{
  "message": [
    "Send the body as JSON (Content-Type: application/json) or YAML (Content-Type: application/yaml)."
  ],
  "code": "unsupported_media_type"
}
```

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 422

`username` or `password` is missing, or not a string: `validation_failed`.

Example:

```json
{
  "message": "The password field is required.",
  "code": "validation_failed",
  "errors": {
    "password": [
      "The password field is required."
    ]
  }
}
```

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

### 429

The same wrong key pair, sent too often in a minute: `too_many_requests`. Wait the seconds `Retry-After` says.

Example:

```json
{
  "message": [
    "Too Many Attempts."
  ],
  "code": "too_many_requests"
}
```

Schema:

```json
{
  "$ref": "#/components/schemas/Error"
}
```

## Schemas

### TokenRequest

`#/components/schemas/TokenRequest`

```json
{
  "type": "object",
  "required": [
    "username",
    "password"
  ],
  "properties": {
    "username": {
      "type": "string",
      "maxLength": 255,
      "description": "Your public key."
    },
    "password": {
      "type": "string",
      "maxLength": 255,
      "description": "Your secret key."
    }
  }
}
```

### Token

`#/components/schemas/Token`

```json
{
  "type": "object",
  "required": [
    "access_token",
    "token_type"
  ],
  "properties": {
    "access_token": {
      "type": "string",
      "description": "Send it as `Authorization: Bearer <access_token>`."
    },
    "token_type": {
      "const": "Bearer"
    },
    "expires_in": {
      "type": "integer",
      "description": "Seconds until the token expires. Absent where tokens do not expire by age."
    }
  }
}
```

### Error

`#/components/schemas/Error`

```json
{
  "type": "object",
  "required": [
    "message",
    "code"
  ],
  "properties": {
    "message": {
      "description": "For people. A string, or an array of one string on some statuses: read it as `Array.isArray(m) ? m[0] : m`.",
      "oneOf": [
        {
          "type": "string"
        },
        {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      ]
    },
    "code": {
      "description": "For programs: stable, one per situation. See the Errors guide.",
      "enum": [
        "bad_request",
        "invalid_output_path",
        "invalid_idempotency_key",
        "unauthenticated",
        "invalid_credentials",
        "forbidden",
        "vod_express_not_enabled",
        "account_restricted",
        "not_found",
        "project_not_found",
        "file_not_found",
        "file_meta_not_found",
        "output_not_found",
        "feed_not_found",
        "upload_not_found",
        "webhook_not_found",
        "webhook_delivery_not_found",
        "aws_access_not_provisioned",
        "storage_connection_not_found",
        "method_not_allowed",
        "conflict",
        "file_exists",
        "project_reads_feed",
        "project_reads_folder",
        "file_processing",
        "project_config_locked",
        "idempotency_in_progress",
        "storage_connection_in_use",
        "payload_too_large",
        "unsupported_media_type",
        "validation_failed",
        "service_start_failed",
        "idempotency_key_reused",
        "webhook_limit_reached",
        "storage_failed",
        "storage_connection_check_failed",
        "storage_connection_folder_only",
        "storage_prefix_taken",
        "build_without_storage_connections",
        "build_has_no_schema",
        "too_many_requests",
        "internal_error",
        "bad_gateway",
        "service_stop_failed",
        "aws_access_failed",
        "platform_unavailable",
        "service_unavailable",
        "build_list_unavailable"
      ]
    },
    "errors": {
      "type": "object",
      "description": "On a 422: each field’s messages, keyed by field name, or by JSON pointer inside `config`.",
      "additionalProperties": {
        "type": "array",
        "items": {
          "type": "string"
        }
      }
    }
  }
}
```
