API

Tulis record

Buat record baru, ubah sebagian field-nya dengan aman, lalu hapus record lewat REST API.

Menulis butuh capability write_records di workspace dan akses create, update, atau delete pada koleksi. Contoh memakai ulang base dari Baca record.

Buat record

POST /api/v1/workspaces/:workspace/collections/:collection/records

Kirim nilai field sebagai objek JSON. Field wajib harus ada.

curl -X POST 'http://127.0.0.1:8080/api/v1/workspaces/YOUR_WORKSPACE_ID/collections/YOUR_COLLECTION_ID/records' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  --data '{"title":"Cafe loyalty app","stage":"Lead","amount":4500000}'
const res = await fetch(`${base}/records`, {
	method: 'POST',
	headers: { Authorization: `Bearer ${token}`, 'Content-Type': 'application/json' },
	body: JSON.stringify({ title: 'Cafe loyalty app', stage: 'Lead', amount: 4500000 })
});
const { data: created } = await res.json();
body := strings.NewReader(`{"title":"Cafe loyalty app","stage":"Lead","amount":4500000}`)
req, _ := http.NewRequest("POST", base+"/records", body)
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
res, err := http.DefaultClient.Do(req)
res = requests.post(
    f"{base}/records",
    headers={"Authorization": f"Bearer {token}"},
    json={"title": "Cafe loyalty app", "stage": "Lead", "amount": 4500000},
)
created = res.json()["data"]

Responsnya adalah record baru, lengkap dengan id, created_at, dan updated_at:

{
	"data": {
		"id": "a462692b32bea7f8c1a523c20eea51cf",
		"title": "Cafe loyalty app",
		"stage": "Lead",
		"amount": 4500000,
		"created_at": "2026-10-23T13:00:32.221427Z",
		"updated_at": "2026-10-23T13:00:32.221427Z"
	},
	"meta": { "request_id": "...", "response_time": 2.9 }
}

Update record

PATCH /api/v1/workspaces/:workspace/collections/:collection/records/:record

Kirim hanya field yang berubah. Tambahkan If-Match dengan ETag yang kamu baca untuk menolak update jika record berubah di sela waktu itu.

curl -X PATCH 'http://127.0.0.1:8080/api/v1/workspaces/YOUR_WORKSPACE_ID/collections/YOUR_COLLECTION_ID/records/YOUR_RECORD_ID' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN' \
  -H 'Content-Type: application/json' \
  -H 'If-Match: "2026-10-23T13:00:32.221427Z"' \
  --data '{"stage":"Qualified"}'
const res = await fetch(`${base}/records/${recordId}`, {
	method: 'PATCH',
	headers: {
		Authorization: `Bearer ${token}`,
		'Content-Type': 'application/json',
		'If-Match': etag
	},
	body: JSON.stringify({ stage: 'Qualified' })
});
const { data: updated } = await res.json();
req, _ := http.NewRequest("PATCH", base+"/records/"+recordID, strings.NewReader(`{"stage":"Qualified"}`))
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("If-Match", etag)
res, err := http.DefaultClient.Do(req)
res = requests.patch(
    f"{base}/records/{record_id}",
    headers={"Authorization": f"Bearer {token}", "If-Match": etag},
    json={"stage": "Qualified"},
)
updated = res.json()["data"]

Responsnya record lengkap dengan updated_at yang baru. Jika record berubah setelah kamu membacanya, kamu mendapat 412 record_changed: baca ulang lalu coba lagi.

Hapus record

DELETE /api/v1/workspaces/:workspace/collections/:collection/records/:record

curl -X DELETE 'http://127.0.0.1:8080/api/v1/workspaces/YOUR_WORKSPACE_ID/collections/YOUR_COLLECTION_ID/records/YOUR_RECORD_ID' \
  -H 'Authorization: Bearer YOUR_ACCESS_TOKEN'
const res = await fetch(`${base}/records/${recordId}`, {
	method: 'DELETE',
	headers: { Authorization: `Bearer ${token}` }
});
console.log(res.status); // 204
req, _ := http.NewRequest("DELETE", base+"/records/"+recordID, nil)
req.Header.Set("Authorization", "Bearer "+token)
res, err := http.DefaultClient.Do(req)
res = requests.delete(f"{base}/records/{record_id}", headers={"Authorization": f"Bearer {token}"})
print(res.status_code)  # 204

Delete yang berhasil mengembalikan 204 tanpa body. Penghapusan bersifat permanen.

Langkah berikutnya

Traktir kopi