{"openapi":"3.0.3","info":{"title":"LeadFlow API","version":"1.0.0","description":"API pública del CRM LeadFlow. Autenticación con clave de API por cuenta. Documentación: https://api-leads.vred.es/v1/docs"},"servers":[{"url":"https://api-leads.vred.es/v1"}],"security":[{"apiKey":[]}],"components":{"securitySchemes":{"apiKey":{"type":"http","scheme":"bearer","description":"Clave lf_live_… creada en Configuración › API e integraciones"}},"schemas":{"Error":{"type":"object","properties":{"error":{"type":"object","properties":{"code":{"type":"string"},"message":{"type":"string"}}}}},"Person":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"email":{"type":"string"}}},"Tag":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string"},"slug":{"type":"string"}}},"Deal":{"type":"object","properties":{"value":{"type":"integer","nullable":true,"description":"Importe en euros"},"probability":{"type":"integer","nullable":true},"expectedCloseAt":{"type":"string","nullable":true,"description":"AAAA-MM-DD"},"wonAt":{"type":"string","nullable":true},"lostAt":{"type":"string","nullable":true},"lostReason":{"type":"string","nullable":true}}},"Lead":{"type":"object","properties":{"id":{"type":"integer"},"name":{"type":"string","nullable":true},"phone":{"type":"string","nullable":true},"email":{"type":"string","nullable":true},"status":{"type":"string","enum":["nuevo","en_cualificacion","cualificado","cita_agendada","ganado","perdido"]},"step":{"type":"string","nullable":true},"source":{"type":"string","nullable":true},"channel":{"type":"string","nullable":true},"tags":{"type":"array","items":{"$ref":"#/components/schemas/Tag"}},"assignedTo":{"allOf":[{"$ref":"#/components/schemas/Person"}],"nullable":true},"conversationOwner":{"type":"string","enum":["ia","humano"]},"outreachPaused":{"type":"boolean"},"deal":{"$ref":"#/components/schemas/Deal"},"appointment":{"type":"object","properties":{"at":{"type":"string","nullable":true},"outcome":{"type":"string","nullable":true}}},"data":{"type":"object","additionalProperties":{"type":"string"}},"lastInteractionAt":{"type":"string","nullable":true},"createdAt":{"type":"string"},"updatedAt":{"type":"string"}}},"LeadInput":{"type":"object","properties":{"name":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"status":{"type":"string"},"source":{"type":"string"},"tags":{"type":"array","items":{"type":"string"}},"data":{"type":"object","additionalProperties":{"type":"string"}},"deal":{"type":"object","properties":{"value":{"type":"integer"},"probability":{"type":"integer"},"expectedCloseAt":{"type":"string"}}},"assignedTo":{"type":"integer","nullable":true},"outreach":{"type":"boolean","description":"true para que el seguimiento automático pueda escribirle"},"note":{"type":"string"}}},"LeadPatch":{"type":"object","properties":{"name":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"status":{"type":"string"},"lostReason":{"type":"string"},"tags":{"type":"array","items":{"type":"string"}},"addTags":{"type":"array","items":{"type":"string"}},"removeTags":{"type":"array","items":{"type":"string"}},"data":{"type":"object","additionalProperties":{"type":"string","nullable":true}},"deal":{"type":"object","properties":{"value":{"type":"integer"},"probability":{"type":"integer"},"expectedCloseAt":{"type":"string"}}},"assignedTo":{"type":"integer","nullable":true},"outreach":{"type":"boolean"}}},"Task":{"type":"object","properties":{"id":{"type":"integer"},"leadId":{"type":"integer"},"title":{"type":"string"},"kind":{"type":"string"},"note":{"type":"string","nullable":true},"dueAt":{"type":"string"},"doneAt":{"type":"string","nullable":true},"origin":{"type":"string"},"assignedTo":{"allOf":[{"$ref":"#/components/schemas/Person"}],"nullable":true},"createdBy":{"type":"string"},"createdAt":{"type":"string"}}},"TaskInput":{"type":"object","required":["title","dueAt"],"properties":{"title":{"type":"string"},"kind":{"type":"string","enum":["llamar","email","whatsapp","reunion","otro"]},"dueAt":{"type":"string"},"assignedTo":{"type":"integer","nullable":true},"note":{"type":"string"}}},"TaskPatch":{"type":"object","properties":{"title":{"type":"string"},"kind":{"type":"string"},"dueAt":{"type":"string"},"note":{"type":"string"},"assignedTo":{"type":"integer","nullable":true},"done":{"type":"boolean"}}},"Note":{"type":"object","properties":{"id":{"type":"integer"},"leadId":{"type":"integer"},"body":{"type":"string"},"pinned":{"type":"boolean"},"author":{"type":"string"},"createdAt":{"type":"string"}}},"MessageInput":{"type":"object","required":["body"],"properties":{"channel":{"type":"string","enum":["whatsapp","email"]},"body":{"type":"string"},"subject":{"type":"string"}}},"MessageResult":{"type":"object","properties":{"id":{"type":"integer"},"leadId":{"type":"integer"},"channel":{"type":"string"},"status":{"type":"string"},"error":{"type":"string","nullable":true},"createdAt":{"type":"string"}}}},"responses":{"Error":{"description":"Error","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}},"paths":{"/":{"get":{"summary":"Cuenta y rutas disponibles","responses":{"200":{"description":"OK"}}}},"/leads":{"get":{"summary":"Listar leads","parameters":[{"name":"status","in":"query","schema":{"type":"string"},"description":"Uno o varios separados por coma"},{"name":"assigned_to","in":"query","schema":{"type":"integer"}},{"name":"tag","in":"query","schema":{"type":"string"},"description":"Nombre o slug de la etiqueta"},{"name":"q","in":"query","schema":{"type":"string"},"description":"Busca en nombre, teléfono y email"},{"name":"created_since","in":"query","schema":{"type":"string","format":"date-time"}},{"name":"updated_since","in":"query","schema":{"type":"string","format":"date-time"}},{"name":"sort","in":"query","schema":{"type":"string","enum":["updated","created","last_interaction"]}},{"name":"limit","in":"query","schema":{"type":"integer","maximum":100,"default":50}},{"name":"offset","in":"query","schema":{"type":"integer","default":0}}],"responses":{"200":{"description":"Página","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Lead"}},"total":{"type":"integer"},"limit":{"type":"integer"},"offset":{"type":"integer"}}}}}}}},"post":{"summary":"Crear o actualizar un lead por teléfono o email","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadInput"}}}},"responses":{"200":{"description":"Ya existía; actualizado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Lead"}}}},"201":{"description":"Creado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Lead"}}}},"400":{"$ref":"#/components/responses/Error"}}}},"/leads/{id}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"get":{"summary":"Ficha completa con notas, tareas, mensajes y eventos","responses":{"200":{"description":"Lead","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Lead"}}}},"404":{"$ref":"#/components/responses/Error"}}},"patch":{"summary":"Modificar un lead","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/LeadPatch"}}}},"responses":{"200":{"description":"Lead","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Lead"}}}}}}},"/leads/{id}/notes":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"post":{"summary":"Añadir una nota","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["body"],"properties":{"body":{"type":"string"},"pinned":{"type":"boolean"}}}}}},"responses":{"201":{"description":"Nota","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Note"}}}}}}},"/leads/{id}/tasks":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"post":{"summary":"Crear una tarea","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TaskInput"}}}},"responses":{"201":{"description":"Tarea","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Task"}}}}}}},"/leads/{id}/messages":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"post":{"summary":"Enviar un mensaje al lead por WhatsApp o email","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageInput"}}}},"responses":{"201":{"description":"Enviado","content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessageResult"}}}},"502":{"description":"El canal no aceptó el envío"}}}},"/tasks":{"get":{"summary":"Listar tareas","parameters":[{"name":"status","in":"query","schema":{"type":"string","enum":["pending","done","all"],"default":"pending"}},{"name":"assigned_to","in":"query","schema":{"type":"integer"}},{"name":"lead_id","in":"query","schema":{"type":"integer"}},{"name":"due_before","in":"query","schema":{"type":"string","format":"date-time"}},{"name":"limit","in":"query","schema":{"type":"integer","maximum":100}},{"name":"offset","in":"query","schema":{"type":"integer"}}],"responses":{"200":{"description":"Página","content":{"application/json":{"schema":{"type":"object","properties":{"data":{"type":"array","items":{"$ref":"#/components/schemas/Task"}},"total":{"type":"integer"}}}}}}}}},"/tasks/{id}":{"parameters":[{"name":"id","in":"path","required":true,"schema":{"type":"integer"}}],"patch":{"summary":"Modificar o cerrar una tarea","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/TaskPatch"}}}},"responses":{"200":{"description":"Tarea","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Task"}}}}}}},"/team":{"get":{"summary":"Usuarios del equipo","responses":{"200":{"description":"OK"}}}},"/tags":{"get":{"summary":"Etiquetas","responses":{"200":{"description":"OK"}}}}}}