{
    "openapi": "3.0.3",
    "info": {
        "title": "RoboCRM API",
        "version": "1.0.0"
    },
    "servers": [
        {
            "url": "https://crm.simulatefin.com/api/v1"
        }
    ],
    "components": {
        "securitySchemes": {
            "bearer": {
                "type": "http",
                "scheme": "bearer"
            },
            "apiKey": {
                "type": "apiKey",
                "in": "header",
                "name": "X-API-Key"
            }
        }
    },
    "security": [
        {
            "bearer": []
        },
        {
            "apiKey": []
        }
    ],
    "paths": {
        "/me": {
            "get": {
                "summary": "Organization, key name and scopes of the calling key",
                "description": "Organization, key name and scopes of the calling key.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            }
        },
        "/clients": {
            "get": {
                "summary": "List clients",
                "description": "List clients. Filters: q, email, phone, status, updated_since (ISO date), page, per_page (max 100). Scope: clients:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            },
            "post": {
                "summary": "Create a client",
                "description": "Create a client. Add ?upsert=email or ?upsert=phone to update the existing client instead of creating a duplicate. Fires client.created. Scope: clients:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "name": "Dana Levi",
                                "email": "dana@levi-tech.co.il",
                                "phone": "052-1234567",
                                "company": "Levi Tech",
                                "status": "lead",
                                "source": "website",
                                "owner_email": "agent@company.co.il",
                                "tags": [
                                    "VIP"
                                ],
                                "custom_fields": {
                                    "industry": "Software"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/clients/{id}": {
            "get": {
                "summary": "One client with tags and custom fields",
                "description": "One client with tags and custom fields. Scope: clients:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            },
            "patch": {
                "summary": "Update any of the fields above",
                "description": "Update any of the fields above. Status changes fire client.status_changed. Scope: clients:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "status": "customer"
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Move the client to the trash (soft delete)",
                "description": "Move the client to the trash (soft delete). Scope: clients:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            }
        },
        "/deals": {
            "get": {
                "summary": "List deals",
                "description": "List deals. Filters: client_id, pipeline_id, stage, updated_since. Scope: deals:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            },
            "post": {
                "summary": "Create a deal",
                "description": "Create a deal. stage is a stage slug from GET /pipelines (default: first open stage of the default pipeline). Scope: deals:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "client_id": 42,
                                "title": "CRM rollout",
                                "amount": 20000,
                                "stage": "proposal",
                                "close_date": "2026-12-31"
                            }
                        }
                    }
                }
            }
        },
        "/deals/{id}": {
            "get": {
                "summary": "One deal",
                "description": "One deal. Scope: deals:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ]
            },
            "patch": {
                "summary": "Update title, amount, close_date, owner_email, pipeline_id, stage",
                "description": "Update title, amount, close_date, owner_email, pipeline_id, stage. Moving the stage fires deal.stage_changed. Scope: deals:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "stage": "won"
                            }
                        }
                    }
                }
            }
        },
        "/pipelines": {
            "get": {
                "summary": "Pipelines with their stages (slug, name, kind open|won|lost, probability)",
                "description": "Pipelines with their stages (slug, name, kind open|won|lost, probability). Scope: deals:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            }
        },
        "/tasks": {
            "get": {
                "summary": "List tasks",
                "description": "List tasks. Filters: client_id, status. Scope: tasks:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            },
            "post": {
                "summary": "Create a task",
                "description": "Create a task. Scope: tasks:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "title": "Send contract",
                                "client_id": 42,
                                "due_date": "2026-10-20",
                                "priority": "high",
                                "assignee_email": "agent@company.co.il"
                            }
                        }
                    }
                }
            }
        },
        "/tasks/{id}": {
            "patch": {
                "summary": "Update a task",
                "description": "Update a task. status=done fires task.completed. Scope: tasks:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "status": "done"
                            }
                        }
                    }
                }
            }
        },
        "/activities": {
            "post": {
                "summary": "Add a timeline entry to a client: note, call, meeting, email, whatsapp or sms",
                "description": "Add a timeline entry to a client: note, call, meeting, email, whatsapp or sms. Scope: activities:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "client_id": 42,
                                "type": "sms",
                                "body": "Reminder sent",
                                "occurred_at": "2026-10-08T10:00:00+03:00"
                            }
                        }
                    }
                }
            }
        },
        "/products": {
            "get": {
                "summary": "Active products of the price list",
                "description": "Active products of the price list. Scope: catalog:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            }
        },
        "/calls": {
            "post": {
                "summary": "PBX call event (see \"Connecting a PBX\")",
                "description": "PBX call event (see \"Connecting a PBX\"). Idempotent per call_id: send ringing, answered and completed / missed for the same call_id. Scope: calls:write.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                },
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object"
                            },
                            "example": {
                                "call_id": "pbx-1700000000.123",
                                "status": "completed",
                                "direction": "inbound",
                                "from": "052-1234567",
                                "to": "03-5551234",
                                "extension": "201",
                                "started_at": "2026-10-08T10:00:00+03:00",
                                "duration": 184,
                                "recording_url": "https://pbx.example.com/rec/123.mp3"
                            }
                        }
                    }
                }
            },
            "get": {
                "summary": "Call log",
                "description": "Call log. Filters: client_id, status, since. Scope: calls:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            }
        },
        "/lookup": {
            "get": {
                "summary": "Caller ID / screen pop: ?phone=0521234567 returns the client, its owner, the owner's extension and open deals",
                "description": "Caller ID / screen pop: ?phone=0521234567 returns the client, its owner, the owner's extension and open deals. Scope: calls:read.",
                "responses": {
                    "200": {
                        "description": "OK"
                    },
                    "401": {
                        "description": "Invalid key"
                    },
                    "403": {
                        "description": "Missing scope"
                    },
                    "422": {
                        "description": "Validation error"
                    },
                    "429": {
                        "description": "Rate limited"
                    }
                }
            }
        }
    }
}