> 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/fr/fonctionnalites/consent-management/onsite-api/getting-started.md).

# Prise en main

Vue d'ensemble de l'API OnSite Consent de Commanders Act.

L’API Consent de Commanders Act permet d’interagir avec Commanders Act Consent à l’aide de JavaScript. Elle propose actuellement uniquement des méthodes pour recevoir et mettre à jour le consentement, mais sera enrichie de méthodes supplémentaires à l’avenir.

## Stub de l’API

Il est nécessaire d’installer un stub JavaScript avant de pouvoir utiliser les méthodes de l’API OnSite. Le stub met en mémoire tampon toutes les méthodes dans un tableau JavaScript jusqu’à ce que le JavaScript de la bannière de consentement Commanders Act soit chargé et prêt à les traiter. Cela permet d’utiliser l’API OnSite avant le chargement de la bannière de consentement Commanders Act (fichier JavaScript).

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

`window.caReady` est un tableau JavaScript qui met en mémoire tampon les interactions avec l’API. `window.cact` est une fonction JavaScript utilisée pour interagir avec l’API OnSite.

{% hint style="success" %}
Si vous travaillez au sein d’une grande équipe et ne savez pas si le stub a déjà été installé, vous pouvez l’installer plusieurs fois.
{% endhint %}

## Méthodes

Après avoir installé le stub, vous pouvez utiliser n’importe quelle méthode de l’API OnSite via la fonction `window.cact` .

{% hint style="info" %}
Les méthodes disponibles sont répertoriées dans la documentation, à la rubrique **ONSITE API**.
{% endhint %}

Chaque méthode suit une signature stricte :

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

| Argument   | Descriptions                                                                                                 | Obligatoire |
| ---------- | ------------------------------------------------------------------------------------------------------------ | ----------- |
| `command`  | Un identifiant sous forme de chaîne de caractères permettant de sélectionner la méthode souhaitée.           | Obligatoire |
| `options`  | Un objet JavaScript contenant les données transmises à la méthode.                                           | Facultatif  |
| `callback` | Une fonction de rappel JavaScript permettant de recevoir des informations ou des événements de l’API OnSite. | Facultatif  |

Vous trouverez ci-dessous un exemple de méthode permettant de récupérer l’état du consentement Commanders Act avec l’API OnSite. Cet exemple fournit uniquement une fonction de rappel pour recevoir le consentement, sans transmettre d’options.

```javascript
cact('consent.get', function (result) {
    
    if (result.consent.status === "all-on") {
        
        // Consentement disponible pour toutes les catégories.
        
    }
    
});
```

{% hint style="warning" %}
Les méthodes de l’API OnSite sont appelées de manière asynchrone. Par exemple, si vous avez besoin d’informations de manière synchrone dans le `<head>` du document, il est recommandé de mettre en cache le résultat de l’API et de le récupérer depuis `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 by asking a question.

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

```
GET https://doc.commandersact.com/fr/fonctionnalites/consent-management/onsite-api/getting-started.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.
