HomeDocs

Example: Node.js

Use the official SDK from the api/ workspace, or plain fetch.

Option A — official SDK

import { NexloLabsVerification } from "@nexlolabs/api";

const client = new NexloLabsVerification({
  apiUrl: "https://verify.nexlolabs.net/api",
});

// ---- Express / Fastify route handler ----
app.post("/api/contact", async (req, res) => {
  const { token, name, email, message } = req.body;

  try {
    const result = await client.verify(token, process.env.NLV_SITE_SECRET);

    if (!result.success || result.score < 0.5) {
      return res.status(400).json({ error: "Human verification failed" });
    }

    await saveMessage({ name, email, message });
    return res.json({ ok: true });
  } catch (error) {
    if (error instanceof NexloApiError) {
      // error.code, e.g. "TOKEN_REPLAYED", "TOKEN_EXPIRED"
      return res.status(400).json({ error: error.code });
    }
    throw error;
  }
});

Option B — plain fetch

async function verifyToken(token, secret) {
  const res = await fetch("https://verify.nexlolabs.net/api/challenge/verify", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ token, secret }),
  });

  const body = await res.json();
  if (!res.ok) {
    const err = new Error(body.error?.message ?? "Verification failed");
    err.code = body.error?.code;
    throw err;
  }
  return body; // { success, score, challengeId, hostname, expires }
}

Full form handler (Express)

import express from "express";

const app = express();
app.use(express.json());

app.post("/submit", async (req, res) => {
  const { token, ...form } = req.body;

  if (!token) {
    return res.status(400).json({ error: "Missing verification token" });
  }

  const result = await verifyToken(token, process.env.NLV_SITE_SECRET);

  // Reject bots outright
  if (!result.success || result.score < 0.5) {
    return res.status(400).json({ error: "Please complete the verification again" });
  }

  // Now safe to process `form`
  res.json({ ok: true });
});

Using the stats API with an API key

const res = await fetch("https://verify.nexlolabs.net/api/statistics?range=month", {
  headers: { Authorization: `Bearer ${process.env.NLV_API_KEY}` },
});
const stats = await res.json();