Skip to content
StatusSupportDashboard
Using the Data API

Copy-and-Paste Quickstart

Copy-paste starter snippets for ingest, import, polling, and webhooks.

import Safetykit from "safetykit";
const client = new Safetykit({ apiKey: process.env.SAFETYKIT_API_KEY });
const response = await client.data.ingest("messages", {
data: [
{
id: "message_12345",
user_id: "user_67890",
text: "sample content",
},
],
});
console.log(response.requestId);

API reference: POST /v1/data/{namespace}

const importResponse = await client.data.import("messages", {});
await fetch(importResponse.upload_url, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: `{"id":"message_12345","text":"sample content"}\n{"id":"message_12346","text":"another message"}\n`,
});
console.log(importResponse.requestId);

API reference: POST /v1/data/{namespace}/import

async function waitForCompletion(namespace: string, requestId: string) {
while (true) {
const status = await client.data.getStatus(namespace, requestId);
if (status.status === "succeeded" || status.status === "failed") {
return status;
}
await new Promise((resolve) => setTimeout(resolve, 5000));
}
}

API reference: GET /v1/data/{namespace}/requests/{requestId}

import { Webhook } from "svix";
const verifier = new Webhook(process.env.SAFETYKIT_WEBHOOK_SECRET!);
const payload = verifier.verify(rawBody, {
"webhook-id": req.headers["webhook-id"] as string,
"webhook-timestamp": req.headers["webhook-timestamp"] as string,
"webhook-signature": req.headers["webhook-signature"] as string,
});

API reference: Verifying Signatures

if (event.type === "workflow.succeeded" && event.namespace === "messages") {
const { id, output } = event;
await handleReviewDecision(id, output);
}

API reference: workflow.succeeded event