Developer API & webhooks
API keys
Create keys in API & Webhooks. Each key belongs to one server and has scopes (e.g. levels:read, moderation:write). Keys are shown once and stored hashed. Limit: 120 requests/minute per key.
http
GET /api/v1/guilds/{guildId}/levels
Authorization: Bearer csk_xxxxxxxx_...| Method | Path | Scope |
|---|---|---|
| GET | /api/v1/guilds/:id | guild:read |
| GET / PUT | /api/v1/guilds/:id/config/:module | config:read / config:write |
| GET / POST | /api/v1/guilds/:id/cases | moderation:read / moderation:write |
| GET | /api/v1/guilds/:id/levels | levels:read |
| POST | /api/v1/guilds/:id/levels/:userId/xp | levels:write |
| GET / POST | /api/v1/guilds/:id/economy/:userId | economy:read / economy:write |
| GET | /api/v1/guilds/:id/tickets | tickets:read |
| GET | /api/v1/guilds/:id/logs | logs:read |
| GET | /api/v1/guilds/:id/analytics | analytics:read |
| POST | /api/v1/guilds/:id/messages | messages:send |
JavaScript
js
const res = await fetch(`${BASE}/api/v1/guilds/${GUILD}/levels/${USER}/xp`, {
method: "POST",
headers: { Authorization: `Bearer ${process.env.CASHARKS_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ amount: 50 }),
});
console.log(await res.json()); // { oldLevel, newLevel, xp }TypeScript
ts
interface Case { caseNumber: number; action: string; targetId: string; reason: string | null }
async function warn(userId: string, reason: string): Promise<Case> {
const r = await fetch(`${BASE}/api/v1/guilds/${GUILD}/cases`, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({ action: "WARN", targetId: userId, reason }),
});
if (!r.ok) throw new Error((await r.json()).error);
return r.json();
}Lua (FiveM server)
lua
PerformHttpRequest(BASE .. "/api/v1/guilds/" .. GUILD .. "/economy/" .. discordId, function(code, body)
print(code, body)
end, "POST", json.encode({ amount = 250, note = "Job payout" }), {
["Authorization"] = "Bearer " .. GetConvar("casharks_api_key", ""),
["Content-Type"] = "application/json"
})Webhooks
Subscribe an HTTPS endpoint to events such as member.join, moderation.case_created, ticket.closed, level.up or appeal.decided. Each request includes:
X-Casharks-Event,X-Casharks-Delivery,X-Casharks-TimestampX-Casharks-Signature: sha256=HMAC_SHA256(secret, "<timestamp>.<raw body>")
ts
import { createHmac, timingSafeEqual } from "node:crypto";
export function verify(rawBody: string, ts: string, sig: string, secret: string) {
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false; // replay protection
const expected = "sha256=" + createHmac("sha256", secret).update(`${ts}.${rawBody}`).digest("hex");
return expected.length === sig.length && timingSafeEqual(Buffer.from(expected), Buffer.from(sig));
}Failed deliveries are retried with exponential backoff; endpoints are disabled after 20 consecutive failures.
Plugins
A remote plugin is an external service that receives webhooks and acts through the API with its own scoped key — it never runs inside Casharks Bot. Bundle plugins install ready-made workflows, commands and embeds.