Webhooks

You want to send user choices to your server

Several methods are possible to send a user's choices to your server

window._axcb = window._axcb || [];
window._axcb.push(function (axeptio) {
    axeptio.on('cookies:complete', function (choices) {
        fetch('/backend/consent', {
            method: 'POST',
            body: {
                settings: axeptio.settings,
                choices: choices
            }
        }).then(function (response) {
            console.info('successfully saved user preferences');
        }).catch(function (error) {
            console.info('something went wrong');
        })
    });
});

Option 2a : register the token generated by Axeptio and use a webhook

window._axcb = window._axcb || [];
window._axcb.push(function (axeptio) {
    axeptio.on('ready', function () {
        fetch('/backend/token', {
            method: 'POST',
            body: { token: axeptio.settings.token  }
        }).then(function (response) {
            console.info('successfully saved user token');
        }).catch(function (error) {
            console.info('something went wrong');
        })
    });
});

Send a POST request for the webhook creation :

POST https://api.axept.io/v1/webhooks
Authorization: Bearer XXXXXXXXXXXXX <-- your bearer token
{
    "method": "POST",
    "url": "https://www.yourwebsite.com/backend/consent",
    "event": "consent/XXXXXXXXXXXXX" <-- your project Id
}

Option 2b : specify the Axeptio token and use a webhook

<script>
    window.axeptioSettings = {
        clientId: "XXXXXXXXXXXX",
        cookiesVersion: "ga_only",
        token: <?php echo json_encode(session_id()) ?>
    };
    (function(d, s) {
        var t = d.getElementsByTagName(s)[0], e = d.createElement(s);
        e.async = true; e.src = "//static.axept.io/sdk.js";
        t.parentNode.insertBefore(e, t);
    })(document, "script");
</script>

Send a POST request for the webhook creation :

POST https://api.axept.io/v1/webhooks
Authorization: Bearer XXXXXXXXXXXX <-- your bearer token
{
    "method": "POST",
    "url": "https://www.yourwebsite.com/backend/consent",
    "event": "consent/XXXXXXXXXXXXX" <-- your project Id
}

Last updated