---
updatedAt: 2026-09-07T12:36:03.000Z
agentTools:
  projectIndex: https://apideveloper.compliancely.com/llms.txt
---

# Create Access and Refresh Tokens V2

<Callout icon="far fa-shield-check" theme="success">
  ### **Authentication Using Client Credentials**

  Compliancely now supports Client ID and Client Secret authentication as an alternative to account username and password for generating API access and refresh tokens.

  We recommend using client credentials for API integrations, as they provide authentication independent of your Compliancely account login credentials. This helps prevent integration disruptions when account passwords or email addresses change.
</Callout>


Authenticates a user using a valid Client ID and Client Secret, and returns a pair of tokens: an access token and a refresh token.

Refer to the [Authentication Guide](https://apideveloper.compliancely.com/docs/authentication) for the recommended process.

This API allows you to create or retrieve an access token and refresh token using your Client ID and Client Secret.  The `access_token` provided must be included in the Authorization header as a `Bearer` for all subsequent API requests, as shown below

```curl cURL
--header 'Authorization: Bearer {{access_token}}'
```

### Request & Response Format

```curl Option 1: Client Credentials (Recommended)
curl --location '{{base_url}}/api/v2/token/' \
--header 'Content-Type: application/json' \
--data-raw '{
  "client_id": "<client_id>",
  "client_secret": "<client_secret>"
}'
```
```curl Option 2: Username and Password (Existing Method)
curl --location '{{base_url}}/api/v2/token/' \
--header 'Content-Type: application/json' \
--data-raw '{
  "username": "<username>",
  "password": "<password>"
}'
```
```curl Response Format
{
    "access": "<access_token>",
    "access_expiry_seconds": <expires_in_seconds>,
    "refresh": "<refresh_token>",
    "refresh_expiry_seconds": <expires_in_seconds>
}
```
Both authentication methods use the same API endpoint.

### **Generate Client Credentials**

To generate your credentials:

1. Log in to the Compliancely portal.
2. Navigate to the Developer section.
3. Generate your Client ID and Client Secret.

Securely store the credentials and use them to authenticate through the existing Token API.

### Compatibility with Existing Integrations
To simplify the transition to client credentials, Compliancely currently provides a temporary compatibility option for integrations using the existing username and password request fields.

You can supply your Client ID and Client Secret through these fields without modifying your existing request structure:

```json Request
{
  "username": "<client_id>",
  "password": "<client_secret>"
}
```
This allows existing integrations to adopt client credentials with minimal development effort.

**Important**: This is a transitional compatibility option and may be discontinued in a future release. We recommend updating your integration to use the dedicated client_id and client_secret fields for long-term compatibility.

**Security Note**: Keep your Client Secret secure and do not expose it in frontend applications or client-side code.


### Validity

The `access_token` is valid for **1 hour**. After it expires, you can use the **[Access Token by Refresh Token](https://apideveloper.compliancely.com/reference/api_v2_token_refresh_create)** endpoint to obtain a new `access_token`.\
The refresh_token remains valid for **24 hours**.

Recommendation: Use the refresh token after the access_token expires to enhance overall security.

### Throttling

This API enforces throttling, allowing a maximum of 10 requests per minute (RPM). If you exceed this limit, the following error will be returned, and you will need to wait 10 minutes before retrying.

```json 429 Too Many Requests
{  
    "detail": "Your request has been throttled due to exceeding the allowed rate limit. Please wait for 10 minutes before trying again. If this issue persists, consider adjusting the request frequency or contact support for further assistance."  
}
```

# OpenAPI definition

````json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Get Access",
    "version": "1.0.0",
    "description": "Get Access APIs",
    "contact": {
      "name": "Compliancely Support",
      "email": "support@compliancely.com",
      "url": "https://compliancely.com"
    },
    "license": {
      "name": "Proprietary"
    }
  },
  "paths": {
    "/api/v2/token/": {
      "post": {
        "operationId": "api_v2_token_create",
        "description": "<Callout icon=\"far fa-shield-check\" theme=\"success\">\r\n  ### **Authentication Using Client Credentials**\r\n\r\n  Compliancely now supports Client ID and Client Secret authentication as an alternative to account username and password for generating API access and refresh tokens.\r\n\r\n  We recommend using client credentials for API integrations, as they provide authentication independent of your Compliancely account login credentials. This helps prevent integration disruptions when account passwords or email addresses change.\r\n</Callout>\r\n\r\n\r\nAuthenticates a user using a valid Client ID and Client Secret, and returns a pair of tokens: an access token and a refresh token.\r\n\r\nRefer to the [Authentication Guide](https://apideveloper.compliancely.com/docs/authentication) for the recommended process.\r\n\r\nThis API allows you to create or retrieve an access token and refresh token using your Client ID and Client Secret.  The `access_token` provided must be included in the Authorization header as a `Bearer` for all subsequent API requests, as shown below\r\n\r\n```curl cURL\r\n--header 'Authorization: Bearer {{access_token}}'\r\n```\r\n\r\n### Request & Response Format\r\n\r\n```curl Option 1: Client Credentials (Recommended)\r\ncurl --location '{{base_url}}/api/v2/token/' \\\r\n--header 'Content-Type: application/json' \\\r\n--data-raw '{\r\n  \"client_id\": \"<client_id>\",\r\n  \"client_secret\": \"<client_secret>\"\r\n}'\r\n```\r\n```curl Option 2: Username and Password (Existing Method)\r\ncurl --location '{{base_url}}/api/v2/token/' \\\r\n--header 'Content-Type: application/json' \\\r\n--data-raw '{\r\n  \"username\": \"<username>\",\r\n  \"password\": \"<password>\"\r\n}'\r\n```\r\n```curl Response Format\r\n{\r\n    \"access\": \"<access_token>\",\r\n    \"access_expiry_seconds\": <expires_in_seconds>,\r\n    \"refresh\": \"<refresh_token>\",\r\n    \"refresh_expiry_seconds\": <expires_in_seconds>\r\n}\r\n```\r\nBoth authentication methods use the same API endpoint.\r\n\r\n### **Generate Client Credentials**\r\n\r\nTo generate your credentials:\r\n\r\n1. Log in to the Compliancely portal.\r\n2. Navigate to the Developer section.\r\n3. Generate your Client ID and Client Secret.\r\n\r\nSecurely store the credentials and use them to authenticate through the existing Token API.\r\n\r\n### Compatibility with Existing Integrations\r\nTo simplify the transition to client credentials, Compliancely currently provides a temporary compatibility option for integrations using the existing username and password request fields.\r\n\r\nYou can supply your Client ID and Client Secret through these fields without modifying your existing request structure:\r\n\r\n```json Request\r\n{\r\n  \"username\": \"<client_id>\",\r\n  \"password\": \"<client_secret>\"\r\n}\r\n```\r\nThis allows existing integrations to adopt client credentials with minimal development effort.\r\n\r\n**Important**: This is a transitional compatibility option and may be discontinued in a future release. We recommend updating your integration to use the dedicated client_id and client_secret fields for long-term compatibility.\r\n\r\n**Security Note**: Keep your Client Secret secure and do not expose it in frontend applications or client-side code.\r\n\r\n\r\n### Validity\r\n\r\nThe `access_token` is valid for **1 hour**. After it expires, you can use the **[Access Token by Refresh Token](https://apideveloper.compliancely.com/reference/api_v2_token_refresh_create)** endpoint to obtain a new `access_token`.\\\r\nThe refresh_token remains valid for **24 hours**.\r\n\r\nRecommendation: Use the refresh token after the access_token expires to enhance overall security.\r\n\r\n### Throttling\r\n\r\nThis API enforces throttling, allowing a maximum of 10 requests per minute (RPM). If you exceed this limit, the following error will be returned, and you will need to wait 10 minutes before retrying.\r\n\r\n```json 429 Too Many Requests\r\n{  \r\n    \"detail\": \"Your request has been throttled due to exceeding the allowed rate limit. Please wait for 10 minutes before trying again. If this issue persists, consider adjusting the request frequency or contact support for further assistance.\"  \r\n}\r\n```",
        "summary": "Create Access and Refresh Tokens V2",
        "tags": [
          "Authentication"
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TokenObtainPairCustomRequest"
              },
              "examples": {
                "UsernameAndPassword": {
                  "value": {
                    "username": "valid_username",
                    "password": "valid_password"
                  },
                  "summary": "Username and password"
                },
                "ClientCredentials": {
                  "value": {
                    "client_id": "3f1c2b8e-6a4d-4e0f-9b2a-1d5c7e8f9a01",
                    "client_secret": "<client_secret>"
                  },
                  "summary": "Client credentials",
                  "description": "client_id and client_secret of an API client created under Settings."
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "access": {
                      "type": "string",
                      "description": "JWT access token used for authenticating API requests."
                    },
                    "access_expiry_seconds": {
                      "type": "integer",
                      "description": "Time in seconds until the access token expires."
                    },
                    "refresh": {
                      "type": "string",
                      "description": "JWT refresh token used to obtain a new access token."
                    },
                    "refresh_expiry_seconds": {
                      "type": "integer",
                      "description": "Time in seconds until the refresh token expires."
                    }
                  }
                },
                "examples": {
                  "AccessAndRefreshTokens": {
                    "value": {
                      "access": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
                      "access_expiry_seconds": 3600,
                      "refresh": "dGhpcyBpcyBhIHJlZnJlc2ggdG9rZW4gZXhhbXBsZQ...",
                      "refresh_expiry_seconds": 28800
                    },
                    "summary": "Success",
                    "description": "Successful login — access and refresh JWTs with expiry seconds."
                  }
                }
              }
            },
            "description": "Returns access and refresh token along with their expiry times in seconds."
          },
          "400": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "code": {
                            "type": "string",
                            "description": "Field name that caused the error (username, password, client_id or client_secret)."
                          },
                          "message": {
                            "type": "string",
                            "description": "Validation error message for that field."
                          },
                          "detail": {
                            "type": "string",
                            "description": "Present for AttributeError / AuthenticationFailed catch paths."
                          }
                        }
                      }
                    },
                    "detail": {
                      "type": "string",
                      "description": "Present for ParseError (invalid JSON) catch path."
                    }
                  }
                },
                "examples": {
                  "ValidationError": {
                    "value": {
                      "errors": [
                        {
                          "code": "username",
                          "message": "This field is required."
                        },
                        {
                          "code": "password",
                          "message": "This field is required."
                        }
                      ]
                    },
                    "summary": "Validation Error",
                    "description": "TokenObtainPairCustomSerializer validation failed (missing/invalid fields)."
                  },
                  "InvalidJSON": {
                    "value": {
                      "detail": "JSON parse error - Expecting value: line 1 column 1 (char 0)"
                    },
                    "summary": "Invalid JSON",
                    "description": "ParseError — request body is not valid JSON."
                  }
                }
              }
            },
            "description": "Bad Request — serializer validation errors, invalid JSON (ParseError), AttributeError, or AuthenticationFailed."
          },
          "401": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "detail": {
                            "type": "string",
                            "description": "One of the following messages:\n- Invalid username or password.\n- Invalid client_id or client_secret.\n- Account has been temporarily locked due to multiple failed login attempts. Please reset your password or contact support.\n- There is some problem with your account. Please contact support for further assistance.\n- Something went wrong while processing your request"
                          }
                        }
                      }
                    },
                    "success": {
                      "type": "boolean"
                    }
                  }
                },
                "examples": {
                  "InvalidCredentials": {
                    "value": {
                      "errors": [
                        {
                          "detail": "Invalid username or password."
                        }
                      ]
                    },
                    "summary": "Invalid Credentials",
                    "description": "authenticate() returned no user for the given username/password."
                  },
                  "InvalidClientCredentials": {
                    "value": {
                      "errors": [
                        {
                          "detail": "Invalid client_id or client_secret."
                        }
                      ]
                    },
                    "summary": "Invalid Client Credentials",
                    "description": "No active API client matches the given client_id/client_secret."
                  }
                }
              }
            },
            "description": "Unauthorized — invalid username/password or invalid client_id/client_secret."
          },
          "403": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "detail": {
                            "type": "string",
                            "description": "One of the following messages:\n- Invalid username or password.\n- Invalid client_id or client_secret.\n- Account has been temporarily locked due to multiple failed login attempts. Please reset your password or contact support.\n- There is some problem with your account. Please contact support for further assistance.\n- Something went wrong while processing your request"
                          }
                        }
                      }
                    },
                    "success": {
                      "type": "boolean"
                    }
                  }
                },
                "examples": {
                  "AccountLocked": {
                    "value": {
                      "errors": [
                        {
                          "detail": "Account has been temporarily locked due to multiple failed login attempts. Please reset your password or contact support."
                        }
                      ]
                    },
                    "summary": "Account Locked",
                    "description": "Returned by get_if_login_allowed_for_user when the account is locked, or after the last failed attempt when lock_or_unlock_user_account(lock=True) runs."
                  },
                  "AccountInactive": {
                    "value": {
                      "errors": [
                        {
                          "detail": "There is some problem with your account. Please contact support for further assistance."
                        }
                      ]
                    },
                    "summary": "Account Inactive",
                    "description": "User exists but is_active is False."
                  }
                }
              }
            },
            "description": "Forbidden — account temporarily locked (get_if_login_allowed_for_user / lock after failed attempts) or inactive user account."
          },
          "405": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "Error detail message.",
                      "example": "Method \"PUT\" not allowed."
                    }
                  },
                  "example": {
                    "detail": "Method \"PUT\" not allowed."
                  }
                },
                "examples": {
                  "MethodNotAllowed": {
                    "value": {
                      "detail": "Method \"PUT\" not allowed."
                    },
                    "summary": "Method Not Allowed"
                  }
                }
              }
            },
            "description": "Method not allowed error response."
          },
          "415": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "Detailed message explaining the unsupported media type error.",
                      "example": "Unsupported media type \"text/plain\" in request."
                    }
                  },
                  "example": {
                    "detail": "Unsupported media type \"text/plain\" in request."
                  }
                },
                "examples": {
                  "UnsupportedMediaType": {
                    "value": {
                      "detail": "Unsupported media type \"text/plain\" in request."
                    },
                    "summary": "Unsupported Media Type"
                  }
                }
              }
            },
            "description": "Error response for unsupported media type in the request"
          },
          "429": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "Detailed message explaining that the request has been throttled due to exceeding the allowed rate limit. May include wait time and further instructions.",
                      "example": "Your request has been throttled due to exceeding the allowed rate limit. Please wait 26 seconds before trying again."
                    }
                  },
                  "example": {
                    "detail": "Your request has been throttled due to exceeding the allowed rate limit. Please wait 26 seconds before trying again. If this issue persists, consider adjusting the request frequency or contact support for further assistance."
                  }
                },
                "examples": {
                  "RateLimitExceeded": {
                    "value": {
                      "detail": "Your request has been throttled due to exceeding the allowed rate limit. Please wait 26 seconds before trying again. If this issue persists, consider adjusting the request frequency or contact support for further assistance."
                    },
                    "summary": "Rate Limit Exceeded"
                  }
                }
              }
            },
            "description": "Throttling error response indicating the rate limit has been exceeded."
          },
          "500": {
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "errors": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "detail": {
                            "type": "string",
                            "description": "Something went wrong while processing your request"
                          }
                        }
                      }
                    },
                    "success": {
                      "type": "boolean"
                    }
                  }
                },
                "examples": {
                  "ServerError": {
                    "value": {
                      "errors": [
                        {
                          "detail": "Something went wrong while processing your request"
                        }
                      ]
                    },
                    "summary": "Server Error",
                    "description": "Unhandled exception in UserTokenObtainPairAPIView.post."
                  }
                }
              }
            },
            "description": "Internal Server Error"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "TokenObtainPairCustomRequest": {
        "type": "object",
        "properties": {
          "username": {
            "type": "string",
            "minLength": 1,
            "description": "Account username. Required with password unless client_id/client_secret are sent.",
            "maxLength": 150
          },
          "password": {
            "type": "string",
            "writeOnly": true,
            "minLength": 1,
            "description": "Account password. Required with username unless client_id/client_secret are sent.",
            "maxLength": 255
          },
          "client_id": {
            "type": "string",
            "minLength": 1,
            "description": "API client ID (UUID). Use with client_secret instead of username/password.",
            "maxLength": 64
          },
          "client_secret": {
            "type": "string",
            "writeOnly": true,
            "minLength": 1,
            "description": "API client secret, shown once when the client is created or its secret is regenerated.",
            "maxLength": 255
          }
        }
      }
    }
  },
  "tags": [
    {
      "name": "Authentication"
    }
  ],
  "servers": [
    {
      "url": "https://app1.compliancely.com"
    }
  ]
}
````