{
    "openapi": "3.0.3",
    "info": {
        "title": "ToroDocs REST API",
        "version": "v1",
        "description": "Programmatic e-signatures. Enterprise-only. Team-scoped Sanctum bearer tokens."
    },
    "servers": [
        {
            "url": "https://torodocs.com/api/v1"
        }
    ],
    "security": [
        {
            "bearerAuth": []
        }
    ],
    "components": {
        "securitySchemes": {
            "bearerAuth": {
                "type": "http",
                "scheme": "bearer"
            }
        },
        "schemas": {
            "Error": {
                "type": "object",
                "properties": {
                    "error": {
                        "type": "object",
                        "properties": {
                            "code": {
                                "type": "string"
                            },
                            "message": {
                                "type": "string"
                            },
                            "details": {
                                "type": "object"
                            }
                        }
                    }
                }
            },
            "Envelope": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "title": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string",
                        "enum": [
                            "draft",
                            "sent",
                            "in_progress",
                            "completed",
                            "voided",
                            "declined",
                            "expired"
                        ]
                    },
                    "sequential": {
                        "type": "boolean"
                    },
                    "recipient_count": {
                        "type": "integer"
                    },
                    "is_sealed": {
                        "type": "boolean"
                    },
                    "from_template": {
                        "type": "boolean"
                    },
                    "template_id": {
                        "type": "integer",
                        "nullable": true
                    },
                    "sent_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "completed_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "created_at": {
                        "type": "string"
                    },
                    "document": {
                        "type": "object",
                        "properties": {
                            "title": {
                                "type": "string"
                            },
                            "page_count": {
                                "type": "integer"
                            }
                        }
                    },
                    "recipients": {
                        "type": "array",
                        "items": {
                            "$ref": "#/components/schemas/Recipient"
                        }
                    },
                    "sealed": {
                        "type": "object",
                        "nullable": true,
                        "properties": {
                            "sha256": {
                                "type": "string"
                            },
                            "sealed_at": {
                                "type": "string"
                            },
                            "bytes": {
                                "type": "integer"
                            },
                            "download_url": {
                                "type": "string"
                            }
                        }
                    }
                }
            },
            "Recipient": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "name": {
                        "type": "string"
                    },
                    "email": {
                        "type": "string"
                    },
                    "signer_slot": {
                        "type": "integer"
                    },
                    "routing_order": {
                        "type": "integer"
                    },
                    "status": {
                        "type": "string"
                    },
                    "signed_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "viewed_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "signing_url": {
                        "type": "string",
                        "nullable": true
                    }
                }
            },
            "Field": {
                "type": "object",
                "properties": {
                    "key": {
                        "type": "string",
                        "nullable": true
                    },
                    "type": {
                        "type": "string"
                    },
                    "label": {
                        "type": "string"
                    },
                    "required": {
                        "type": "boolean"
                    },
                    "page": {
                        "type": "integer"
                    }
                }
            },
            "Template": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "name": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string",
                        "nullable": true
                    },
                    "page_count": {
                        "type": "integer"
                    },
                    "created_at": {
                        "type": "string"
                    }
                }
            },
            "TemplateDetail": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "name": {
                        "type": "string"
                    },
                    "description": {
                        "type": "string",
                        "nullable": true
                    },
                    "page_count": {
                        "type": "integer"
                    },
                    "created_at": {
                        "type": "string"
                    },
                    "sequential": {
                        "type": "boolean"
                    },
                    "default_title": {
                        "type": "string",
                        "nullable": true
                    },
                    "default_message": {
                        "type": "string",
                        "nullable": true
                    },
                    "roles": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "signer_slot": {
                                    "type": "integer"
                                },
                                "label": {
                                    "type": "string"
                                },
                                "default_email": {
                                    "type": "string",
                                    "nullable": true
                                },
                                "routing_order": {
                                    "type": "integer"
                                },
                                "fields": {
                                    "type": "array",
                                    "items": {
                                        "$ref": "#/components/schemas/Field"
                                    }
                                }
                            }
                        }
                    }
                }
            },
            "Webhook": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "integer"
                    },
                    "url": {
                        "type": "string"
                    },
                    "events": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "active": {
                        "type": "boolean"
                    },
                    "consecutive_failures": {
                        "type": "integer"
                    },
                    "last_success_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "last_failure_at": {
                        "type": "string",
                        "nullable": true
                    },
                    "created_at": {
                        "type": "string"
                    }
                }
            }
        }
    },
    "paths": {
        "/me": {
            "get": {
                "summary": "The authenticated team",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/templates": {
            "get": {
                "summary": "List templates",
                "parameters": [
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "default": 25,
                            "maximum": 100
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/Template"
                                            }
                                        },
                                        "meta": {
                                            "type": "object",
                                            "properties": {
                                                "current_page": {
                                                    "type": "integer"
                                                },
                                                "per_page": {
                                                    "type": "integer"
                                                },
                                                "total": {
                                                    "type": "integer"
                                                },
                                                "last_page": {
                                                    "type": "integer"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        },
        "/templates/{id}": {
            "get": {
                "summary": "Get a template (roles + fields, by field_key)",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/TemplateDetail"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/envelopes": {
            "get": {
                "summary": "List envelopes",
                "parameters": [
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        }
                    },
                    {
                        "name": "template_id",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        }
                    },
                    {
                        "name": "per_page",
                        "in": "query",
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "422": {
                        "description": "Validation failed",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "summary": "Create + send an envelope from a template",
                "parameters": [
                    {
                        "name": "Idempotency-Key",
                        "in": "header",
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "template_id",
                                    "recipients"
                                ],
                                "properties": {
                                    "template_id": {
                                        "type": "integer"
                                    },
                                    "title": {
                                        "type": "string"
                                    },
                                    "message": {
                                        "type": "string"
                                    },
                                    "sequential": {
                                        "type": "boolean"
                                    },
                                    "expires_in_days": {
                                        "type": "integer",
                                        "minimum": 1,
                                        "maximum": 365
                                    },
                                    "reminders": {
                                        "type": "object",
                                        "properties": {
                                            "enabled": {
                                                "type": "boolean"
                                            },
                                            "interval_days": {
                                                "type": "integer"
                                            }
                                        }
                                    },
                                    "recipients": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "required": [
                                                "signer_slot",
                                                "name",
                                                "email"
                                            ],
                                            "properties": {
                                                "signer_slot": {
                                                    "type": "integer"
                                                },
                                                "name": {
                                                    "type": "string"
                                                },
                                                "email": {
                                                    "type": "string"
                                                },
                                                "routing_order": {
                                                    "type": "integer"
                                                },
                                                "fields": {
                                                    "type": "object",
                                                    "additionalProperties": {
                                                        "type": "string"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Created",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Envelope"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "403": {
                        "description": "insufficient_scope / api_not_enabled",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "409": {
                        "description": "idempotency_conflict",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "422": {
                        "description": "Validation failed",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/envelopes/{id}": {
            "get": {
                "summary": "Get an envelope",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "data": {
                                            "$ref": "#/components/schemas/Envelope"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/envelopes/{id}/recipients": {
            "get": {
                "summary": "List an envelope's recipients",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/envelopes/{id}/download": {
            "get": {
                "summary": "Download the sealed PDF",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "application/pdf"
                    },
                    "409": {
                        "description": "not_ready",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/webhooks": {
            "get": {
                "summary": "List webhook endpoints",
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            },
            "post": {
                "summary": "Create a webhook endpoint (secret returned once)",
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "url"
                                ],
                                "properties": {
                                    "url": {
                                        "type": "string",
                                        "format": "uri"
                                    },
                                    "events": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Created"
                    },
                    "422": {
                        "description": "invalid_url",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/webhooks/{id}": {
            "delete": {
                "summary": "Delete a webhook endpoint",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "404": {
                        "description": "Not found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/webhooks/{id}/test": {
            "post": {
                "summary": "Send a test event",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "responses": {
                    "202": {
                        "description": "Queued"
                    }
                }
            }
        }
    }
}