Developer tools
API Documentation
Comprehensive documentation for the Defense System API endpoints. Use this documentation to understand how to integrate with our services.
Local device views
These pages open directly on a Garden Defense device in the same local network. Replacegardendefensewith the private device IP if local hostname resolution is unavailable.
Defense System API
Device heartbeats, versioned settings, annotation target catalogs, and private event image/video uploads.
https://holcjxpztfeikwgubuql.supabase.co/functions/v1POST/defense-heartbeatSend device heartbeat
Send device heartbeat
Endpoint for defense devices to send heartbeat data including system status and operational metrics. Recommended interval: every 5 minutes while monitoring, every 15 minutes in sleep mode.
Request example
{
"api_key": "550e8400-e29b-41d4-a716-446655440000",
"local_time": "2024-01-15T10:30:00Z",
"firmware": "v2.1.0",
"ai_model_version": "defense-v1.2.3",
"wifi_signal_strength": -45,
"local_ip": "192.168.20.17",
"uptime": 86400.5,
"status": "monitoring"
}Responses
200Heartbeat successfully recorded400Bad request - Invalid input data401Unauthorized - Invalid API key403Forbidden - Device not active405Method not allowed - Only POST requests are accepted500Internal server errorOPTIONS/defense-heartbeatCORS preflight request
CORS preflight request
Handles CORS preflight requests for cross-origin access
Responses
200CORS preflight responsePOST/defense-eventsSubmit defense event
Submit defense event
Endpoint for defense devices to submit image-recognition detections, spray responses and sleep-mode transitions with pre-uploaded media files using the optimized two-step process
Request example
{
"api_key": "550e8400-e29b-41d4-a716-446655440000",
"event_type": "detection",
"start_time": "2024-01-15T14:30:15Z",
"end_time": "2024-01-15T14:30:17Z",
"confidence": 0.87,
"target_class": "cat",
"metadata": {
"detection_zone": "front_yard"
}
}Responses
200Event successfully recorded400Bad request - Invalid input data401Unauthorized - Invalid API key403Forbidden - Device not active413Payload too large - Media file size exceeds limits500Internal server errorOPTIONS/defense-eventsCORS preflight request
CORS preflight request
Handles CORS preflight requests for cross-origin access
Responses
200CORS preflight responsePOST/api/public/device-pairPair device with a 6-digit code
Pair device with a 6-digit code
The user generates a 6-digit code in the web app. The device sends the code here and receives its permanent api_key. Codes expire after 15 minutes and can be used once.
Responses
200Device paired400Invalid, expired or already used code500Internal server errorGET/api/public/device-settingsRead desired settings
Read desired settings
On boot/reconnect or changed heartbeat version. No additional periodic settings polling. Returns model metadata, last report sequence and an additive class_configuration extension outside the strict Settings v3 object. Email-only changes also increment settings_version.
Responses
200Full versioned settings snapshot400Invalid protocol payload401Invalid device key409Version, mutation or report conflict422Unsupported configuration503Temporarily unavailablePUT/api/public/device-settingsSubmit versioned local changes
Submit versioned local changes
Persist base_version, mutation_id, changes and optional class_configuration before sending. Replay the identical mutation after uncertain delivery. Action/email changes are atomic. With class_configuration, changes may be empty for an email-only save. HTTP 409 returns the current snapshot; class edits including email are one conflict group.
Responses
200Full versioned settings snapshot400Invalid protocol payload401Invalid device key409Version, mutation or report conflict422Unsupported configuration503Temporarily unavailablePOST/api/public/device-settings/appliedReport effective settings
Report effective settings
A successful PUT is not an apply acknowledgment. Persist monotonic report_sequence and exact body before sending; report actual effective settings and, when supported, class_configuration. Applied reports must match the referenced revision; extended reports also match current version and email preferences.
Responses
200Report accepted400Invalid protocol payload401Invalid device key409Version, mutation or report conflict422Unsupported configuration503Temporarily unavailablePOST/api/public/device-eventsRegister an event idempotently
Register an event idempotently
Persist client_event_id and replay the identical body. Do not also send to legacy defense-events.
Responses
200Accepted / identical replay400Invalid payload or media type/size401Invalid device key403Device inactive404Event or upload reservation not found409Reused identifier, changed media slot or missing object410The event was permanently deleted and must not be uploaded again413JSON exceeds 16 KiB422Uploaded size or MIME differs from reservation503Storage or database unavailable; retryPOST/api/public/device-events/uploadReserve a private media upload
Reserve a private media upload
Raw PUT to upload_url with Content-Type and Content-Length, without device key. Valid for 2 hours. The role identifies an ordered capture. Reusing client_media_id links one immutable file (for example a shared clip) without uploading it again. Images <=10 MiB, MP4 <=50 MiB.
Responses
200Accepted / identical replay400Invalid payload or media type/size401Invalid device key403Device inactive404Event or upload reservation not found409Reused identifier, changed media slot or missing object413JSON exceeds 16 KiB422Uploaded size or MIME differs from reservation503Storage or database unavailable; retryPOST/api/public/device-events/completeConfirm a stored media file
Confirm a stored media file
Verifies existence, size and MIME before exposing to the owner. Repeat safely after timeouts.
Responses
200Accepted / identical replay400Invalid payload or media type/size401Invalid device key403Device inactive404Event or upload reservation not found409Reused identifier, changed media slot or missing object413JSON exceeds 16 KiB422Uploaded size or MIME differs from reservation503Storage or database unavailable; retryDELETE/api/public/device-events/{clientEventId}Permanently delete an event from the device
Permanently delete an event from the device
Use only for an explicit user deletion on the device. Automatic local retention must not call this endpoint. Replays of an already deleted event succeed idempotently.
Responses
200Event, media and device tombstone updated401Invalid device key404Unknown event503Deletion temporarily unavailable; retry without deleting locallyGET/api/public/device-event-deletionsList pending cloud-initiated event deletions
List pending cloud-initiated event deletions
Responses
200Up to 100 pending client event identifiers401Invalid device key503Deletion sync temporarily unavailablePOST/api/public/device-event-deletionsAcknowledge locally applied event deletions
Acknowledge locally applied event deletions
Responses
200Deletion acknowledgements stored idempotently400Invalid acknowledgement body401Invalid device key503Deletion sync temporarily unavailableGET/api/public/annotation-catalogFetch the active annotation target catalog
Fetch the active annotation target catalog
Returns the global, versioned classes that a reviewer can assign to existing device-side Bounding Boxes. The device fetches this endpoint when annotation_catalog_version in a heartbeat response advances.
Responses
200Active target classes and stable YOLO IDs401Invalid or inactive device key503Annotation catalog temporarily unavailable