> ## Documentation Index
> Fetch the complete documentation index at: https://docs.talescria.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get an access token

> Exchange an OAuth client's credentials for an access token.

Form-encoded (`application/x-www-form-urlencoded`). Authenticate the client with HTTP Basic (`client_id:client_secret`) or with `client_id` and `client_secret` in the body, but not both. See [Authentication](https://docs.talescria.com/concepts/authentication.md).

**grant\_type** `string` *required*

`client_credentials` for a new token, or `refresh_token` to refresh one.

**scope** `string`

Space-separated scopes, to get a token that can do less than its client. Leave it out for all of the client's scopes.

**refresh\_token** `string`

With `grant_type=refresh_token`: the `rt_…` token from your last token response. Each refresh returns a new one; reusing an old one revokes the whole chain.

**client\_id** `string`

Your client ID, if you're not using HTTP Basic.

**client\_secret** `string`

Your client secret, if you're not using HTTP Basic.

### Response

**access\_token** `string`

`at_test_…` or `at_live_…`. Send as `Authorization: Bearer …`.

**token\_type** `string`

`Bearer`.

**expires\_in** `integer`

Seconds until the access token expires: `900`.

**refresh\_token** `string`

`rt_test_…` or `rt_live_…`, valid for 30 days.

**scope** `string`

The scopes the token carries, space-separated.

### Errors

Errors follow OAuth 2 (`{"error": "invalid_client"}`), not the API's error format.

| Status | `error` | Meaning |
| - | - | - |
| `400` | `invalid_request` | A parameter is missing, or credentials were sent both ways. |
| `400` | `invalid_grant` | The refresh token is invalid, expired or already used. |
| `400` | `invalid_scope` | A scope doesn't exist or the client doesn't hold it. |
| `400` | `unsupported_grant_type` | Use `client_credentials` or `refresh_token`. |
| `401` | `invalid_client` | Unknown client, wrong secret, or a revoked client. |

```bash curl theme={null}
curl https://idp.talescria.com/oauth/token \
  -u "$TALESCRIA_CLIENT_ID:$TALESCRIA_CLIENT_SECRET" \
  -d grant_type=client_credentials \
  -d "scope=accounts:read payments:write"
```

```python Python theme={null}
import requests

resp = requests.post(
    "https://idp.talescria.com/oauth/token",
    auth=(client_id, client_secret),
    data={"grant_type": "client_credentials", "scope": "accounts:read payments:write"},
    timeout=30,
)
token = resp.json()
```

```json 200 theme={null}
{
  "access_token": "at_test_…",
  "refresh_token": "rt_test_…",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "accounts:read payments:write"
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.