Authentification
Every API-call made to the /api/*
endpoint needs to carry a token
to authenticate the call. The token can be passed to the Cockpit API in three ways:
- In a query parameter.
- As a
Cockpit-Token
header. - As a
Bearer
token in theAuthorization
header.
Examples
Query Parameter
fetch('/api/collections/get/posts?token=xxtokenxx').then(res =>
res.json()
).then(res =>
console.log(res)
);
Cockpit-Token
header
fetch('/api/collections/get/posts', {
headers: { 'Cockpit-Token': 'xxtokenxx' }
}).then(res =>
res.json()
).then(res =>
console.log(res)
);
Bearer
token in the Authorization
header
fetch('/api/collections/get/posts', {
headers: { 'Authorization': 'Bearer xxtokenxx' }
}).then(res =>
res.json()
).then(res =>
console.log(res)
);