> For the complete documentation index, see [llms.txt](https://docs.hos.accessacloud.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hos.accessacloud.com/resdiary-api/guides/authentication/oauth-2.0-client-credentials-flow.md). Agents can also search and read this documentation through its [MCP server](https://docs.hos.accessacloud.com/~gitbook/mcp).

# OAuth 2.0 Client Credentials Flow

Use this grant for machine-to-machine integrations. It authenticates your application without a user. The token endpoint returns an access token for your API requests.

### Prerequisites

You need:

* a `client_id`
* a `client_secret`
* the required `audience` value
* an allowed API scope
* the correct authorization server for your environment

Supported scopes:

| Scope              | API                                                                                                           |
| ------------------ | ------------------------------------------------------------------------------------------------------------- |
| `consumer_api`     | [Consumer API](https://docs.hos.accessacloud.com/resdiary-api/guides/consumer-api-guide.md)                   |
| `data_extract_api` | [Data Extract API](https://docs.hos.accessacloud.com/resdiary-api/api-references/data-extract-api/booking.md) |
| `epos_api`         | [EPOS API](https://docs.hos.accessacloud.com/resdiary-api/guides/epos-api-guide.md)                           |

Request only the scope your integration needs.

***

Product APIs use OAuth 2.0 **client credentials**: your app exchanges its client ID and client secret for a short-lived access token, then sends that token on every request.

You also need your app's subscription key — see [Using your subscription key](broken://spaces/xDIaLeqW86aLGejSkZHo/pages/4PrXJQqgTrUlcKIZq3Cm).

### 1. Get your client credentials

1. Sign in to the [Developer Portal](https://developers.uk.hos.accessacloud.com/) and go to **My Apps**.
2. Click your app.
3. In the **API Credentials** card, choose **Sandbox** or **Production**, and copy the **Client ID**.

The **Client Secret** is shown **once only**, when credentials are created:

* **sandbox** — on the screen shown right after you register the app, or after **Regenerate Sandbox Keys**;
* **production** — after **Generate Production Keys**.

{% hint style="warning" %}
Store the client secret somewhere safe as soon as it is shown. If you lose it, regenerate the secret from the app's **API Credentials** card — regenerating invalidates the old secret.

**Do not mix environments.** Sandbox and production use different client IDs, client secrets, and base URLs.
{% endhint %}

### 2. Request an access token

Your app's `token URL`, `scope` and `audience` values are shown in the portal under the **API Integration** of section in the App Details Page. Send all three values when requesting a token.<br>

#### Token endpoint

Select the endpoint that matches your app's environment.&#x20;

| Environment | Token endpoint                                                        |
| ----------- | --------------------------------------------------------------------- |
| Sandbox     | `https://api-staging.hos.accessacloud.com/platform/m2m-auth/v1/token` |
| Production  | `https://api.hos.accessacloud.com/platform/m2m-auth/v1/token`         |

{% tabs %}
{% tab title="cURL" %}

```bash
curl -X POST "$TOKEN_URL" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=client_credentials" \
  -d "client_id=$CLIENT_ID" \
  -d "client_secret=$CLIENT_SECRET" \
  -d "scope=$SCOPE" \
  -d "audience=$AUDIENCE"
```

{% endtab %}

{% tab title="Python" %}

```python
import os
import requests

response = requests.post(
    os.environ["TOKEN_URL"],
    data={
        "grant_type": "client_credentials",
        "client_id": os.environ["CLIENT_ID"],
        "client_secret": os.environ["CLIENT_SECRET"],
        "scope": os.environ["SCOPE"],
        "audience": os.environ["AUDIENCE"],
    },
)
response.raise_for_status()
access_token = response.json()["access_token"]
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const response = await fetch(process.env.TOKEN_URL, {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: new URLSearchParams({
    grant_type: "client_credentials",
    client_id: process.env.CLIENT_ID,
    client_secret: process.env.CLIENT_SECRET,
    scope: process.env.SCOPE,
    audience: process.env.AUDIENCE,
  }),
});
if (!response.ok) {
  throw new Error(`Token request failed: ${response.status}`);
}
const { access_token: accessToken } = await response.json();
```

{% endtab %}

{% tab title="C#" %}

```csharp
using System.Collections.Generic;

var tokenUrl = Environment.GetEnvironmentVariable("TOKEN_URL");
using var client = new HttpClient();

var content = new FormUrlEncodedContent(new Dictionary<string, string>
{
    { "grant_type", "client_credentials" },
    { "client_id", Environment.GetEnvironmentVariable("CLIENT_ID") },
    { "client_secret", Environment.GetEnvironmentVariable("CLIENT_SECRET") },
    { "scope", Environment.GetEnvironmentVariable("SCOPE") },
    { "audience", Environment.GetEnvironmentVariable("AUDIENCE") },
});

var response = await client.PostAsync(tokenUrl, content);
response.EnsureSuccessStatusCode();
```

{% endtab %}
{% endtabs %}

The response contains the token and its lifetime:

```json
{
  "access_token": "eyJhbGciOi...",
  "token_type": "Bearer",
  "expires_in": 3600
}
```

### 3. Send the token

Put the token in the `Authorization` header of every API request, alongside your subscription key:

```bash
curl -X GET "$BASE_URL/your/endpoint" \
  -H "Ocp-Apim-Subscription-Key: $SUBSCRIPTION_KEY" \
  -H "Authorization: Bearer $ACCESS_TOKEN"
```

Cache the token and reuse it until shortly before it expires. Renew it before the `expires_in` limit — do not request a token per API call.

### Troubleshooting

| Error                           | Fix                                                                                               |
| ------------------------------- | ------------------------------------------------------------------------------------------------- |
| `invalid_client`                | Client ID or secret is wrong, or you are mixing sandbox credentials with the production token URL |
| `invalid_scope`                 | Use the `scope` value shown for your app under **Generate a Token**                               |
| `401 Unauthorized` from the API | The token is missing, expired or from the wrong environment — request a new one                   |

### Good to know

* Never put the client secret in front-end code, a public repository or a support ticket. Keep it in an environment variable or a secret store.
* Regenerating a client secret does **not** change your subscription key.
* Use sandbox credentials while you build and test; switch to production credentials only in your production systems.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.hos.accessacloud.com/resdiary-api/guides/authentication/oauth-2.0-client-credentials-flow.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
