API · JavaScript
JavaScript guide
Browser fetch for sign-in and reading alerts. Walk through register or sign-in, create a key, send one ordinary request, read alerts, then the follow-up calls you will need later.
Use browser fetch for sign-in and for reading alerts from an admin page you control. Send ingest from a server. Never put the API key in page source.
Before you start
- API host: https://api-vigil.bizinvestify.com
- Store accessToken and refreshToken in memory or a cookie you control — not in a public gist.
- Ingest belongs on the server with VIGIL_API_KEY.
Day one in JavaScript
Sign in and read alerts
Typical admin-page flow. Plans are public so you can show Naira prices without a token.
async function vigil(path, { method = "GET", token, body } = {}) {
const response = await fetch("https://api-vigil.bizinvestify.com" + path, {
method,
headers: {
accept: "application/json",
...(body ? { "content-type": "application/json" } : {}),
...(token ? { authorization: "Bearer " + token } : {}),
},
body: body ? JSON.stringify(body) : undefined,
});
const payload = await response.json();
if (!payload.success) throw new Error(payload.message || payload.error);
return payload.data;
}
const session = await vigil("/api/v1/auth/login", {
method: "POST",
body: { email: "ada@example.com", password: "Password!234" },
});
const alerts = await vigil("/api/v1/alerts?limit=20", {
token: session.accessToken,
});
console.log(alerts);
const plans = await vigil("/api/v1/plans");
plans.forEach((plan) => {
console.log(plan.name, "₦" + plan.amountKobo / 100);
});More useful calls
Refresh before the access token dies
Save the new refresh token; the previous one is retired.
const next = await vigil("/api/v1/auth/refresh", {
method: "POST",
body: { refreshToken: session.refreshToken },
});
// keep next.accessToken and next.refreshTokenMark an alert seen
Same call the dashboard uses.
await vigil("/api/v1/alerts/" + alertId + "/ack", {
method: "POST",
token: session.accessToken,
});What success looks like
Alerts list
Empty array until a request scores 50 or more.
{ "success": true, "data": [] }Tips
- Do not call /api/v1/ingest from the browser with a live key.
- Show payload.message when success is false.
- Money is always NGN; amounts in JSON are kobo integers.
Prefer the dashboard for day-to-day work. Prefer these language pages when you wire by hand. The interactive operator reference stays on the console at https://api-vigil.bizinvestify.com/docs.
New here? Open a workspace on the site, create a key under API keys, then come back and run step 3.