> For the complete documentation index, see [llms.txt](https://doc.commandersact.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.commandersact.com/features/consent-management/onsite-api/getting-started.md).

# Getting Started

The Commanders Act Consent API is used to interact with Commanders Act Consent with JavaScript. It currently only offers methods to receive and update consent, but it will be improved with additional methods in the future.

## API Stub

It is necessary to install a JavaScript stub before any of the OnSite API methods can be used. The stub is used to buffer all methods in a JavaScript array until Commanders Act consent banner JavaScript is loaded and ready to process the methods. This allows to use the OnSite API before Commanders Act Consent Banner (JavaScript file) was loaded.

```javascript
window.caReady = window.caReady || []; 
window.cact = function() { window.caReady.push(arguments); };
```

`window.caReady` is a JavaScript array that buffers the interactions with the API. `window.cact` is a JavaScript function used to interact with the OnSite API.

{% hint style="success" %}
In case you work in a big team and are unsure the stub was already installed it is ok to install the JavaScript stub multiple times.
{% endhint %}

## Methods

After installing the stub it is then possible to use any of the OnSite API methods via the `window.cact` function.

{% hint style="info" %}
The available methods are listed in the documentation under **ONSITE API**.
{% endhint %}

Each method follows a strict signature:

```javascript
cact(command, [options,] [callback])
```

| Argument   | Descriptions                                                                                      | Required |
| ---------- | ------------------------------------------------------------------------------------------------- | -------- |
| `command`  | A string identifier used to select the desired method.                                            | Required |
| `options`  | A JavaScript object that includes data passed to the method.                                      | Optional |
| `callback` | A JavaScript callback function that is used to receive information or events from the OnSite API. | Optional |

Below you will find an example method that is used to receive the Commanders Act consent status with the OnSite API. This example only provides a callback to receive the consent without providing any options.

```javascript
cact('consent.get', function (result) {
    
    if (result.consent.status === "all-on") {
        
        // Consent available for all categories.
        
    }
    
});
```

{% hint style="warning" %}
The OnSite API methods are called asynchronously. In case e.g. you need information synchronous in the `<head>` of the document it is recommended to cache and retrieve the result of the API in `localStorage`.
{% endhint %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://doc.commandersact.com/features/consent-management/onsite-api/getting-started.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
