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

    v2.2.0

    Device heartbeats, versioned settings, annotation target catalogs, and private event image/video uploads.

    https://holcjxpztfeikwgubuql.supabase.co/functions/v1
    POST
    /defense-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 recorded
    400Bad request - Invalid input data
    401Unauthorized - Invalid API key
    403Forbidden - Device not active
    405Method not allowed - Only POST requests are accepted
    500Internal server error
    OPTIONS
    /defense-heartbeat

    CORS preflight request

    Handles CORS preflight requests for cross-origin access

    Responses

    200CORS preflight response
    POST
    /defense-events

    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 recorded
    400Bad request - Invalid input data
    401Unauthorized - Invalid API key
    403Forbidden - Device not active
    413Payload too large - Media file size exceeds limits
    500Internal server error
    OPTIONS
    /defense-events

    CORS preflight request

    Handles CORS preflight requests for cross-origin access

    Responses

    200CORS preflight response
    POST
    /api/public/device-pair

    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 paired
    400Invalid, expired or already used code
    500Internal server error
    GET
    /api/public/device-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 snapshot
    400Invalid protocol payload
    401Invalid device key
    409Version, mutation or report conflict
    422Unsupported configuration
    503Temporarily unavailable
    PUT
    /api/public/device-settings

    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 snapshot
    400Invalid protocol payload
    401Invalid device key
    409Version, mutation or report conflict
    422Unsupported configuration
    503Temporarily unavailable
    POST
    /api/public/device-settings/applied

    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 accepted
    400Invalid protocol payload
    401Invalid device key
    409Version, mutation or report conflict
    422Unsupported configuration
    503Temporarily unavailable
    POST
    /api/public/device-events

    Register an event idempotently

    Persist client_event_id and replay the identical body. Do not also send to legacy defense-events.

    Responses

    200Accepted / identical replay
    400Invalid payload or media type/size
    401Invalid device key
    403Device inactive
    404Event or upload reservation not found
    409Reused identifier, changed media slot or missing object
    410The event was permanently deleted and must not be uploaded again
    413JSON exceeds 16 KiB
    422Uploaded size or MIME differs from reservation
    503Storage or database unavailable; retry
    POST
    /api/public/device-events/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 replay
    400Invalid payload or media type/size
    401Invalid device key
    403Device inactive
    404Event or upload reservation not found
    409Reused identifier, changed media slot or missing object
    413JSON exceeds 16 KiB
    422Uploaded size or MIME differs from reservation
    503Storage or database unavailable; retry
    POST
    /api/public/device-events/complete

    Confirm a stored media file

    Verifies existence, size and MIME before exposing to the owner. Repeat safely after timeouts.

    Responses

    200Accepted / identical replay
    400Invalid payload or media type/size
    401Invalid device key
    403Device inactive
    404Event or upload reservation not found
    409Reused identifier, changed media slot or missing object
    413JSON exceeds 16 KiB
    422Uploaded size or MIME differs from reservation
    503Storage or database unavailable; retry
    DELETE
    /api/public/device-events/{clientEventId}

    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 updated
    401Invalid device key
    404Unknown event
    503Deletion temporarily unavailable; retry without deleting locally
    GET
    /api/public/device-event-deletions

    List pending cloud-initiated event deletions

    Responses

    200Up to 100 pending client event identifiers
    401Invalid device key
    503Deletion sync temporarily unavailable
    POST
    /api/public/device-event-deletions

    Acknowledge locally applied event deletions

    Responses

    200Deletion acknowledgements stored idempotently
    400Invalid acknowledgement body
    401Invalid device key
    503Deletion sync temporarily unavailable
    GET
    /api/public/annotation-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 IDs
    401Invalid or inactive device key
    503Annotation catalog temporarily unavailable