Developers · Agents
Flood Watch API
ให้เอเจนต์ แชตบอต หรือแอปของคุณแจ้งน้ำท่วมและดึงรายงานน้ำท่วมจากชุมชนได้ ไม่ต้องมีบัญชีหรือ API key
กติกาที่ควรรู้
- แจ้งได้ 5 รายงานต่อ 10 นาที ต่อ IP (เกินจะได้ 429 rate_limited) การดึงข้อมูลไม่จำกัด
- รายงานเป็นข้อมูลสาธารณะ ทุกคนเห็นบนแผนที่ ยกเว้น delete_token ที่เป็นความลับ
- photo_url / thumb_url เป็นลิงก์แบบ signed ที่หมดอายุในราว 1 ชั่วโมง ให้ดึงใหม่เมื่อจำเป็น
- เก็บ delete_token ที่ได้ตอนแจ้งไว้ หากต้องการลบรายงานภายหลัง (ขอใหม่ไม่ได้)
- เรียก API จากฝั่งเซิร์ฟเวอร์ของเอเจนต์ (CORS เปิดให้เฉพาะเว็บ Flood Watch)
1 · แจ้งน้ำท่วม
POST https://flood-api.rooptanjai.com/api/reports · operationId createReport
ส่งภาพ ตำแหน่ง และระดับน้ำ รายงานจะขึ้นบนแผนที่ทันที ต้องมีภาพทุกครั้ง หากเอเจนต์รับแจ้งจากผู้ใช้ ให้ส่งต่อภาพของผู้ใช้มาด้วย
ฟิลด์ใน body (JSON)
| ชื่อ | ชนิด | จำเป็น | คำอธิบาย |
|---|---|---|---|
| lat | number | ใช่ | Latitude where the photo was taken (WGS84). |
| lng | number | ใช่ | Longitude where the photo was taken (WGS84). |
| accuracy_m | integer | null | Location accuracy in metres, if known. | |
| depth | Depth | ใช่ | Water depth: `none` = no water (0 cm) · `ankle` = up to 20 cm · `knee` = 20–50 cm · `waist` = 50 cm or deeper. |
| note | string | Optional short note (up to 500 characters). Leading/trailing spaces are trimmed. | |
| photo | string | ใช่ | The photo as a base64 data URL (`data:image/jpeg;base64,…`). JPEG, PNG or WebP, up to 1.5 MB decoded; the type is checked from the bytes. The server stores a full-size (≤1600 px) and a thumbnail (≤256 px) JPEG. Whole request body ≤ 2.2 MB. |
ค่าระดับน้ำ (depth)
| depth | คำอธิบาย |
|---|---|
| none | ไม่มีน้ำ · 0 ซม. |
| ankle | ถึงข้อเท้า · ไม่เกิน 20 ซม. |
| knee | ถึงเข่า · 20–50 ซม. |
| waist | ถึงเอวขึ้นไป · 50 ซม. ขึ้นไป |
curl
# photo = base64 data URL of the image (JPEG/PNG/WebP, ≤1.5 MB)
PHOTO="data:image/jpeg;base64,$(base64 -w0 flood.jpg)"
curl -X POST https://flood-api.rooptanjai.com/api/reports \
-H 'Content-Type: application/json' \
-d "{\"lat\":13.7563,\"lng\":100.5018,\"depth\":\"knee\",\"note\":\"Road flooded\",\"photo\":\"$PHOTO\"}"ตัวอย่างผลลัพธ์
HTTP/1.1 201 Created
{
"id": 42,
"lat": 13.7563, "lng": 100.5018, "accuracy_m": null,
"depth": "knee",
"note": "Road flooded",
"photo_url": "https://storage.googleapis.com/…_full.jpg?X-Goog-Signature=…",
"thumb_url": "https://storage.googleapis.com/…_thumb.jpg?X-Goog-Signature=…",
"created_at": "2026-09-27T08:30:00Z",
"delete_token": "3f9c…" // keep this private
}ข้อผิดพลาด
| HTTP | error | คำอธิบาย |
|---|---|---|
| 400 | validation | fields: { field → message } |
| 400 | invalid_json | malformed JSON or unknown field |
| 413 | too_large | body > 2.2 MB |
| 429 | rate_limited | 5 reports / 10 min / IP |
| 503 | database_unavailable | retry later |
2 · ดึงข้อมูลรายงาน
GET https://flood-api.rooptanjai.com/api/reports · operationId listReports
ดึงรายงานล่าสุดในพื้นที่ (bbox) และช่วงเวลา (since) เรียงจากใหม่ไปเก่า
พารามิเตอร์ใน query
| ชื่อ | ชนิด | คำอธิบาย |
|---|---|---|
| bbox | string | Map area as `minLng,minLat,maxLng,maxLat` (WGS84 degrees). Omit for all areas. |
| since | string | Only reports newer than this: a Go duration (`24h`, `90m`, `168h`) or an RFC 3339 time. Default `24h`. Capped at 30 days (`720h`). |
| limit | integer | Maximum number of reports. Default 200. Values above 500 are capped at 500. |
curl
curl 'https://flood-api.rooptanjai.com/api/reports?bbox=100.45,13.70,100.60,13.80&since=24h&limit=50'ตัวอย่างผลลัพธ์
HTTP/1.1 200 OK
{
"reports": [
{ "id": 42, "lat": 13.7563, "lng": 100.5018, "accuracy_m": null, "depth": "knee",
"note": "Road flooded", "photo_url": "https://…", "thumb_url": "https://…",
"created_at": "2026-09-27T08:30:00Z" }
]
}ลบรายงานของคุณ
ใช้ delete_token ที่ได้ตอนแจ้ง ส่งใน header X-Delete-Token ได้ 204 เมื่อสำเร็จ
curl -X DELETE https://flood-api.rooptanjai.com/api/reports/42 -H 'X-Delete-Token: <delete_token>'