Shell
# check the key from the server that will use it
curl -s -H "Authorization: Bearer $COREDNA_API_KEY" \
"$COREDNA_URL/cdna-api/users/account?properties=%7B%20id,%20username%20%7D"
JavaScript
// coredna.js: the one module that holds the key (Node 18 or later)
const SITE = process.env.COREDNA_URL; // https://www.example.com
const KEY = process.env.COREDNA_API_KEY;
if (!SITE || !KEY) throw new Error('COREDNA_URL and COREDNA_API_KEY must be set');
export async function coredna(method, path, { query, body } = {}) {
const url = new URL(SITE + '/cdna-api/' + path);
for (const [k, v] of Object.entries(query ?? {})) url.searchParams.set(k, v);
const response = await fetch(url, {
method,
headers: {
Authorization: 'Bearer ' + KEY,
Accept: 'application/json',
...(body === undefined ? {} : { 'Content-Type': 'application/json' }),
},
body: body === undefined ? undefined : JSON.stringify(body),
});
const data = await response.json().catch(() => ({}));
if (!response.ok) {
throw new Error(method + ' ' + path + ': ' + response.status + ' ' + (data.message ?? response.headers.get('x-reason') ?? ''));
}
return data;
}
What the failures look like, so the log line says which one it was:
| Response | Meaning |
401, x-reason: not logged in | No Authorization header reached the site: a proxy stripped it, or the variable is empty |
| 403, Authentication failed | The key is wrong or deleted |
| 403, IP … not permitted for this API key | The request came from an address not on the key's list |
| 403, Authorization method not supported | The scheme is not exactly Bearer |
| 403 on one endpoint only | The integration user lacks permission for that module |