# Create personal access token


[API catalog](/reference/api/) · [Docker Hub overview](/reference/api/hub/latest/) · [Product manual](https://docs.docker.com/docker-hub/) · [OpenAPI specification](/reference/api/hub/latest.yaml)

API version: 2-beta



`POST /v2/access-tokens`

Creates and returns a personal access token.

## Connection and access

[API connection and authentication guidance](/reference/api/hub/latest/#authentication)


Server: `https://hub.docker.com`

Effective security: alternatives are OR; schemes within an alternative are AND. An empty array declares no HTTP authentication requirement.

```json
[
  {
    "bearerAuth": []
  }
]
```
## Example request

Replace placeholders and provide the required credentials or request body.

```console
curl \
  --request POST \
  --header "Authorization: Bearer ${TOKEN}" \
  --header 'Accept: application/json' \
  --header 'Content-Type: application/json' \
  --data-raw '{
  "scopes": [
    "repo:read"
  ],
  "token_label": "My read only token"
}' \
  'https://hub.docker.com/v2/access-tokens'
```

## Parameters

## Request and responses

### Request  application/json




Schema:

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




Schema example:
```json
{
  "scopes": [
    "repo:read"
  ],
  "token_label": "My read only token"
}
```


### Response 201 application/json

Created


Schema:

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




Schema example:
```json
{
  "client_id": "HUB",
  "created_at": "2021-07-20T12:00:00.000000Z",
  "creator_ip": "127.0.0.1",
  "creator_ua": "some user agent",
  "expires_at": "2021-10-28T18:30:19.520861Z",
  "generated_by": "manual",
  "is_active": true,
  "last_used": null,
  "scopes": [
    "repo:read"
  ],
  "token": "a7a5ef25-8889-43a0-8cc7-f2a94268e861",
  "token_label": "My read only token",
  "uuid": "b30bbf97-506c-4ecd-aabc-842f3cb484fb"
}
```


### Response 400 application/json

Bad Request


Schema:

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




error:
```json
{
  "errinfo": null,
  "message": "bad request"
}
```


### Response 401 application/json

Unauthorized


Schema:

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




error:
```json
{
  "errinfo": null,
  "message": "unauthorized"
}
```


## Complete operation contract

```json
{
  "description": "Creates and returns a personal access token.",
  "operationId": "postV2AccessTokens",
  "requestBody": {
    "content": {
      "application/json": {
        "schema": {
          "$ref": "#/components/schemas/createAccessTokenRequest"
        }
      }
    },
    "required": true
  },
  "responses": {
    "201": {
      "content": {
        "application/json": {
          "schema": {
            "$ref": "#/components/schemas/createAccessTokensResponse"
          }
        }
      },
      "description": "Created"
    },
    "400": {
      "$ref": "#/components/responses/BadRequest"
    },
    "401": {
      "$ref": "#/components/responses/Unauthorized"
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "summary": "Create personal access token",
  "tags": [
    "access-tokens"
  ]
}
```

## Referenced schemas

- `#/components/responses/BadRequest`

- `#/components/responses/Unauthorized`

- [#/components/schemas/createAccessTokenRequest](/reference/api/hub/latest/schemas/createAccessTokenRequest/)

- [#/components/schemas/createAccessTokensResponse](/reference/api/hub/latest/schemas/createAccessTokensResponse/)




