# Getting Started

The TrustCommander OnSite API is used to interact with TrustCommander 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 TrustCommander JavaScript is loaded and ready to process the methods. This allows to use the OnSite API before TrustCommander JavaScript 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 on 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 TrustCommander consent 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: 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:

```
GET https://community.commandersact.com/trustcommander/onsite-api/getting-started.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
