> This page is part of EVVA for Developers (https://developers.evvahub.com), the documentation of the EVVA Partner API. The API is in developer preview and the SDK packages are not yet published: do not suggest installing them. Index: https://developers.evvahub.com/llms.txt

# Request an access token

POST https://api.evvahub.com/partner/v1/oauth/token
Content-Type: application/x-www-form-urlencoded

Issues an access token for your application with the OAuth 2.0 `client_credentials` grant.

**Request**

Send `grant_type=client_credentials` as `application/x-www-form-urlencoded` (RFC 6749) or as JSON with the same parameter names. Send each parameter once, in the body, never in the URL query. `scope` is space-separated and must name only scopes your application is allowed; omit it to receive all of them. See [requesting tokens](/authentication/tokens).

**Client authentication**

Authenticate the client with exactly one of `client_secret_basic`, `client_secret_post` or `private_key_jwt`. With `private_key_jwt`:

* send `client_assertion_type=urn:ietf:params:oauth:client-assertion-type:jwt-bearer`;
* sign the assertion with an RS256 or ES256 key registered for the application in the Partner Hub;
* set `iss` = `sub` = `client_id`, and `aud` = this endpoint's URL;
* set `exp` at most five minutes ahead;
* use a single-use `jti`.

**Response**

`{access_token, token_type: "Bearer", expires_in, scope}`, with an `evpa_live_…` or `evpa_test_…` token. `expires_in` is the token's lifetime in seconds, 900 by default, and `scope` lists the scopes it carries. There is no refresh token: request a new token when the current one expires. The token answer, like every `OAuthTokenError` answer, carries `Cache-Control: no-store` and `Pragma: no-cache`.

**Errors**

Errors use the RFC 6749, section 5.2 body (`OAuthTokenError`), except `INVALID_REQUEST`, which uses the common `Error` envelope:

* `400 INVALID_REQUEST` — the body does not ask for `grant_type=client_credentials`, for example because `grant_type` is missing.
* `400 invalid_request` — a malformed request: a parameter sent twice, too long or in the URL query, more than one client authentication method, `client_secret` without `client_id`, or `client_assertion` without `client_assertion_type`.
* `400 unsupported_grant_type` — this environment does not offer the `client_credentials` grant.
* `400 unauthorized_client` — the application is not active, or its agency is suspended.
* `400 invalid_scope` — a malformed scope, more than 64 scopes, or a scope beyond the application's allowed scopes.
* `401 invalid_client` — any client authentication failure. The answer is the same constant in every case, with `WWW-Authenticate: Basic` when you used HTTP Basic.
* `503 temporarily_unavailable` — EVVA cannot answer right now, and no token is issued. Retry after `Retry-After`.

Reference: https://developers.evvahub.com/api-reference/authentication/issue-token

## Authentication

- `Authorization` header (basic auth, required) — Client authentication at the token and revocation endpoints with the client id and secret (`client_secret_basic`, RFC 6749, section 2.3.1). `client_secret_post` and `private_key_jwt` send the credentials in the form body instead.

## Request

### Body (application/x-www-form-urlencoded)

This endpoint expects a ClientCredentialsTokenRequest.

- `grant_type` ("client_credentials", required)
- `scope` (string, optional) — Space-separated; a subset of the application's allowed scopes.
- `client_id` (string, optional)
- `client_secret` (string, optional)
- `client_assertion_type` ("urn:ietf:params:oauth:client-assertion-type:jwt-bearer", optional)
- `client_assertion` (string, optional) — A JWT signed with RS256 or ES256. Set `iss` and `sub` to your `client_id`, `aud` to the token URL, and `exp` at most 5 minutes ahead; `jti` must be single-use.

## Response

### 200

The access token. The answer carries `Cache-Control: no-store` and `Pragma: no-cache`.

- `access_token` (string, required)
- `token_type` ("Bearer", required)
- `expires_in` (integer, required) — The token's lifetime in seconds. 900 by default; a deployment may set it between 60 and 3600, so read it rather than assume it.
- `scope` (string, required)

## Errors

### 400 Bad Request Error

A malformed or refused request, with an RFC 6749, section 5.2 body (`OAuthTokenError`): `invalid_request`, `invalid_scope`, `unauthorized_client` or `unsupported_grant_type`. A body that does not ask for `grant_type=client_credentials`, for example one without `grant_type`, is answered `INVALID_REQUEST` in the common `Error` envelope.

- `IssueTokenRequestBadRequestError`
  - Error: Error
  - OAuthTokenError: OAuthTokenError

### 401 Unauthorized Error

Client authentication failed: `invalid_client` (`OAuthTokenError`), one constant body for every failure, with `WWW-Authenticate: Basic` when HTTP Basic was attempted.

- `IssueTokenRequestUnauthorizedError`
  - Error: Error
  - OAuthTokenError: OAuthTokenError

### 429 Too Many Requests Error

Rate limited: `RATE_LIMIT_EXCEEDED`. Wait `Retry-After` seconds before retrying.

- `code` (enum, required) — A stable machine-readable code (see `KnownErrorCode`; new codes may appear within v1).
  - Allowed values: `RATE_LIMIT_EXCEEDED`, `TOO_MANY_MESSAGES`
- `error` (string, required)
- `requestId` (string, required, nullable) — The same value as the `X-Request-Id` response header — quote it when reporting a problem.
- `details` (RateLimitErrorDetails, optional) — Extra detail for the code, specific to the operation, such as field errors, limits or the creator's account-status details.

### 500 Internal Server Error

Unexpected server error: `INTERNAL_ERROR`. Nothing internal is disclosed; quote the `X-Request-Id` when you report it.

- `code` (string, required) — A stable machine-readable code (see `KnownErrorCode`; new codes may appear within v1).
- `error` (string, required)
- `requestId` (string, required, nullable) — The same value as the `X-Request-Id` response header — quote it when reporting a problem.
- `details` (any, optional) — Extra detail for the code, specific to the operation, such as field errors, limits or the creator's account-status details.

### 503 Service Unavailable Error

EVVA cannot answer right now, and no token is issued; always with `Retry-After`. The body is `temporarily_unavailable` (`OAuthTokenError`).

- `IssueTokenRequestServiceUnavailableError`
  - Error: Error
  - OAuthTokenError: OAuthTokenError

## Types

### Error

The common error envelope. Branch on `code`; `error` is human-readable and may change.

- `code` (string, required) — A stable machine-readable code (see `KnownErrorCode`; new codes may appear within v1).
- `error` (string, required)
- `requestId` (string, required, nullable) — The same value as the `X-Request-Id` response header — quote it when reporting a problem.
- `details` (any, optional) — Extra detail for the code, specific to the operation, such as field errors, limits or the creator's account-status details.

### OAuthTokenError

The error body of the token endpoint (`client_credentials`) and of application token revocation (RFC 7009), as defined by RFC 6749, section 5.2. It is not the `Error` envelope. - `400` — `invalid_request`, `unsupported_grant_type`, `invalid_scope` or `unauthorized_client`. - `401` — `invalid_client`: one constant body for every authentication failure, with `WWW-Authenticate: Basic` when HTTP Basic was attempted. - `503` — `temporarily_unavailable`, with `Retry-After`: a store the decision needs did not answer, and no token is issued when in doubt. Retry later.

- `error` (enum, required)
  - Allowed values: `invalid_request`, `invalid_client`, `unauthorized_client`, `unsupported_grant_type`, `invalid_scope`, `temporarily_unavailable`
- `error_description` (string, optional)

### RateLimitErrorDetails

Extra detail for the code, specific to the operation, such as field errors, limits or the creator's account-status details.

- `retryAfterSec` (integer, required)
- `level` (enum, optional) — The DM send limit that refused the message, set only with `TOO_MANY_MESSAGES`. It is never a quota, a count or a key. - `conversation` — one side of one thread. - `sender` — a person's own ceiling; it does not apply to applications. - `creator` — everything sent for the creator, studio included. - `application` — everything your application sends. - `agency` — everything your agency sends. - `platform` — the agency's fair share of the platform: its throughput or its concurrency. See [rate limits](/authentication/rate-limits).
  - Allowed values: `conversation`, `sender`, `creator`, `application`, `agency`, `platform`

## Examples

### Authentication_issueToken_example (application/x-www-form-urlencoded)

**Request**

```json
{
  "grant_type": "client_credentials",
  "scope": "read:messages write:messages write:messages:automated read:buyer_context"
}
```

**Response**

```json
{
  "access_token": "evpa_live_k3Vq7XcN2mR8tL5wZp1Hb9Df4Gy6Js0Ae3Uo8Qi2Tn5",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "read:messages write:messages write:messages:automated read:buyer_context"
}
```

**SDK Code**

```python Authentication_issueToken_example (application/x-www-form-urlencoded)
import requests

url = "https://api.evvahub.com/partner/v1/oauth/token"

payload = ""
headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}

response = requests.post(url, data=payload, headers=headers, auth=("<clientId>", "<clientSecret>"))

print(response.json())
```

```go Authentication_issueToken_example (application/x-www-form-urlencoded)
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.evvahub.com/partner/v1/oauth/token"

	req, _ := http.NewRequest("POST", url, nil)

	req.SetBasicAuth("<clientId>", "<clientSecret>")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```php Authentication_issueToken_example (application/x-www-form-urlencoded)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.evvahub.com/partner/v1/oauth/token', [
  'form_params' => null,
  'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
    'auth' => ['<clientId>', '<clientSecret>'],
]);

echo $response->getBody();
```

### Authentication_issueToken_example (application/json)

**Request**

```json
{
  "grant_type": "client_credentials",
  "scope": "read:messages write:messages write:messages:automated",
  "client_id": "app_7Kq2mX9vR4tB",
  "client_secret": "example-client-secret-not-real"
}
```

**Response**

```json
{
  "access_token": "evpa_live_k3Vq7XcN2mR8tL5wZp1Hb9Df4Gy6Js0Ae3Uo8Qi2Tn5",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "read:messages write:messages write:messages:automated read:buyer_context"
}
```

**SDK Code**

```python Authentication_issueToken_example (application/json)
import requests

url = "https://api.evvahub.com/partner/v1/oauth/token"

payload = ""
headers = {
    "Content-Type": "application/x-www-form-urlencoded"
}

response = requests.post(url, data=payload, headers=headers, auth=("<clientId>", "<clientSecret>"))

print(response.json())
```

```go Authentication_issueToken_example (application/json)
package main

import (
	"fmt"
	"net/http"
	"io"
)

func main() {

	url := "https://api.evvahub.com/partner/v1/oauth/token"

	req, _ := http.NewRequest("POST", url, nil)

	req.SetBasicAuth("<clientId>", "<clientSecret>")
	req.Header.Add("Content-Type", "application/x-www-form-urlencoded")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```php Authentication_issueToken_example (application/json)
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.evvahub.com/partner/v1/oauth/token', [
  'form_params' => null,
  'headers' => [
    'Content-Type' => 'application/x-www-form-urlencoded',
  ],
    'auth' => ['<clientId>', '<clientSecret>'],
]);

echo $response->getBody();
```