Contoh kode
Alur lengkap dalam curl, TypeScript, dan Python.
Semua contoh membaca key dari DAMPINGIN_API_KEY dan memakai base URL https://api.dampingin.com. Ganti ID contoh (ord_..., kas_..., bid_...) dengan ID asli.
Alur lengkap
Katalog, order dengan Idempotency-Key, polling, balas permintaan data, terima hasil:
// Node 18+ / Bun / Deno: fetch is built in.
const API = "https://api.dampingin.com";
const KEY = process.env.DAMPINGIN_API_KEY!;
async function dp<T>(method: string, path: string, body?: unknown, headers: Record<string, string> = {}): Promise<T> {
const res = await fetch(API + path, {
method,
headers: { authorization: `Bearer ${KEY}`, ...(body ? { "content-type": "application/json" } : {}), ...headers },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(`${res.status} ${data.error?.code}: ${data.error?.message}`);
return data as T;
}
// 1. Catalog: agent price, SLA and intake schema per service.
const { data: services } = await dp<{ data: { code: string; price_idr: number | null; intake: { key: string; required: boolean }[] }[] }>("GET", "/v1/services");
const svc = services.find((s) => s.code === "pt-perorangan")!;
// 2. Order. Reuse the same Idempotency-Key when you retry this exact request.
const order = await dp<{ id: string; status: string }>("POST", "/v1/orders", {
service: svc.code,
intake: { nama_pt: "PT Maju Jaya, PT Maju Jaya Abadi, PT Maju Bersama", kbli: "62019", pemilik: "Budi Santoso" },
max_budget: 3_000_000,
}, { "idempotency-key": crypto.randomUUID() });
// 3. Poll (or use webhooks). Answer when the practitioner asks for input; accept when delivered.
for (;;) {
const o = await dp<{ status: string; deliverable: string | null; messages: { role: string; body: string }[] }>("GET", `/v1/orders/${order.id}`);
if (o.status === "butuh_input_klien") {
const ask = o.messages.filter((m) => m.role === "practitioner").at(-1);
console.log("Practitioner asks:", ask?.body);
// await dp("POST", `/v1/orders/${order.id}/messages`, { body: "..." });
}
if (o.status === "diserahkan") {
console.log("Deliverable:", o.deliverable);
await dp("POST", `/v1/orders/${order.id}/accept`);
break;
}
if (["dibatalkan", "direfund", "sengketa"].includes(o.status)) break;
await new Promise((r) => setTimeout(r, 60_000)); // stay well under 60 req/min
}Semua endpoint (curl)
| Langkah | Perintah |
|---|---|
| Katalog | GET /v1/services |
| Order | POST /v1/orders |
| Status | GET /v1/orders/{id} |
| Balas | POST /v1/orders/{id}/messages |
| Terima | POST /v1/orders/{id}/accept |
| Saldo | GET /v1/balance |
export DAMPINGIN_API_KEY="dk_live_xxxxxx.rahasia"
curl https://api.dampingin.com/v1/services \
-H "Authorization: Bearer $DAMPINGIN_API_KEY"Papan kasus
curl -X POST https://api.dampingin.com/v1/cases \
-H "Authorization: Bearer $DAMPINGIN_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"contact_name": "Rina",
"contact_email": "rina@example.com",
"story": "Supplier menolak mengembalikan uang muka Rp 80 juta setelah kontrak dibatalkan sepihak di Bandung.",
"area": "kontrak",
"urgency": "tinggi",
"budget_range": "Rp 5-15 juta"
}'status kasus
curl https://api.dampingin.com/v1/cases/kas_xxxxxxxxxxxxxxxxxxxx \
-H "Authorization: Bearer $DAMPINGIN_API_KEY"