{
  "openapi": "3.1.0",
  "info": {
    "title": "Datalyse API",
    "version": "1.0",
    "description": "Public REST API of Datalyse, a multi-tenant CRM and communication platform. Every endpoint requires an API access token in the `token` parameter (query string for GET, JSON body otherwise). Get your token by signing in at /devs/."
  },
  "servers": [
    {
      "url": "https://api.datalyse.io"
    }
  ],
  "paths": {
    "/api/1.0/leads/create.json": {
      "post": {
        "operationId": "create_lead",
        "summary": "Create a new contact or company",
        "tags": [
          "leads"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Set to \"unassigned\" to assign this lead to all agents, or provide a specific agent_id to assign it to an agent (optional)"
                  },
                  "leadtypedatal": {
                    "type": "string",
                    "description": "Identifier of the contact or company type (optional)"
                  },
                  "ESCOMPANIES": {
                    "type": "string",
                    "description": "Set to \"y\" if it is a company (optional)"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID",
                    "example": "0"
                  },
                  "name": {
                    "type": "string",
                    "description": "Name for the contact",
                    "example": "Marc"
                  },
                  "lastname": {
                    "type": "string",
                    "description": "Last name",
                    "example": "Doe"
                  },
                  "phone": {
                    "type": "string",
                    "description": "Phone with international prefix",
                    "example": "34682288888"
                  },
                  "email": {
                    "type": "string",
                    "description": "Email",
                    "example": "example@exampleemail.com"
                  },
                  "country": {
                    "type": "string",
                    "description": "Country ISO code",
                    "example": "es"
                  },
                  "add_note": {
                    "type": "string",
                    "description": "Add a note to this contact or company (optional)"
                  },
                  "in_leadcompany": {
                    "type": "string",
                    "description": "ID of the company this contact belongs to (optional)"
                  }
                },
                "required": [
                  "token",
                  "status",
                  "name",
                  "lastname",
                  "phone",
                  "email",
                  "country"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/leads/edit.json": {
      "post": {
        "operationId": "edit_lead",
        "summary": "Edit a contact or company",
        "tags": [
          "leads"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "ID of the contact or company to edit"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Set to \"unassigned\" to assign this lead to all agents, or provide a specific agent_id to assign it to an agent (optional)"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID",
                    "example": "0"
                  },
                  "name": {
                    "type": "string",
                    "description": "Name of the contact or company",
                    "example": "Marc"
                  },
                  "lastname": {
                    "type": "string",
                    "description": "Last name",
                    "example": "Doe"
                  },
                  "phone": {
                    "type": "string",
                    "description": "Phone number with international prefix",
                    "example": "34682288888"
                  },
                  "email": {
                    "type": "string",
                    "description": "Email",
                    "example": "example@exampleemail.com"
                  },
                  "country": {
                    "type": "string",
                    "description": "Country ISO code",
                    "example": "es"
                  }
                },
                "required": [
                  "token",
                  "lead_id",
                  "status",
                  "name",
                  "lastname",
                  "phone",
                  "email",
                  "country"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/leads/delete.json": {
      "post": {
        "operationId": "delete_lead",
        "summary": "Delete a contact or company",
        "tags": [
          "leads"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "ID of the contact or company to delete"
                  }
                },
                "required": [
                  "token",
                  "lead_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/leads/get.json": {
      "post": {
        "operationId": "get_leads",
        "summary": "Get a list of contacts or companies",
        "tags": [
          "leads"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  },
                  "var_status": {
                    "type": "string",
                    "description": "Show only results with this status (optional)"
                  },
                  "var_agentfilter": {
                    "type": "string",
                    "description": "Show only results for this agent ID (optional)"
                  },
                  "search_value": {
                    "type": "string",
                    "description": "Text to search for (optional)"
                  },
                  "filter_types": {
                    "type": "string",
                    "description": "Filter type for the search value (optional)"
                  },
                  "datefrom": {
                    "type": "string",
                    "description": "Start date for filtering results (optional, format: YYYY-MM-DD, example: 2026-01-01). Requires dateto and timezone to apply."
                  },
                  "dateto": {
                    "type": "string",
                    "description": "End date for filtering results (optional, format: YYYY-MM-DD, example: 2026-12-31). Requires datefrom and timezone to apply."
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering (optional, example: Europe/Madrid). Required together with datefrom and dateto.",
                    "example": "Europe/Madrid"
                  }
                },
                "required": [
                  "token",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/leads/addnote.json": {
      "post": {
        "operationId": "add_note_to_lead",
        "summary": "Add a note to the contact or company",
        "tags": [
          "leads"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "ID of the contact or company"
                  },
                  "text": {
                    "type": "string",
                    "description": "Text of the note",
                    "example": "Hello world"
                  }
                },
                "required": [
                  "token",
                  "lead_id",
                  "text"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tickets/create.json": {
      "post": {
        "operationId": "create_ticket",
        "summary": "Create a new ticket",
        "tags": [
          "tickets"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Set to \"unassigned\" to assign this ticket to all agents, or provide a specific agent_id (optional)",
                    "example": "unassigned"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "ID of the contact or company"
                  },
                  "ticketname": {
                    "type": "string",
                    "description": "Name for the ticket",
                    "example": "Name for the ticket"
                  },
                  "ticketdescription": {
                    "type": "string",
                    "description": "Description for the ticket",
                    "example": "Description for the ticket"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID",
                    "example": "0"
                  },
                  "pipeline": {
                    "type": "string",
                    "description": "Pipeline ID (optional)"
                  },
                  "ticketvisiblecabinet": {
                    "type": "string",
                    "description": "Visible in client cabinet (optional)"
                  }
                },
                "required": [
                  "token",
                  "lead_id",
                  "ticketname",
                  "ticketdescription",
                  "status"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tickets/get.json": {
      "post": {
        "operationId": "get_tickets",
        "summary": "Get a list of tickets",
        "tags": [
          "tickets"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  },
                  "var_status": {
                    "type": "string",
                    "description": "Show only results with this status (optional)"
                  },
                  "var_agentfilter": {
                    "type": "string",
                    "description": "Show only results for this agent ID (optional)"
                  },
                  "search_value": {
                    "type": "string",
                    "description": "Text to search for (optional)"
                  },
                  "datefrom": {
                    "type": "string",
                    "description": "Start date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "dateto": {
                    "type": "string",
                    "description": "End date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering (optional, example: Europe/Madrid)"
                  }
                },
                "required": [
                  "token",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tickets/edit.json": {
      "post": {
        "operationId": "edit_ticket",
        "summary": "Edit a ticket",
        "tags": [
          "tickets"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "ticket_id": {
                    "type": "string",
                    "description": "ID of the ticket to edit"
                  },
                  "ticketname": {
                    "type": "string",
                    "description": "Name for the ticket (optional)"
                  },
                  "ticketdescription": {
                    "type": "string",
                    "description": "Description for the ticket (optional)"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID (optional)"
                  },
                  "pipeline": {
                    "type": "string",
                    "description": "Pipeline ID (optional)"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Agent ID or \"unassigned\" (optional)"
                  }
                },
                "required": [
                  "token",
                  "ticket_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tickets/delete.json": {
      "post": {
        "operationId": "delete_ticket",
        "summary": "Delete a ticket",
        "tags": [
          "tickets"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "ticket_id": {
                    "type": "string",
                    "description": "ID of the ticket to delete"
                  }
                },
                "required": [
                  "token",
                  "ticket_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tickets/addnote.json": {
      "post": {
        "operationId": "add_note_to_ticket",
        "summary": "Add a note to a ticket",
        "tags": [
          "tickets"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "ticket_id": {
                    "type": "string",
                    "description": "ID of the ticket"
                  },
                  "text": {
                    "type": "string",
                    "description": "Text of the note",
                    "example": "Hello world"
                  }
                },
                "required": [
                  "token",
                  "ticket_id",
                  "text"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/opportunities/create.json": {
      "post": {
        "operationId": "create_opportunity",
        "summary": "Create a new opportunity",
        "tags": [
          "opportunities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Agent ID (optional)",
                    "example": "unassigned"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "ID of the contact or company"
                  },
                  "description": {
                    "type": "string",
                    "description": "Description of the opportunity",
                    "example": "New opportunity"
                  },
                  "amount": {
                    "type": "string",
                    "description": "Total amount",
                    "example": "10"
                  },
                  "currency": {
                    "type": "string",
                    "description": "Currency",
                    "example": "eur"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID",
                    "example": "0"
                  },
                  "statusd": {
                    "type": "string",
                    "description": "Stage (optional)"
                  },
                  "pipeline": {
                    "type": "string",
                    "description": "Pipeline ID (optional)"
                  },
                  "expecteddate": {
                    "type": "string",
                    "description": "Expected closing date and time in ONE field: unix timestamp in SECONDS, not milliseconds. The timezone MUST be UTC (optional, recommended; example: 1789041600 = 2026-09-10T12:00:00Z). Convert the user's local time to UTC before sending. Legacy 'YYYY-MM-DD' string also accepted combined with 'time' — legacy values MUST be in UTC too.",
                    "example": "1789041600"
                  },
                  "time": {
                    "type": "string",
                    "description": "Legacy: time HH:MM in UTC, only used when expecteddate is sent as 'YYYY-MM-DD' (optional)"
                  },
                  "calendar_id": {
                    "type": "string",
                    "description": "Calendar task ID (optional)"
                  }
                },
                "required": [
                  "token",
                  "lead_id",
                  "description",
                  "amount",
                  "currency",
                  "status"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/opportunities/get.json": {
      "post": {
        "operationId": "get_opportunities",
        "summary": "Get a list of opportunities. Each result includes 'expecteddate': expected closing date+time as a unix timestamp in SECONDS, timezone UTC (example: 1789041600 = 2026-09-10T12:00:00Z).",
        "tags": [
          "opportunities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  },
                  "var_status": {
                    "type": "string",
                    "description": "Show only results with this status (optional)"
                  },
                  "var_agentfilter": {
                    "type": "string",
                    "description": "Show only results for this agent ID (optional)"
                  },
                  "search_value": {
                    "type": "string",
                    "description": "Text to search for (optional)"
                  },
                  "datefrom": {
                    "type": "string",
                    "description": "Start date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "dateto": {
                    "type": "string",
                    "description": "End date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering (optional, example: Europe/Madrid)"
                  }
                },
                "required": [
                  "token",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/opportunities/edit.json": {
      "post": {
        "operationId": "edit_opportunity",
        "summary": "Edit an opportunity",
        "tags": [
          "opportunities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "opportunity_id": {
                    "type": "string",
                    "description": "ID of the opportunity to edit"
                  },
                  "description": {
                    "type": "string",
                    "description": "Description of the opportunity (optional)"
                  },
                  "amount": {
                    "type": "string",
                    "description": "Total amount (optional)"
                  },
                  "currency": {
                    "type": "string",
                    "description": "Currency (optional)"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID (optional)"
                  },
                  "pipeline": {
                    "type": "string",
                    "description": "Pipeline ID (optional)"
                  },
                  "expecteddate": {
                    "type": "string",
                    "description": "Expected closing date and time in ONE field: unix timestamp in SECONDS, not milliseconds. The timezone MUST be UTC (optional, recommended; example: 1789041600 = 2026-09-10T12:00:00Z). Convert the user's local time to UTC before sending. Legacy 'YYYY-MM-DD' string also accepted combined with 'time' — legacy values MUST be in UTC too.",
                    "example": "1789041600"
                  },
                  "time": {
                    "type": "string",
                    "description": "Legacy: time HH:MM in UTC, only used when expecteddate is sent as 'YYYY-MM-DD' (optional)"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Agent ID or \"unassigned\" (optional)"
                  }
                },
                "required": [
                  "token",
                  "opportunity_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/opportunities/delete.json": {
      "post": {
        "operationId": "delete_opportunity",
        "summary": "Delete an opportunity",
        "tags": [
          "opportunities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "opportunity_id": {
                    "type": "string",
                    "description": "ID of the opportunity to delete"
                  }
                },
                "required": [
                  "token",
                  "opportunity_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/opportunities/addnote.json": {
      "post": {
        "operationId": "add_note_to_opportunity",
        "summary": "Add a note to an opportunity",
        "tags": [
          "opportunities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "opportunity_id": {
                    "type": "string",
                    "description": "ID of the opportunity"
                  },
                  "text": {
                    "type": "string",
                    "description": "Text of the note",
                    "example": "Hello world"
                  }
                },
                "required": [
                  "token",
                  "opportunity_id",
                  "text"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tasks/get.json": {
      "post": {
        "operationId": "get_tasks",
        "summary": "Get a list of tasks. Each result includes 'datestartunixutc' and 'dateendunixutc': start/end date+time as unix timestamps in SECONDS, timezone UTC (example: 1789041600 = 2026-09-10T12:00:00Z), plus the legacy date/time/dateEND/timeEND strings (also UTC).",
        "tags": [
          "tasks"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  },
                  "var_status": {
                    "type": "string",
                    "description": "Show only results with this status (optional)"
                  },
                  "var_agentfilter": {
                    "type": "string",
                    "description": "Show only results for this agent ID (optional)"
                  },
                  "search_value": {
                    "type": "string",
                    "description": "Text to search for (optional)"
                  },
                  "datefrom": {
                    "type": "string",
                    "description": "Start date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "dateto": {
                    "type": "string",
                    "description": "End date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering (optional, example: Europe/Madrid)"
                  }
                },
                "required": [
                  "token",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tasks/edit.json": {
      "post": {
        "operationId": "edit_task",
        "summary": "Edit a task",
        "tags": [
          "tasks"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "task_id": {
                    "type": "string",
                    "description": "ID of the task to edit"
                  },
                  "subject": {
                    "type": "string",
                    "description": "Task subject (optional)"
                  },
                  "text": {
                    "type": "string",
                    "description": "Task description (optional)"
                  },
                  "datestartunixutc": {
                    "type": "string",
                    "description": "Task start date and time in ONE field: unix timestamp in SECONDS, not milliseconds. The timezone MUST be UTC (optional, recommended; example: 1789041600 = 2026-09-10T12:00:00Z). Convert the user's local time to UTC before sending. Replaces the legacy date+time pair.",
                    "example": "1789041600"
                  },
                  "dateendunixutc": {
                    "type": "string",
                    "description": "Task end date and time in ONE field: unix timestamp in SECONDS, not milliseconds. The timezone MUST be UTC (optional, recommended; example: 1789043400 = end 30 min after start). Convert the user's local time to UTC before sending. Replaces the legacy dateEND+timeEND pair.",
                    "example": "1789043400"
                  },
                  "date": {
                    "type": "string",
                    "description": "Legacy: task start date YYYY-MM-DD in UTC (optional; prefer datestartunixutc)"
                  },
                  "time": {
                    "type": "string",
                    "description": "Legacy: task start time HH:MM in UTC (optional; prefer datestartunixutc)"
                  },
                  "dateEND": {
                    "type": "string",
                    "description": "Legacy: task end date YYYY-MM-DD in UTC (optional; prefer dateendunixutc)"
                  },
                  "timeEND": {
                    "type": "string",
                    "description": "Legacy: task end time HH:MM in UTC (optional; prefer dateendunixutc)"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID (optional)"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Agent ID or \"unassigned\" (optional)"
                  }
                },
                "required": [
                  "token",
                  "task_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tasks/delete.json": {
      "post": {
        "operationId": "delete_task",
        "summary": "Delete a task",
        "tags": [
          "tasks"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "task_id": {
                    "type": "string",
                    "description": "ID of the task to delete"
                  }
                },
                "required": [
                  "token",
                  "task_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tasks/addnote.json": {
      "post": {
        "operationId": "add_note_to_task",
        "summary": "Add a note to a task",
        "tags": [
          "tasks"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "task_id": {
                    "type": "string",
                    "description": "ID of the task"
                  },
                  "text": {
                    "type": "string",
                    "description": "Text of the note",
                    "example": "Hello world"
                  }
                },
                "required": [
                  "token",
                  "task_id",
                  "text"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companies/get.json": {
      "post": {
        "operationId": "get_companies",
        "summary": "Get a list of companies",
        "tags": [
          "companies"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  },
                  "var_status": {
                    "type": "string",
                    "description": "Show only results with this status (optional)"
                  },
                  "var_agentfilter": {
                    "type": "string",
                    "description": "Show only results for this agent ID (optional)"
                  },
                  "search_value": {
                    "type": "string",
                    "description": "Text to search for (optional)"
                  },
                  "datefrom": {
                    "type": "string",
                    "description": "Start date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "dateto": {
                    "type": "string",
                    "description": "End date for filtering results (optional, format: YYYY-MM-DD)"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering (optional, example: Europe/Madrid)"
                  }
                },
                "required": [
                  "token",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companies/edit.json": {
      "post": {
        "operationId": "edit_company",
        "summary": "Edit a company",
        "tags": [
          "companies"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "company_lead_id": {
                    "type": "string",
                    "description": "ID of the company to edit"
                  },
                  "name": {
                    "type": "string",
                    "description": "Company name (optional)"
                  },
                  "phone": {
                    "type": "string",
                    "description": "Phone number with international prefix (optional)"
                  },
                  "email": {
                    "type": "string",
                    "description": "Email (optional)"
                  },
                  "country": {
                    "type": "string",
                    "description": "Country ISO code (optional)"
                  },
                  "status": {
                    "type": "string",
                    "description": "Status ID (optional)"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Agent ID or \"unassigned\" (optional)"
                  }
                },
                "required": [
                  "token",
                  "company_lead_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companies/delete.json": {
      "post": {
        "operationId": "delete_company",
        "summary": "Delete a company",
        "tags": [
          "companies"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "company_lead_id": {
                    "type": "string",
                    "description": "ID of the company to delete"
                  }
                },
                "required": [
                  "token",
                  "company_lead_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companies/addnote.json": {
      "post": {
        "operationId": "add_note_to_company",
        "summary": "Add a note to a company",
        "tags": [
          "companies"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "company_lead_id": {
                    "type": "string",
                    "description": "ID of the company"
                  },
                  "text": {
                    "type": "string",
                    "description": "Text of the note",
                    "example": "Hello world"
                  }
                },
                "required": [
                  "token",
                  "company_lead_id",
                  "text"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/payments/create.json": {
      "post": {
        "operationId": "create_payment",
        "summary": "Create a new payment record",
        "tags": [
          "payments"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Agent ID"
                  },
                  "id_lead": {
                    "type": "string",
                    "description": "ID of the contact or company"
                  },
                  "fromagent_id": {
                    "type": "string",
                    "description": "Agent ID who created the payment"
                  },
                  "ispayment": {
                    "type": "string",
                    "description": "Payment type flag"
                  },
                  "mt4_transtype": {
                    "type": "string",
                    "description": "Transaction type"
                  },
                  "name": {
                    "type": "string",
                    "description": "Payment name or description"
                  },
                  "mt4user": {
                    "type": "string",
                    "description": "MT4 user ID (optional)"
                  },
                  "amount": {
                    "type": "string",
                    "description": "Payment amount",
                    "example": "0"
                  },
                  "amount_usd": {
                    "type": "string",
                    "description": "Amount in USD (optional)"
                  },
                  "amount_eur": {
                    "type": "string",
                    "description": "Amount in EUR (optional)"
                  },
                  "currency": {
                    "type": "string",
                    "description": "Currency code",
                    "example": "eur"
                  },
                  "netcurrency": {
                    "type": "string",
                    "description": "Net currency (optional)"
                  },
                  "comission": {
                    "type": "string",
                    "description": "Commission amount (optional)"
                  }
                },
                "required": [
                  "token",
                  "agent_id",
                  "id_lead",
                  "fromagent_id",
                  "ispayment",
                  "mt4_transtype",
                  "name",
                  "amount",
                  "currency"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendsms/smsmt.json": {
      "post": {
        "operationId": "send_sms",
        "summary": "Send a transactional SMS (SMS-MT, mobile terminated) to a single phone number through the company's SMS provider. Use this when the user asks to send an SMS, a short text, a verification code, an OTP, a reminder, a notification or any text message to a phone number. Before calling this, the caller must already know the destination phone number in international format (country code + number, no '+' or spaces), the text body, and a 'from' sender ID (alphanumeric up to 11 chars, e.g. 'MyCompany', or a numeric shortcode). If you do not have a valid sender, ask the user which 'from' to use — do NOT invent one. To estimate the cost per destination country before sending, call /api/1.0/sendsms/prices.json first. Optionally attach a lead_id so the message is logged inside that lead's timeline.",
        "tags": [
          "sendsms"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "to": {
                    "type": "string",
                    "description": "Recipient phone number in international format, digits only, with country code and no '+' sign or spaces (e.g. 34600000000 for Spain, 14155552671 for USA). Required.",
                    "example": "34682288834"
                  },
                  "from": {
                    "type": "string",
                    "description": "Sender ID displayed to the recipient. Alphanumeric up to 11 characters (e.g. 'Datalyse', 'Acme'), or a numeric shortcode. Some carriers strip or rewrite alphanumeric senders — ask the user for a valid one if unsure. Required.",
                    "example": "testfrom"
                  },
                  "text": {
                    "type": "string",
                    "description": "UTF-8 body of the SMS. Keep under 160 GSM-7 characters to fit in one segment; longer texts are split into multiple segments and billed per segment. Required.",
                    "example": "hello world"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "Optional Mongo ObjectId of the lead to attach this SMS to. When provided, the message is stored inside that lead's activity timeline. Optional."
                  }
                },
                "required": [
                  "token",
                  "to",
                  "from",
                  "text"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendsms/prices.json": {
      "get": {
        "operationId": "get_sms_prices",
        "summary": "Get SMS pricing list, optionally filtered by country",
        "tags": [
          "sendsms"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "country",
            "in": "query",
            "required": false,
            "description": "Country ISO code to filter prices (optional)",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/emails/unsubscribe.json": {
      "get": {
        "operationId": "email_unsubscribe",
        "summary": "Unsubscribe an email address",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "email",
            "in": "query",
            "required": true,
            "description": "Email address to unsubscribe",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/emails/send.json": {
      "post": {
        "operationId": "email_send",
        "summary": "Send an email",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "to": {
                    "type": "string",
                    "description": "Recipient email address"
                  },
                  "subject": {
                    "type": "string",
                    "description": "Email subject",
                    "example": "Hello"
                  },
                  "html": {
                    "type": "string",
                    "description": "Email body in HTML",
                    "example": "<p>Hello world</p>"
                  },
                  "cc": {
                    "type": "string",
                    "description": "CC recipients (optional)"
                  },
                  "bcc": {
                    "type": "string",
                    "description": "BCC recipients (optional)"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "Associate email with a contact ID (optional)"
                  },
                  "opportunity_id": {
                    "type": "string",
                    "description": "Associate email with an opportunity ID (optional)"
                  },
                  "signature_id": {
                    "type": "string",
                    "description": "Append this signature to the email (optional, get from signatures/get)"
                  },
                  "tracking": {
                    "type": "string",
                    "description": "Enable open tracking, set to \"y\" (optional)"
                  }
                },
                "required": [
                  "token",
                  "to",
                  "subject",
                  "html"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/get.json": {
      "post": {
        "operationId": "email_get_inbox",
        "summary": "Get emails from inbox or sent folder",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "type": {
                    "type": "string",
                    "description": "Folder: \"inbox\" (default) or \"sent\"",
                    "example": "inbox"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  },
                  "search_value": {
                    "type": "string",
                    "description": "Search in subject (optional)"
                  },
                  "unread_only": {
                    "type": "string",
                    "description": "Show only unread, set to \"y\" (optional)"
                  }
                },
                "required": [
                  "token",
                  "type",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/getone.json": {
      "post": {
        "operationId": "email_get_one",
        "summary": "Get a single email with full body",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "email_id": {
                    "type": "string",
                    "description": "ID of the email"
                  }
                },
                "required": [
                  "token",
                  "email_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/signatures/get.json": {
      "post": {
        "operationId": "email_get_signatures",
        "summary": "Get all email signatures",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/signatures/save.json": {
      "post": {
        "operationId": "email_save_signature",
        "summary": "Create or update an email signature",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "signature_id": {
                    "type": "string",
                    "description": "ID of signature to update (omit to create new)"
                  },
                  "name": {
                    "type": "string",
                    "description": "Signature name",
                    "example": "My Signature"
                  },
                  "html": {
                    "type": "string",
                    "description": "Signature HTML content",
                    "example": "<p>Best regards</p>"
                  },
                  "is_default": {
                    "type": "string",
                    "description": "Set as default signature, \"true\" or \"false\"",
                    "example": "false"
                  }
                },
                "required": [
                  "token",
                  "signature_id",
                  "name",
                  "html",
                  "is_default"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/signatures/delete.json": {
      "post": {
        "operationId": "email_delete_signature",
        "summary": "Delete an email signature",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "signature_id": {
                    "type": "string",
                    "description": "ID of the signature to delete"
                  }
                },
                "required": [
                  "token",
                  "signature_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/templates/get.json": {
      "post": {
        "operationId": "email_get_templates",
        "summary": "Get all email templates",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/templates/create.json": {
      "post": {
        "operationId": "email_create_template",
        "summary": "Create a new email template",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "name": {
                    "type": "string",
                    "description": "Template name",
                    "example": "My Template"
                  },
                  "subject": {
                    "type": "string",
                    "description": "Default email subject (optional)"
                  },
                  "html": {
                    "type": "string",
                    "description": "Template HTML content",
                    "example": "<p>Hello {{name}}</p>"
                  }
                },
                "required": [
                  "token",
                  "name",
                  "html"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/templates/edit.json": {
      "post": {
        "operationId": "email_edit_template",
        "summary": "Edit an email template",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "template_id": {
                    "type": "string",
                    "description": "ID of the template to edit"
                  },
                  "name": {
                    "type": "string",
                    "description": "Template name (optional)"
                  },
                  "subject": {
                    "type": "string",
                    "description": "Default email subject (optional)"
                  },
                  "html": {
                    "type": "string",
                    "description": "Template HTML content (optional)"
                  }
                },
                "required": [
                  "token",
                  "template_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/emails/templates/delete.json": {
      "post": {
        "operationId": "email_delete_template",
        "summary": "Delete an email template",
        "tags": [
          "emails"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "template_id": {
                    "type": "string",
                    "description": "ID of the template to delete"
                  }
                },
                "required": [
                  "token",
                  "template_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/countries.json": {
      "get": {
        "operationId": "phonenumbers_get_countries",
        "summary": "Get all countries with phone numbers available for purchase: ISO code, name, phone prefix, available number types and how many area groups each one has. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/did_groups.json": {
      "get": {
        "operationId": "phonenumbers_get_did_groups",
        "summary": "Get purchasable number groups (area codes) of a country with client prices in EUR. Each group lists its SKUs (capacity plans): setup and monthly price, included channels, per-minute incoming cost (coste_xmin/coste_xllam, 0 for flat-rate plans) and whether the plan is sellable. needs_registration=true means identity documents are required after purchase. Global/UIFN groups are returned for any country. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "country",
            "in": "query",
            "required": true,
            "description": "Country ISO2 code (e.g. ES, GB, US)",
            "schema": {
              "type": "string",
              "example": "ES"
            }
          },
          {
            "name": "type",
            "in": "query",
            "required": false,
            "description": "Filter by group type: Local, National, Mobile, Toll-free, Shared Cost, Global (optional)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "q",
            "in": "query",
            "required": false,
            "description": "Search by area name or prefix (optional)",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/available_dids.json": {
      "get": {
        "operationId": "phonenumbers_get_available_dids",
        "summary": "Get the specific numbers available to pick inside a DID group (live from the provider). If the list is empty a new random number can still be ordered (new_number_available is always true). Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "did_group",
            "in": "query",
            "required": true,
            "description": "DID group id (from did_groups.json)",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/order.json": {
      "post": {
        "operationId": "phonenumbers_order",
        "summary": "Buy a phone number: creates the order at the provider, charges the voice credit balance and assigns the line to a PBX (creates a new PBX with a default IVR if none is given). If needs_registration is true the number requires identity verification (see requirements, identity and identity_submit endpoints). The line starts as activating (estado 0) and switches to active automatically when the provider confirms. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "did_group_id": {
                    "type": "string",
                    "description": "DID group id (from did_groups.json)"
                  },
                  "sku_id": {
                    "type": "string",
                    "description": "Capacity plan SKU id of the group (from did_groups.json, only sellable SKUs)"
                  },
                  "available_did_id": {
                    "type": "string",
                    "description": "Specific number picked from available_dids.json; omit to get a new random number (optional)"
                  },
                  "idcampanadondecrear": {
                    "type": "integer",
                    "description": "PBX id where to attach the number; omit to create a new PBX with a default IVR (optional)"
                  },
                  "lang": {
                    "type": "string",
                    "description": "2-letter language for the default IVR TTS voice when a new PBX is created (optional, default en)"
                  }
                },
                "required": [
                  "token",
                  "did_group_id",
                  "sku_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/requirements.json": {
      "get": {
        "operationId": "phonenumbers_get_requirements",
        "summary": "Get the regulatory registration requirements of a DID group: accepted identity/address proof types, mandatory identity fields and permanent document templates. Returns needs_registration=false with an empty list when no registration is needed. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "did_group_id",
            "in": "query",
            "required": true,
            "description": "DID group id (from did_groups.json)",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/identity.json": {
      "post": {
        "operationId": "phonenumbers_create_identity",
        "summary": "Create a regulatory identity with its address at the provider (needed for numbers with needs_registration). Returns identity_id and address_id to use with identity_document.json and identity_submit.json. The identity is saved and reusable for future numbers (see identities_list.json). Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "identity.identity_type": {
                    "type": "string",
                    "description": "Identity type: personal or business",
                    "example": "personal"
                  },
                  "identity.first_name": {
                    "type": "string",
                    "description": "First name (or legal representative for business)"
                  },
                  "identity.last_name": {
                    "type": "string",
                    "description": "Last name"
                  },
                  "identity.phone_number": {
                    "type": "string",
                    "description": "Contact phone number with international prefix"
                  },
                  "identity.company_name": {
                    "type": "string",
                    "description": "Company name (business identities)"
                  },
                  "identity.company_reg_number": {
                    "type": "string",
                    "description": "Company registration number (if required by the country)"
                  },
                  "identity.vat_id": {
                    "type": "string",
                    "description": "VAT id (if required by the country)"
                  },
                  "identity.personal_tax_id": {
                    "type": "string",
                    "description": "Personal tax id (if required by the country)"
                  },
                  "identity.id_number": {
                    "type": "string",
                    "description": "Personal id/passport number (if required by the country)"
                  },
                  "identity.birth_date": {
                    "type": "string",
                    "description": "Birth date YYYY-MM-DD (if required by the country)"
                  },
                  "identity.contact_email": {
                    "type": "string",
                    "description": "Contact email (optional)"
                  },
                  "address.country_iso": {
                    "type": "string",
                    "description": "Address country ISO2 code",
                    "example": "ES"
                  },
                  "address.city_name": {
                    "type": "string",
                    "description": "City"
                  },
                  "address.postal_code": {
                    "type": "string",
                    "description": "Postal code"
                  },
                  "address.address": {
                    "type": "string",
                    "description": "Street address"
                  },
                  "address.description": {
                    "type": "string",
                    "description": "Address description (optional)"
                  }
                },
                "required": [
                  "token",
                  "identity.identity_type",
                  "identity.first_name",
                  "identity.last_name",
                  "identity.phone_number",
                  "identity.company_name",
                  "identity.company_reg_number",
                  "identity.vat_id",
                  "identity.personal_tax_id",
                  "identity.id_number",
                  "identity.birth_date",
                  "address.country_iso",
                  "address.city_name",
                  "address.postal_code",
                  "address.address"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/identities_list.json": {
      "get": {
        "operationId": "phonenumbers_list_identities",
        "summary": "List the client's saved regulatory identities with their addresses and verification status, to reuse them when registering another number. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/address.json": {
      "post": {
        "operationId": "phonenumbers_create_address",
        "summary": "Add an additional address to one of the client's existing regulatory identities (identity reuse for a number in another city/country). Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "identity_id": {
                    "type": "string",
                    "description": "Identity id owned by the client (from identities_list.json)"
                  },
                  "address.country_iso": {
                    "type": "string",
                    "description": "Address country ISO2 code",
                    "example": "ES"
                  },
                  "address.city_name": {
                    "type": "string",
                    "description": "City"
                  },
                  "address.postal_code": {
                    "type": "string",
                    "description": "Postal code"
                  },
                  "address.address": {
                    "type": "string",
                    "description": "Street address"
                  },
                  "address.description": {
                    "type": "string",
                    "description": "Address description (optional)"
                  }
                },
                "required": [
                  "token",
                  "identity_id",
                  "address.country_iso",
                  "address.city_name",
                  "address.postal_code",
                  "address.address"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/identity_document.json": {
      "post": {
        "operationId": "phonenumbers_upload_identity_document",
        "summary": "Upload a verification document (multipart form-data, field name: file; pdf/jpg/png, max 20MB). The file is encrypted client-side before being sent to the provider. kind=proof_identity links it to an identity (needs proof_type_id), kind=proof_address to an address (needs proof_type_id and address_id), kind=permanent_document to a permanent template (needs template_id). Proof type and template ids come from requirements.json. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "file": {
                    "type": "file",
                    "description": "Document file (multipart form-data; pdf, jpg or png, max 20MB)"
                  },
                  "kind": {
                    "type": "string",
                    "description": "Document kind: proof_identity, proof_address or permanent_document",
                    "example": "proof_identity"
                  },
                  "identity_id": {
                    "type": "string",
                    "description": "Identity id owned by the client (required for proof_identity and permanent_document)"
                  },
                  "proof_type_id": {
                    "type": "string",
                    "description": "Proof type id from requirements.json (required for proof_identity and proof_address)"
                  },
                  "address_id": {
                    "type": "string",
                    "description": "Address id the proof belongs to (required for proof_address)"
                  },
                  "template_id": {
                    "type": "string",
                    "description": "Permanent document template id from requirements.json (required for permanent_document)"
                  },
                  "description": {
                    "type": "string",
                    "description": "File description (optional)"
                  }
                },
                "required": [
                  "token",
                  "file",
                  "kind",
                  "identity_id",
                  "proof_type_id",
                  "address_id",
                  "template_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/identity_submit.json": {
      "post": {
        "operationId": "phonenumbers_submit_identity",
        "summary": "Submit the address verification of a purchased number for provider review. Optionally pre-validates against the address requirement so missing data is reported instantly (validation_failed) instead of days later as a rejection. On approval the line is activated automatically and the user gets a push notification. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "did_id": {
                    "type": "string",
                    "description": "DID id of the purchased number (returned by order.json)"
                  },
                  "address_id": {
                    "type": "string",
                    "description": "Address id of one of the client's identities"
                  },
                  "identity_id": {
                    "type": "string",
                    "description": "Identity id, when the address alone is ambiguous (optional)"
                  },
                  "address_requirement_id": {
                    "type": "string",
                    "description": "Address requirement id from requirements.json to pre-validate before submitting (optional, recommended)"
                  },
                  "service_description": {
                    "type": "string",
                    "description": "Short description of the service using the number (optional, default: CRM phone line)"
                  }
                },
                "required": [
                  "token",
                  "did_id",
                  "address_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/identity_status.json": {
      "get": {
        "operationId": "phonenumbers_get_identity_status",
        "summary": "Get the live verification status of a number registration (pending, approved or rejected with reject reasons). If the provider already approved it, the line is activated on the spot. Pass did_id or verification_id. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "did_id",
            "in": "query",
            "required": true,
            "description": "DID id of the number (alternative to verification_id)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "verification_id",
            "in": "query",
            "required": true,
            "description": "Verification id returned by identity_submit.json (alternative to did_id)",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/pending_registrations.json": {
      "get": {
        "operationId": "phonenumbers_get_pending_registrations",
        "summary": "Get the client's numbers with identity registration pending (not sent, in review or rejected) plus the numbers still activating (bought without registration, waiting for provider confirmation, last 72h). Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/capacity_info.json": {
      "get": {
        "operationId": "phonenumbers_get_capacity_info",
        "summary": "Get the current channel capacity of a phone line (included and dedicated channels) and the monthly price per extra dedicated channel in EUR. pool_disponible=false means extra channels are not available for that country. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "phoneline",
            "in": "query",
            "required": true,
            "description": "Phone line number (digits only, with country prefix)",
            "schema": {
              "type": "string",
              "example": "34930000000"
            }
          }
        ]
      }
    },
    "/api/1.0/phonenumbers/contract_channels.json": {
      "post": {
        "operationId": "phonenumbers_contract_channels",
        "summary": "Buy extra dedicated channels for a phone line (1 to 50). Charges the voice credit balance, expands the DID capacity at the provider and adds the price to the line's monthly renewal. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "phoneline": {
                    "type": "string",
                    "description": "Phone line number (digits only, with country prefix)",
                    "example": "34930000000"
                  },
                  "channels": {
                    "type": "integer",
                    "description": "Number of dedicated channels to add (1-50)",
                    "example": "1"
                  }
                },
                "required": [
                  "token",
                  "phoneline",
                  "channels"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/move.json": {
      "post": {
        "operationId": "phonenumbers_move",
        "summary": "Move a phone number to another PBX of the same client, or create a new PBX (with a default IVR) and move it there. Identify the line with phoneline or id_alias; set to_pbx_id for an existing PBX or new_pbx=true to create one. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "phoneline": {
                    "type": "string",
                    "description": "Phone line number to move (alternative to id_alias)",
                    "example": "34930000000"
                  },
                  "id_alias": {
                    "type": "integer",
                    "description": "Internal line id (alternative to phoneline)"
                  },
                  "to_pbx_id": {
                    "type": "integer",
                    "description": "Destination PBX id (required unless new_pbx is true)"
                  },
                  "new_pbx": {
                    "type": "boolean",
                    "description": "Set to true to create a new PBX and move the number there"
                  },
                  "new_pbx_name": {
                    "type": "string",
                    "description": "Name for the new PBX (optional, only with new_pbx)"
                  },
                  "lang": {
                    "type": "string",
                    "description": "2-letter language for the new PBX default IVR TTS voice (optional, default en)"
                  }
                },
                "required": [
                  "token",
                  "phoneline",
                  "id_alias",
                  "to_pbx_id",
                  "new_pbx"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/clone_pbx.json": {
      "post": {
        "operationId": "phonenumbers_clone_pbx",
        "summary": "Clone a PBX: campaign, configuration and all call-flow nodes (node links are remapped). Phone numbers are NOT cloned. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "pbx_id": {
                    "type": "integer",
                    "description": "PBX id to clone (must belong to the client)"
                  },
                  "new_name": {
                    "type": "string",
                    "description": "Name for the cloned PBX (optional, default: original name + (copy))"
                  }
                },
                "required": [
                  "token",
                  "pbx_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/phonenumbers/delete.json": {
      "post": {
        "operationId": "phonenumber_delete",
        "summary": "Cancel a phone line: terminates the number at the provider and removes the line. The purchase is refunded in credits only if cancelled the same month it was bought. The cancellation is irreversible. Requires phone numbers management permission.",
        "tags": [
          "phonenumbers"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "phoneline": {
                    "type": "string",
                    "description": "Phone line number to cancel (digits only, with country prefix)",
                    "example": "34930000000"
                  }
                },
                "required": [
                  "token",
                  "phoneline"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/check.json": {
      "get": {
        "operationId": "domain_check_availability",
        "summary": "Check domain availability and pricing. Returns availability status, price in credits, original price, current balance and whether the user can afford it.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "domain",
            "in": "query",
            "required": true,
            "description": "Domain name to check (e.g. example.com)",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/domains/register.json": {
      "post": {
        "operationId": "domain_register",
        "summary": "Register (buy) a new domain. Requires registrant contact info. Saves domain with status pending_verification, deducts credits from balance. Domain must be activated after email verification.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name to register"
                  },
                  "years": {
                    "type": "integer",
                    "description": "Number of years to register (default: 1)",
                    "example": "1"
                  },
                  "contact.firstName": {
                    "type": "string",
                    "description": "Registrant first name"
                  },
                  "contact.lastName": {
                    "type": "string",
                    "description": "Registrant last name"
                  },
                  "contact.address1": {
                    "type": "string",
                    "description": "Registrant address"
                  },
                  "contact.city": {
                    "type": "string",
                    "description": "Registrant city"
                  },
                  "contact.state": {
                    "type": "string",
                    "description": "Registrant state/province"
                  },
                  "contact.postalCode": {
                    "type": "string",
                    "description": "Registrant postal code"
                  },
                  "contact.country": {
                    "type": "string",
                    "description": "Registrant country code (e.g. ES, US)"
                  },
                  "contact.phone": {
                    "type": "string",
                    "description": "Registrant phone (e.g. +34.612345678)"
                  },
                  "contact.email": {
                    "type": "string",
                    "description": "Registrant email"
                  },
                  "contact.org": {
                    "type": "string",
                    "description": "Registrant organization (optional)"
                  },
                  "dnsRecords": {
                    "type": "array",
                    "description": "DNS records to configure (optional, uses defaults if not provided)"
                  },
                  "nameservers": {
                    "type": "array",
                    "description": "Custom nameservers (optional)"
                  },
                  "mail": {
                    "type": "boolean",
                    "description": "Enable mail configuration (optional)"
                  },
                  "defaultDns": {
                    "type": "boolean",
                    "description": "Use default DNS records (optional)"
                  }
                },
                "required": [
                  "token",
                  "domain",
                  "years",
                  "contact.firstName",
                  "contact.lastName",
                  "contact.address1",
                  "contact.city",
                  "contact.state",
                  "contact.postalCode",
                  "contact.country",
                  "contact.phone",
                  "contact.email"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/activate.json": {
      "post": {
        "operationId": "domain_activate",
        "summary": "Activate a pending domain after verification. Configures DNS records, registers domain in the mail server, creates reverse proxy routes for HTTPS (domain + www), sets default services (mail, web) and marks status as active.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name to activate"
                  }
                },
                "required": [
                  "token",
                  "domain"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/dns/add.json": {
      "post": {
        "operationId": "domain_dns_add_service",
        "summary": "Add or update a DNS record for a specific service (e.g. mail, web, web). Fetches existing records, adds/replaces the new one, and creates a reverse proxy route with automatic HTTPS if the service requires it.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name"
                  },
                  "type": {
                    "type": "string",
                    "description": "DNS record type (default: A)",
                    "example": "A"
                  },
                  "name": {
                    "type": "string",
                    "description": "DNS record name (default: @)",
                    "example": "@"
                  },
                  "content": {
                    "type": "string",
                    "description": "DNS record content (IP address or hostname)"
                  },
                  "ttl": {
                    "type": "integer",
                    "description": "TTL in seconds (default: 1800)",
                    "example": "1800"
                  },
                  "server": {
                    "type": "string",
                    "description": "Service key for tracking (e.g. mail, crm, web). Used to create reverse proxy route and save service status."
                  },
                  "priority": {
                    "type": "integer",
                    "description": "Priority for MX records (optional)"
                  }
                },
                "required": [
                  "token",
                  "domain",
                  "type",
                  "name",
                  "content",
                  "ttl",
                  "server"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/servers.json": {
      "get": {
        "operationId": "domain_get_services",
        "summary": "Get the status of all configured services for a domain. Returns each service key, status, host and value.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "domain",
            "in": "query",
            "required": true,
            "description": "Domain name to query",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/domains/managed.json": {
      "get": {
        "operationId": "domain_get_managed",
        "summary": "Get all domains managed by the user's company. Returns domains filtered by company_id with status, verification state, SMTP/IMAP config and services. Does not include shared platform domains.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          }
        ]
      }
    },
    "/api/1.0/domains/add.json": {
      "post": {
        "operationId": "domain_add_custom",
        "summary": "Add a custom (already owned) domain for verification. Saves it with status pending_verification and returns the required DNS records. The user must configure DNS and call dns/verify.json before activation.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name to add"
                  }
                },
                "required": [
                  "token",
                  "domain"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/dns/verify.json": {
      "get": {
        "operationId": "domain_dns_verify",
        "summary": "Verify DNS configuration for a domain. Performs real DNS lookups checking MX, SPF and DMARC records. If all pass, registers the domain in the mail server and marks it as active and verified.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "description": "API access token",
            "schema": {
              "type": "string",
              "example": "YOUR_APIKEY"
            }
          },
          {
            "name": "domain",
            "in": "query",
            "required": true,
            "description": "Domain name to verify",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/domains/delete_domain.json": {
      "post": {
        "operationId": "domain_delete",
        "summary": "Delete a domain completely. Removes all email accounts associated with that domain from the mail server, disconnects all agents using emails on that domain, removes all reverse proxy routes (domain, www, service subdomains), and deletes the domain record from the database. System domains cannot be deleted.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name to delete"
                  }
                },
                "required": [
                  "token",
                  "domain"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/renewdomain.json": {
      "post": {
        "operationId": "domain_renew",
        "summary": "Renew a registered domain. Verifies the domain belongs to the company, gets renewal pricing, checks credit balance, renews via the registrar, deducts credits and updates the expiry date in the database. External domains cannot be renewed from this platform. System domains cannot be renewed.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name to renew"
                  },
                  "years": {
                    "type": "number",
                    "description": "Number of years to renew (default: 1)",
                    "example": 1
                  }
                },
                "required": [
                  "token",
                  "domain",
                  "years"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/markasdelete.json": {
      "post": {
        "operationId": "domain_mark_delete",
        "summary": "Mark a domain for deletion. Changes the domain status to 'pending_delete' so it will not be automatically renewed when it expires. The domain is not deleted immediately — it remains active until expiration. System domains cannot be marked.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name to mark for deletion"
                  }
                },
                "required": [
                  "token",
                  "domain"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/domains/activate_services.json": {
      "post": {
        "operationId": "domain_activate_services",
        "summary": "Activate multiple services for a domain in a single API call. Accepts an array of service keys. For registered domains, creates all DNS records in a single batch call to the registrar. For external domains, verifies DNS is correctly configured before activating. Creates reverse proxy routes for each service that needs HTTPS.",
        "tags": [
          "domains"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "domain": {
                    "type": "string",
                    "description": "Domain name"
                  },
                  "services": {
                    "type": "array",
                    "description": "Array of service keys to activate: mail, web, crm, meets, infinitycloud, cabinet, webtrade",
                    "example": [
                      "crm",
                      "meets",
                      "mail"
                    ]
                  }
                },
                "required": [
                  "token",
                  "domain",
                  "services"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendwhatsapp/getsessionsandtemplates.json": {
      "post": {
        "operationId": "whatsapp_get_sessions_and_templates",
        "summary": "List every WhatsApp Business session connected to this company and, for each session, its approved Meta-hosted templates. Call this BEFORE using /api/1.0/sendwhatsapp/sendmsgtemplate.json, sendmsg.json or sendfile.json, because you need a valid 'idses' (session _id) to send anything, and for templates you also need to know the exact 'name', 'language' and the 'components' array (which defines what {{1}}, {{2}}... variables each template expects, and whether the HEADER is TEXT/IMAGE/VIDEO/DOCUMENT). Returns only the fields needed for dispatch: each session's _id and name, plus a whats_templates[] array with the template name, language, status, category, id and components. The caller must then pick the right session and template based on what the user wants to send.",
        "tags": [
          "sendwhatsapp"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendwhatsapp/sendmsgtemplate.json": {
      "post": {
        "operationId": "sendwhatsapp_sendmsgtemplate",
        "summary": "Send a pre-approved WhatsApp Business template message directly through the Meta Cloud API and return Meta's response synchronously (including the delivered message wamid on success, or Meta's error on failure). Use this to start conversations outside the 24-hour customer service window, to send transactional notifications (OTP, order updates, shipping, reminders), or to re-engage a lead when the free-form chat window is closed. MANDATORY WORKFLOW: (1) first call /api/1.0/sendwhatsapp/getsessionsandtemplates.json to discover the sessions and their approved templates; (2) pick the session 'idses' the user wants to send from and the exact 'template_name' that matches the intent; (3) inspect that template's 'components' array — if any component contains {{1}}, {{2}}, {{3}}... body variables, pass the matching values inside the simplified 'variables' field (the server auto-inspects the template and places each value in the correct Meta slot — you do NOT need to build the Meta components array yourself). If the template has ZERO body variables and no TEXT header variable, simply omit 'variables' entirely. IMPORTANT — MEDIA HEADERS (IMAGE/VIDEO/DOCUMENT): do NOT ask the user for a media URL and do NOT send 'variables.header' for these. The server auto-loads the media from the file that was originally uploaded with the template (infinitycloud), falling back to Meta's stored example. Only pass 'variables.header' as a media URL if the user explicitly asks to override the template's attached file with a different one. Never invent variable values — if the user did not provide body/text values, ask first. Unlike the old queue-based behaviour, this endpoint now POSTs to Meta synchronously: a successful response returns 'wamid' from Meta, and a failure returns status:'error' with the Meta error embedded.",
        "tags": [
          "sendwhatsapp"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "idses": {
                    "type": "string",
                    "description": "WhatsApp session _id (24-char Mongo ObjectId) identifying which WhatsApp Business number sends the message. Obtain it from /api/1.0/sendwhatsapp/getsessionsandtemplates.json. Required."
                  },
                  "to": {
                    "type": "string",
                    "description": "Recipient phone number in full international format, digits only, no '+' sign, no spaces, no dashes (e.g. 34600000000). Required.",
                    "example": "34682288834"
                  },
                  "template_name": {
                    "type": "string",
                    "description": "Exact 'name' field of the approved WhatsApp template to send (e.g. 'datalysewowia'). Must be one of the templates returned by getsessionsandtemplates for the chosen session. Required."
                  },
                  "language": {
                    "type": "string",
                    "description": "Template language code (e.g. 'es', 'en_US', 'pt_BR'). Optional: defaults to the template's own language. Only override it if you know the same template has multiple approved translations."
                  },
                  "variables": {
                    "type": "object",
                    "description": "Simplified template variables — the server auto-inspects the approved template's components and places each value in the correct Meta slot, so you do NOT build the Meta components array yourself. Shape: an object with any of these keys — 'body' is an array of strings matching the template BODY's {{1}},{{2}},... placeholders in order (e.g. body:['Marc','OFFER105']); 'header' is used ONLY when the template HEADER is TEXT with a {{1}} variable (value is the plain text) OR when the caller wants to explicitly override an IMAGE/VIDEO/DOCUMENT media template with a different public URL (normally you should NOT send 'header' for media templates — the server auto-loads the file that was uploaded with the template); 'button' is an array of URL-button values where each element is either a plain string or an object {index:N, payload:'...'} for button parameter {{1}}. Shortcuts: pass a bare array of strings (['123456','Marc']) to fill only body variables, or a bare string ('123456') for a single body variable. Count and order of 'body' entries MUST match the {{n}} placeholders in the template's BODY text — use /api/1.0/sendwhatsapp/getsessionsandtemplates.json to inspect the template first. Omit this field entirely when the template has no body variables.",
                    "example": {
                      "body": [
                        "123456"
                      ]
                    }
                  },
                  "components": {
                    "type": "array",
                    "description": "ADVANCED / OPTIONAL escape hatch. Pre-built Meta Cloud API components array in the exact Meta shape (entries like {type:'body', parameters:[{type:'text', text:'...'}]}). Only use this if you are replicating an existing hand-crafted Meta payload — normally you should use the simpler 'variables' field instead and let the server build the components automatically. If both 'components' and 'variables' are provided, 'components' wins.",
                    "example": [
                      {
                        "type": "body",
                        "parameters": [
                          {
                            "type": "text",
                            "text": "HOLA"
                          }
                        ]
                      }
                    ]
                  }
                },
                "required": [
                  "token",
                  "idses",
                  "to",
                  "template_name",
                  "variables"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendwhatsapp/sendmsg.json": {
      "post": {
        "operationId": "whatsapp_send_message",
        "summary": "Send a free-form WhatsApp text message from one of the company's WhatsApp Business numbers to a single recipient. IMPORTANT: WhatsApp only allows free-form messages when the recipient has messaged the business within the last 24 hours (the 'customer service window'). If that window is closed, Meta will reject the message and you must instead use /api/1.0/sendwhatsapp/sendmsgtemplate.json with an approved template. Before calling this, pick a valid 'idses' (session _id) from /api/1.0/sendwhatsapp/getsessionsandtemplates.json — that tells you which WhatsApp number sends the message. Never invent text content; use exactly what the user asked to send.",
        "tags": [
          "sendwhatsapp"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "idses": {
                    "type": "string",
                    "description": "WhatsApp session _id (24-char Mongo ObjectId) identifying which WhatsApp Business number sends the message. Obtain from /api/1.0/sendwhatsapp/getsessionsandtemplates.json. Required."
                  },
                  "to": {
                    "type": "string",
                    "description": "Recipient phone number in full international format, digits only, no '+' sign or spaces (e.g. 34600000000). Required.",
                    "example": "34682288834"
                  },
                  "text": {
                    "type": "string",
                    "description": "UTF-8 body of the WhatsApp message. Supports WhatsApp's basic markdown (*bold*, _italic_, ~strike~, ```mono```). Required.",
                    "example": "hello world"
                  }
                },
                "required": [
                  "token",
                  "idses",
                  "to",
                  "text"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendwhatsapp/sendfile.json": {
      "post": {
        "operationId": "whatsapp_send_file",
        "summary": "Send a media or document file (image, video, audio, PDF, spreadsheet, etc.) via WhatsApp to a single recipient, from one of the company's WhatsApp Business numbers. The file MUST already be hosted on a public HTTPS URL that Meta can download (no auth, no signed-url with short TTL). Same 24-hour free-form window rule as sendmsg.json: if the recipient has not written to the business in the last 24h, use sendmsgtemplate.json instead. Meta auto-detects the media type from the URL's Content-Type, so make sure the server returns the correct MIME. Optionally provide a 'filename' (mandatory for documents if you want the recipient to see a proper name) and a 'caption' that will display under images and videos.",
        "tags": [
          "sendwhatsapp"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "idses": {
                    "type": "string",
                    "description": "WhatsApp session _id (24-char Mongo ObjectId) identifying which WhatsApp Business number sends the file. Obtain from /api/1.0/sendwhatsapp/getsessionsandtemplates.json. Required."
                  },
                  "to": {
                    "type": "string",
                    "description": "Recipient phone number in full international format, digits only, no '+' sign or spaces (e.g. 34600000000). Required.",
                    "example": "34682288834"
                  },
                  "file_url": {
                    "type": "string",
                    "description": "Publicly reachable HTTPS URL of the file to send. Meta will fetch it; the host must serve the file without authentication and with the correct Content-Type header. Required."
                  },
                  "filename": {
                    "type": "string",
                    "description": "Display filename (including extension) shown to the recipient — especially important for PDFs and documents. Optional for images/videos."
                  },
                  "caption": {
                    "type": "string",
                    "description": "Optional caption text that appears under the media (images/videos only; ignored for audio and most document types)."
                  }
                },
                "required": [
                  "token",
                  "idses",
                  "to",
                  "file_url"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companyuserdata/companyproperties.json": {
      "post": {
        "operationId": "get_company_properties",
        "summary": "Get all statuses, and additional data for company",
        "tags": [
          "companyuserdata"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companyuserdata/getallagents.json": {
      "post": {
        "operationId": "get_all_agents",
        "summary": "Get all agents for the company",
        "tags": [
          "companyuserdata"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/payments/get.json": {
      "post": {
        "operationId": "get_payments",
        "summary": "Get a paginated list of payments/credits for the authenticated company. Supports filtering by payment type, lead, agent, and date range (datefrom/dateto/timezone). Dates are filtered against the payment 'date' field (unix timestamp in seconds). Use this to answer questions like 'show me payments last month', 'list credits for lead X', or 'how many payments did agent Y process in January'.",
        "tags": [
          "payments"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  },
                  "ispayment": {
                    "type": "string",
                    "description": "Filter by type: \"y\" for payments, \"n\" for credits (optional)"
                  },
                  "id_lead": {
                    "type": "string",
                    "description": "Filter by lead ID (optional)"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Filter by agent ID (optional)"
                  },
                  "datefrom": {
                    "type": "string",
                    "description": "Start date for filtering results by payment date (optional, format: YYYY-MM-DD, example: 2026-01-01). Requires dateto and timezone to apply."
                  },
                  "dateto": {
                    "type": "string",
                    "description": "End date for filtering results by payment date (optional, format: YYYY-MM-DD, example: 2026-12-31). Requires datefrom and timezone to apply."
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering (optional, example: Europe/Madrid). Required together with datefrom and dateto."
                  }
                },
                "required": [
                  "token",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/payments/edit.json": {
      "post": {
        "operationId": "edit_payment",
        "summary": "Edit a payment",
        "tags": [
          "payments"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "payment_id": {
                    "type": "string",
                    "description": "ID of the payment to edit"
                  },
                  "name": {
                    "type": "string",
                    "description": "Payment name (optional)"
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Agent ID (optional)"
                  },
                  "amount": {
                    "type": "string",
                    "description": "Payment amount (optional)"
                  },
                  "amount_usd": {
                    "type": "string",
                    "description": "Amount in USD (optional)"
                  },
                  "amount_eur": {
                    "type": "string",
                    "description": "Amount in EUR (optional)"
                  },
                  "currency": {
                    "type": "string",
                    "description": "Currency code (optional)"
                  },
                  "ispayment": {
                    "type": "string",
                    "description": "Payment type flag (optional)"
                  },
                  "mt4_transtype": {
                    "type": "string",
                    "description": "Transaction type (optional)"
                  }
                },
                "required": [
                  "token",
                  "payment_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/payments/delete.json": {
      "post": {
        "operationId": "delete_payment",
        "summary": "Delete a payment (soft delete)",
        "tags": [
          "payments"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "payment_id": {
                    "type": "string",
                    "description": "ID of the payment to delete"
                  }
                },
                "required": [
                  "token",
                  "payment_id"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/leads/getactivity.json": {
      "post": {
        "operationId": "get_lead_activity",
        "summary": "Get activity/timeline for a contact",
        "tags": [
          "leads"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "lead_id": {
                    "type": "string",
                    "description": "ID of the contact"
                  },
                  "type": {
                    "type": "string",
                    "description": "Filter by activity type: callin, callout, email, emailin, emailout, note, sms, form_completed, etc. (optional)"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  }
                },
                "required": [
                  "token",
                  "lead_id",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/opportunities/getactivity.json": {
      "post": {
        "operationId": "get_opportunity_activity",
        "summary": "Get activity/timeline for an opportunity",
        "tags": [
          "opportunities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "opportunity_id": {
                    "type": "string",
                    "description": "ID of the opportunity"
                  },
                  "type": {
                    "type": "string",
                    "description": "Filter by activity type (optional)"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  }
                },
                "required": [
                  "token",
                  "opportunity_id",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companies/getactivity.json": {
      "post": {
        "operationId": "get_company_activity",
        "summary": "Get activity/timeline for a company (includes activity from contacts inside the company)",
        "tags": [
          "companies"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "company_lead_id": {
                    "type": "string",
                    "description": "ID of the company"
                  },
                  "type": {
                    "type": "string",
                    "description": "Filter by activity type (optional)"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  }
                },
                "required": [
                  "token",
                  "company_lead_id",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tasks/getactivity.json": {
      "post": {
        "operationId": "get_task_activity",
        "summary": "Get activity/timeline for a task",
        "tags": [
          "tasks"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "task_id": {
                    "type": "string",
                    "description": "ID of the task"
                  },
                  "type": {
                    "type": "string",
                    "description": "Filter by activity type (optional)"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  }
                },
                "required": [
                  "token",
                  "task_id",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/tickets/getactivity.json": {
      "post": {
        "operationId": "get_ticket_activity",
        "summary": "Get activity/timeline for a ticket",
        "tags": [
          "tickets"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "ticket_id": {
                    "type": "string",
                    "description": "ID of the ticket"
                  },
                  "type": {
                    "type": "string",
                    "description": "Filter by activity type (optional)"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Maximum number of results to display",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number",
                    "example": "1"
                  }
                },
                "required": [
                  "token",
                  "ticket_id",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companyuserdata/getpricepercredit.json": {
      "post": {
        "operationId": "get_price_per_credit",
        "summary": "Get price per credit for VOIP calls and SMS, balance and plan info",
        "tags": [
          "companyuserdata"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companyuserdata/agentstypes.json": {
      "post": {
        "operationId": "get_agents_types",
        "summary": "Get all agent types (roles) for the company, including the number of agents assigned to each type",
        "tags": [
          "companyuserdata"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companyuserdata/callerids.json": {
      "post": {
        "operationId": "get_callerids",
        "summary": "List ALL outbound caller IDs (phone lines) the company can dial from, filtered by agent permissions and campaign access. Returns a JSON object { status: 'ok', callerids: [...] } where 'callerids' is an array with one entry per available line — typically several entries, not just one. Each entry has a 'host' field which is the phone number in international format (digits only, no '+'), plus 'id', 'id_campana', 'pais' (ISO 3166-1 numeric country code: 724=ES, 826=GB, 840=US, 33=FR, 49=DE, 39=IT, 351=PT, 52=MX, 55=BR, 54=AR), 'alias', 'estado', and cost fields ('coste_mes', 'coste_xllam', 'coste_xmin'). Virtual rows (rotation) have 'virtual':1 and a synthetic 'host' like '9992078'. When the user asks 'dame mis callerids' / 'qué líneas tengo' / 'all my numbers', you MUST call this endpoint and show EVERY entry in the returned 'callerids' array — never truncate, never show only the first one. Use the 'host' value as the caller_id parameter when calling /api/1.0/sendvoicecall/createcall.json.",
        "tags": [
          "companyuserdata"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendvoicecall/listaiagents.json": {
      "post": {
        "operationId": "sendvoicecall_listaiagents",
        "summary": "List every AI voice agent configured for this company. Call this BEFORE /api/1.0/sendvoicecall/createcall.json, because creating an AI call batch requires a valid 'agent_ai_id' — that id is the _id of one of the agents returned here. The response includes each agent's name, language, voice, system prompt summary and knowledge base so the caller can pick the agent that best fits the call's purpose (sales, support, appointment reminder, etc.). Does not place any call by itself.",
        "tags": [
          "sendvoicecall"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/sendvoicecall/createcall.json": {
      "post": {
        "operationId": "sendvoicecall_createcall",
        "summary": "Create a new AI voice call batch campaign that will phone one or more recipients using an AI agent. Use this when the user wants the system to actually place outbound phone calls (e.g. 'call these leads', 'phone these customers', 'launch a reminder call campaign'). MANDATORY WORKFLOW: (1) call /api/1.0/sendvoicecall/listaiagents.json to pick the right 'agent_ai_id' for the campaign's purpose; (2) call /api/1.0/companyuserdata/callerids.json to pick a valid 'caller_id' (one of the company's phone lines allowed to place outbound calls); (3) build the 'recipients' array with one entry per person to call, each with phone (international format, digits only), name and country ISO code. Optionally schedule the campaign: set mode='schedule' plus start_date/start_time/end_time/timezone, or mode='immediately' to dial as soon as the worker picks it up. Returns a batch_id that can be later used with getone.json, stop.json, pause.json and unpause.json. Never invent phone numbers — only use the ones the user explicitly provided or the ones retrieved from a previous query.",
        "tags": [
          "sendvoicecall"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "agent_ai_id": {
                    "type": "string",
                    "description": "Mongo ObjectId of the AI voice agent that will conduct the calls. Obtain from /api/1.0/sendvoicecall/listaiagents.json. Required."
                  },
                  "caller_id": {
                    "type": "string",
                    "description": "Phone number (caller id) the AI will dial out from. Must be one of the callerids available to the company — obtain from /api/1.0/companyuserdata/callerids.json. Can also be a shared caller id in the format 'compartido 999id_campana'. Required."
                  },
                  "batch_name": {
                    "type": "string",
                    "description": "Human-readable name for this call batch (shown in the UI and reports). Optional."
                  },
                  "recipients": {
                    "type": "array",
                    "description": "JSON array of call targets. Each element is an object with three string fields: 'phone' (international format, digits only, no '+' and no spaces, e.g. 34660558411), 'name' (display name, e.g. Marc) and 'country' (ISO 3166-1 alpha-2 lowercase, e.g. es, us, mx). At least one recipient is required. Pass it as a real JSON array of objects — do NOT wrap it in a string. See the 'default' field for a concrete example.",
                    "example": [
                      {
                        "name": "marc",
                        "phone": "34660558411",
                        "country": "es"
                      },
                      {
                        "name": "James",
                        "phone": "34682288834",
                        "country": "es"
                      }
                    ]
                  },
                  "mode": {
                    "type": "string",
                    "description": "Dispatch mode. 'immediately' (default) starts dialing as soon as the worker picks up the batch; 'schedule' uses the start_date/start_time/end_time/timezone fields below. Required.",
                    "example": "immediately"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "IANA timezone for start_date/start_time/end_time when mode='schedule' (e.g. 'Europe/Madrid', 'America/Mexico_City'). Optional, defaults to 'UTC'.",
                    "example": "UTC"
                  },
                  "start_date": {
                    "type": "string",
                    "description": "Date the campaign can start dialing, in YYYY-MM-DD format. Only used when mode='schedule'. Optional, defaults to today."
                  },
                  "start_time": {
                    "type": "string",
                    "description": "Earliest hour of the day at which the AI is allowed to place calls, in 24h HH:MM format. Only used when mode='schedule'. Optional, defaults to '10:00'.",
                    "example": "10:00"
                  },
                  "end_time": {
                    "type": "string",
                    "description": "Latest hour of the day at which the AI is allowed to place calls, in 24h HH:MM format. Only used when mode='schedule'. Optional, defaults to '19:00'.",
                    "example": "19:00"
                  },
                  "rate_per_minute": {
                    "type": "string",
                    "description": "Maximum number of simultaneous new calls the dialer is allowed to open per minute. Use to throttle spend and avoid carrier rate-limits. Optional, defaults to '30'.",
                    "example": "30"
                  },
                  "date_start_ms": {
                    "type": "string",
                    "description": "Alternative to start_date/start_time: absolute Unix timestamp in MILLISECONDS (UTC) at which dialing should begin. Optional."
                  }
                },
                "required": [
                  "token",
                  "agent_ai_id",
                  "caller_id",
                  "recipients",
                  "mode"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companyuserdata/invoicesget.json": {
      "post": {
        "operationId": "invoices_get",
        "summary": "Get invoices for the authenticated agent, optionally filtered by date range",
        "tags": [
          "companyuserdata"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "date_start": {
                    "type": "string",
                    "description": "Start timestamp for date range filter (optional)"
                  },
                  "date_end": {
                    "type": "string",
                    "description": "End timestamp for date range filter (optional)"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/notifications/list.json": {
      "post": {
        "operationId": "notifications_list",
        "summary": "Get notifications for the authenticated agent with pagination",
        "tags": [
          "notifications"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "var_resultspage": {
                    "type": "string",
                    "description": "Results per page (default 20)",
                    "example": "20"
                  },
                  "var_page": {
                    "type": "string",
                    "description": "Page number (default 1)",
                    "example": "1"
                  },
                  "read": {
                    "type": "string",
                    "description": "Filter by read status: 0 for unread, 1 for read (optional, returns all by default)"
                  }
                },
                "required": [
                  "token",
                  "var_resultspage",
                  "var_page"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/notifications/sendpush.json": {
      "post": {
        "operationId": "notifications_sendpush",
        "summary": "Send a push notification to an agent. Same logic as workflows sendnoti block",
        "tags": [
          "notifications"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "title": {
                    "type": "string",
                    "description": "Notification title"
                  },
                  "text": {
                    "type": "string",
                    "description": "Notification text/body"
                  },
                  "target_agent_id": {
                    "type": "string",
                    "description": "Agent ID to send the notification to (optional, defaults to self)"
                  },
                  "assign_to": {
                    "type": "string",
                    "description": "Set to 'current' to send to the lead's owner agent (requires id_lead)"
                  },
                  "id_lead": {
                    "type": "string",
                    "description": "Lead ID to link in the notification and resolve owner agent (optional)"
                  },
                  "type": {
                    "type": "string",
                    "description": "Notification type (default 'noti')",
                    "example": "noti"
                  },
                  "badge": {
                    "type": "string",
                    "description": "Badge letter shown in notification (default 'L')",
                    "example": "L"
                  }
                },
                "required": [
                  "token",
                  "title",
                  "text",
                  "assign_to",
                  "type",
                  "badge"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/notifications/read.json": {
      "post": {
        "operationId": "notifications_read",
        "summary": "Mark one or all notifications as read",
        "tags": [
          "notifications"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "notification_id": {
                    "type": "string",
                    "description": "ID of a single notification to mark as read (optional if read_all is used)"
                  },
                  "read_all": {
                    "type": "string",
                    "description": "Set to 'y' to mark all notifications as read"
                  }
                },
                "required": [
                  "token",
                  "read_all"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/costexplorer/get.json": {
      "post": {
        "operationId": "costexplorer_get",
        "summary": "Get aggregated cost/usage data from the calls_leads collection grouped by configurable dimensions with a date range filter. By default returns only real communication records (answered/received calls, SMS, WhatsApp) grouped by agent_id and type — excludes AI, file, payment, credit and other internal service types unless explicitly overridden via service_type. Date range must be within a single calendar year. Only master/admin users can call this endpoint. Use this to answer questions like 'cost of calls per agent this month', 'total SMS cost by country', or 'which agent spent most credits on callouts'.",
        "tags": [
          "costexplorer"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "datestart_unix": {
                    "type": "number",
                    "description": "Start date as UNIX timestamp in seconds UTC (inclusive). Example: 1767225600 corresponds to 2026-01-01 00:00 UTC."
                  },
                  "dateend_unix": {
                    "type": "number",
                    "description": "End date as UNIX timestamp in seconds UTC (exclusive). Example: 1769904000 corresponds to 2026-02-01 00:00 UTC."
                  },
                  "group_by": {
                    "type": "array",
                    "description": "Array of dimensions to group by. Allowed values: type, country, agent_id, month, day, hour, phone, destination. Default when omitted: [\"agent_id\",\"type\"] — aggregates cost per agent and per service type.",
                    "example": "[\"agent_id\",\"type\"]"
                  },
                  "service_type": {
                    "type": "array",
                    "description": "Filter by call types (optional). Default when omitted: [\"callout\",\"callin\",\"callpush\",\"callai\",\"sms\",\"smsin\",\"whatsapp\"] — aggregates received/answered calls (incl. AI voice), SMS and WhatsApp (excludes ai, aitts, payment, credit, file, etc). Allowed values in DB: callout, callin, callpush (AI push/vozpush call), callai (AI voice call), sms, smsin, whatsapp, ai, aitts, payment, credit, file, calendar, sale, ticket, emailin, emailout, emailreaded, form_completed, budget-status, fbleads, cli2cal, voiceline (monthly subscription fee of each phone line, one record per line and month). Note: callpush and callai are distinct AI voice service types, each grouped and labeled separately (not merged into 'ai').",
                    "example": "[\"callout\",\"callin\",\"callpush\",\"callai\",\"sms\",\"smsin\",\"whatsapp\"]"
                  },
                  "var_agents_id": {
                    "type": "array",
                    "description": "Filter by agent IDs (optional, admin/master only). Admin users are limited to agents in their department."
                  },
                  "collapse_by": {
                    "type": "array",
                    "description": "Re-aggregate results by these dimensions after initial grouping (optional). Subset of group_by dimensions."
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date range validation (optional, example: Europe/Madrid). Used to ensure the date range stays within a single calendar year in the user's local timezone. Defaults to UTC if omitted or invalid.",
                    "example": "Europe/Madrid"
                  }
                },
                "required": [
                  "token",
                  "datestart_unix",
                  "dateend_unix",
                  "group_by"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/costexplorer/getlistcallsleads.json": {
      "post": {
        "operationId": "costexplorer_getlistcallsleads",
        "summary": "Get call records grouped by agent and country with cost calculated from per-credit tariff. Dates in UNIX UTC seconds",
        "tags": [
          "costexplorer"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "datestart_unix": {
                    "type": "number",
                    "description": "Start date as UNIX timestamp UTC seconds (inclusive)"
                  },
                  "dateend_unix": {
                    "type": "number",
                    "description": "End date as UNIX timestamp UTC seconds (inclusive)"
                  },
                  "service_type": {
                    "type": "array",
                    "description": "Filter by call types array e.g. ['callout','callin','sms'] (optional, returns all types if empty). callpush (AI push/vozpush call) and callai (AI voice call) are distinct service types."
                  },
                  "var_agentfilterpayments": {
                    "type": "string",
                    "description": "Filter by single agent ID (optional)"
                  },
                  "var_agents_id": {
                    "type": "array",
                    "description": "Filter by multiple agent IDs (optional)"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering (optional, example: Europe/Madrid)"
                  }
                },
                "required": [
                  "token",
                  "datestart_unix",
                  "dateend_unix"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/costexplorer/calls.json": {
      "post": {
        "operationId": "costexplorer_calls",
        "summary": "Call report: returns a paginated list of individual communication records (inbound/outbound calls, SMS, WhatsApp) for a date range, plus aggregate stats (total calls, answered, unanswered, total duration in seconds, total credits). Reads from monthly calls_leads collections and applies agent RBAC automatically. By default filters only real communications (callout, callin, sms, smsin, whatsapp) and excludes AI, files, payments, credits and other non-communication service types — override with service_type to include them. Use this to answer questions like 'show me my calls last week', 'how many calls did agent X make in March', 'list missed calls today', 'how many WhatsApp messages did I receive', or 'what's my call cost this month'. All dates are UNIX timestamps in seconds.",
        "tags": [
          "costexplorer"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  },
                  "datestart_unix": {
                    "type": "number",
                    "description": "Start date as UNIX timestamp UTC seconds (inclusive). If omitted or invalid, defaults to current month. Example: 1767225600 corresponds to 2026-01-01 00:00 UTC."
                  },
                  "dateend_unix": {
                    "type": "number",
                    "description": "End date as UNIX timestamp UTC seconds (inclusive). If omitted or invalid, defaults to current month. Example: 1769817599 corresponds to 2026-01-31 23:59 UTC."
                  },
                  "service_type": {
                    "type": "array",
                    "description": "Filter by call types (optional). Default when omitted: [\"callout\",\"callin\",\"callpush\",\"callai\",\"sms\",\"smsin\",\"whatsapp\"] — filters received/answered calls (incl. AI voice), SMS and WhatsApp. Allowed values in DB: callout, callin, callpush (AI push/vozpush call), callai (AI voice call), sms, smsin, whatsapp, ai, aitts, payment, credit, file, calendar, sale, ticket, emailin, emailout, emailreaded, form_completed, budget-status, fbleads, cli2cal, voiceline (monthly subscription fee of each phone line, one record per line and month). Note: callpush and callai are distinct AI voice service types, each grouped and labeled separately (not merged into 'ai'). Example: [\"callout\",\"callin\"]",
                    "example": "[\"callout\",\"callin\",\"callpush\",\"callai\",\"sms\",\"smsin\",\"whatsapp\"]"
                  },
                  "status": {
                    "type": "string",
                    "description": "Filter by call status (optional). Common values: ANSWER (answered), NO ANSWER, BUSY, FAILED, CANCEL"
                  },
                  "phone": {
                    "type": "string",
                    "description": "Filter by phone number substring (optional, case insensitive)"
                  },
                  "var_agents_id": {
                    "type": "array",
                    "description": "Filter by agent IDs (optional). Ignored for agent-type users (they only see their own calls). Admin users are limited to agents in their department."
                  },
                  "page": {
                    "type": "number",
                    "description": "Page number, starts at 1 (optional, default 1)",
                    "example": 1
                  },
                  "pageSize": {
                    "type": "number",
                    "description": "Records per page, between 10 and 500 (optional, default 50)",
                    "example": 50
                  },
                  "timezone": {
                    "type": "string",
                    "description": "Timezone for date filtering context (optional, example: Europe/Madrid).",
                    "example": "Europe/Madrid"
                  }
                },
                "required": [
                  "token",
                  "datestart_unix",
                  "dateend_unix"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/companyuserdata/myuserdata.json": {
      "post": {
        "operationId": "companyuserdata_myuserdata",
        "summary": "Get the full authenticated agent/user record from the clients collection",
        "tags": [
          "companyuserdata"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/calendarwidget/getconfigurationbookingcalendar.json": {
      "get": {
        "operationId": "calendarwidget_get_config",
        "summary": "Get public calendar configuration. Returns availability ranges (per-day, minutes from midnight), duration, timezone and company logo. Calendar must have enabled=true. No authentication required (public endpoint).",
        "tags": [
          "calendarwidget"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "bookingId",
            "in": "query",
            "required": true,
            "description": "Calendar widget ObjectId (query param)",
            "schema": {
              "type": "string"
            }
          }
        ]
      }
    },
    "/api/1.0/calendarwidget/availabilityByDay.json": {
      "get": {
        "operationId": "calendarwidget_availability",
        "summary": "Get available time slots for a specific date. Returns UTC ISO slots filtered by agent availability. How it works: 1) Load calendar config 2) Check enabled=true 3) Get availability ranges for the day of week 4) Generate slots every {duration} minutes within each range 5) Filter out past slots 6) For each slot check if at least ONE assigned agent has no conflicting task in calendar collection 7) Return available slots as UTC ISO strings. No authentication required (public endpoint).",
        "tags": [
          "calendarwidget"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "parameters": [
          {
            "name": "bookingId",
            "in": "query",
            "required": true,
            "description": "Calendar widget ObjectId (query param)",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "selectedDay",
            "in": "query",
            "required": true,
            "description": "Date in YYYY-MM-DD format (query param)",
            "schema": {
              "type": "string",
              "example": "2026-03-30"
            }
          },
          {
            "name": "timezone",
            "in": "query",
            "required": false,
            "description": "IANA timezone string (optional query param, auto-detected from company country if not sent)",
            "schema": {
              "type": "string",
              "example": "Europe/Madrid"
            }
          }
        ]
      }
    },
    "/api/1.0/calendarwidget/booking.json": {
      "post": {
        "operationId": "calendarwidget_create_booking",
        "summary": "Create an appointment booking. How it works: 1) Load calendar config, check enabled=true 2) Calculate UTC start/end from start_time + duration 3) Find assigned agents 4) Check which agents already have a task at that date+time 5) Pick first free agent 6) Detect existing lead by phone then by email 7) If no lead found create new lead (source: calendarwidget) 8) Create calendar task via appexpress_modal_addcalendar() 9) Return agent info. No authentication required (public endpoint).",
        "tags": [
          "calendarwidget"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "booking_id": {
                    "type": "string",
                    "description": "Calendar widget ObjectId"
                  },
                  "start_time": {
                    "type": "string",
                    "description": "ISO 8601 UTC datetime of the chosen slot (e.g. 2026-03-30T09:00:00.000Z)"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "IANA timezone string (optional, auto-detected from company country if not sent)",
                    "example": "Europe/Madrid"
                  },
                  "contact": {
                    "type": "object",
                    "description": "Contact info object: { name: string, email: string, phone: string (with intl prefix), country: string (ISO 2-char code), notes: string }",
                    "example": {
                      "name": "John Doe",
                      "email": "john@example.com",
                      "phone": "+34600000000",
                      "country": "es",
                      "notes": ""
                    }
                  }
                },
                "required": [
                  "booking_id",
                  "start_time",
                  "contact"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/schemas.json": {
      "post": {
        "operationId": "entities_get_schemas",
        "summary": "Get ALL CRM entities of the company with their full schemas in a single call: property identifiers, types, required/unique flags, select options, statuses, associations and the exact endpoints to create, query and edit records of each entity. This is the entry point for AI assistants, MCP integrations and developers: call it first and you will not need to fetch company properties or configuration from any other endpoint. ENTITY TYPES: entities with system='y' are the 6 built-in CRM entities (leads = Contacts, companies, opportunities = Deals, tasks, tickets, budgets); entities with system=null are CUSTOM entities created by this company and their key always starts with 'cust_'. Both share exactly the same schema shape. STATUSES: an entity can have status groups (statusgroups). Every status has a stable 'id', a human 'label', a color and (built-in entities only) a numeric 'legacyIndex'. The 'mode' of the group tells you which value is stored in records and therefore what to send in filters and on creation: mode 'index' (contacts/companies) uses the legacyIndex, mode 'id' (custom entities) uses the status 'id'. The property that backs each group carries 'statusgroup' and 'statusoptions'. ASSOCIATIONS: a property of type 'association' links a record to another entity: 'targetEntity' says which entity it points to and the stored value is the _id string of the target record; the entity's 'associations' array lists all its links. Association properties are CREATED through /api/1.0/entities/saveproperty.json (type 'association' + targetEntity) or directly at entity creation with the 'properties' parameter of /api/1.0/entities/createentity.json. GET is also supported with the same parameters as query string.",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  }
                },
                "required": [
                  "token"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/getrecords.json": {
      "post": {
        "operationId": "entities_get_records",
        "summary": "Query records of any CRM entity — contacts (entitykey 'leads'), 'companies', 'opportunities', 'tasks', 'tickets' or any CUSTOM entity ('cust_...') — with filters on schema properties, free-text search, ordering, pagination and creation-date range. Records are returned CLEAN: only 'id', base fields (agent_id, agents_id, creation_date, last_update and, on entities that store it — opportunities/tasks —, a raw 'date' field), the properties defined in the entity schema, resolved status labels (extra '<statusfield>_label' fields) and display labels of linked records ('assoclabels', custom entities). Property identifiers for filters come from /api/1.0/entities/schemas.json. Results respect the visibility of the user linked to the token: masters see everything; agents see their own records; admins see their department on built-in entities and EVERYTHING on custom entities (no department scoping there). For budgets use /api/1.0/budgets/getlist.json.",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "entitykey": {
                    "type": "string",
                    "description": "Entity key from schemas.json: 'leads' (contacts), 'companies', 'opportunities', 'tasks', 'tickets', or a custom key starting with 'cust_'. Required.",
                    "example": "leads"
                  },
                  "filters": {
                    "type": "object",
                    "description": "Filters on property identifiers (from schemas.json). Simple form {\"identifier\": \"value\"} means equals; an array value means IN; advanced form {\"identifier\": {\"op\": \"gte\", \"value\": 100}} with ops: eq, ne, in, nin, gt, gte, lt, lte, re (regex contains, case-sensitive; only meaningful on text-like properties — on 'number' properties it never matches anything, and on opportunities 'expecteddate' it is rejected with invalid_filter_op_re_for_expecteddate). Status fields: send the legacyIndex for contacts/companies (statusgroups mode 'index') or the status 'id' for custom entities (mode 'id'). Association properties: send the _id string of the target record. agent_id and agents_id support only eq/in (agents_id is an array: eq = contains, in = contains any). Also accepts a JSON-encoded string. (optional) RANGE/multi-op form: a value object WITHOUT 'op' whose keys are operators applies them all to the identifier — {\"identifier\": {\"gte\": 100, \"lte\": 200}} (both bounds merged with AND); works for any property type and is THE way to express from-to ranges in a single call.",
                    "example": {
                      "status": "0",
                      "country": "es"
                    }
                  },
                  "search": {
                    "type": "string",
                    "description": "Free-text search over the entity's text properties (name, email, phone...). Case-insensitive. (optional)"
                  },
                  "page": {
                    "type": "string",
                    "description": "Page number, starts at 1. (optional)",
                    "example": "1"
                  },
                  "perpage": {
                    "type": "string",
                    "description": "Results per page, max 100. (optional)",
                    "example": "20"
                  },
                  "orderby": {
                    "type": "string",
                    "description": "Property identifier to sort by. Defaults to creation date, newest first. (optional)",
                    "example": "creation_date"
                  },
                  "orderdir": {
                    "type": "string",
                    "description": "Sort direction: 'asc' or 'desc'. Defaults to 'desc'. (optional)",
                    "example": "desc"
                  },
                  "count": {
                    "type": "string",
                    "description": "Set to 'y' to also get the exact total count in 'total' (slower). By default 'total' is null and pagination relies on 'hasmore'. (optional)"
                  },
                  "datefrom": {
                    "type": "string",
                    "description": "Start of creation-date range, format YYYY-MM-DD. Requires dateto and timezone. (optional)",
                    "example": "2026-01-01"
                  },
                  "dateto": {
                    "type": "string",
                    "description": "End of creation-date range, format YYYY-MM-DD. Requires datefrom and timezone. (optional)",
                    "example": "2026-12-31"
                  },
                  "timezone": {
                    "type": "string",
                    "description": "IANA timezone for the date range, e.g. Europe/Madrid. Required together with datefrom and dateto. (optional)",
                    "example": "Europe/Madrid"
                  }
                },
                "required": [
                  "token",
                  "entitykey"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/createrecord.json": {
      "post": {
        "operationId": "entities_create_record",
        "summary": "Create a record in a CRM entity using its schema: contacts (entitykey 'leads'), companies (entitykey 'companies') or any CUSTOM entity (entitykey 'cust_...'). Field names inside 'values' are the property identifiers returned by /api/1.0/entities/schemas.json. STATUSES: for contacts/companies send the status legacyIndex in the 'status' parameter; for custom entities send the status 'id' inside values using the status group's docField (e.g. values.status_main = 'st_1a2b3c'); if omitted, the status flagged 'isdefault':'y' in schemas.json is applied (or, if none is flagged, the first live status in display order — the first one schemas.json lists). ASSOCIATIONS (custom entities): to link the new record to another record, pass the _id string of the target record as the value of the association property. For opportunities and tickets use their specific create endpoints (the 'create' hint of the schemas response tells you which endpoint to use for each entity).",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "entitykey": {
                    "type": "string",
                    "description": "Entity key from schemas.json: 'leads' (contacts), 'companies', or a custom key starting with 'cust_'. Required.",
                    "example": "leads"
                  },
                  "values": {
                    "type": "object",
                    "description": "Object mapping property identifiers (from schemas.json) to values. Required properties of the entity must be present. Association properties take the _id string of the target record. Also accepts a JSON-encoded string. Required.",
                    "example": {
                      "name": "Marc",
                      "email": "example@exampleemail.com",
                      "phone": "34682288888"
                    }
                  },
                  "agent_id": {
                    "type": "string",
                    "description": "Only for 'leads'/'companies': agent _id to assign the record to, or 'unassigned' to assign it to all agents (default). For custom entities the record is always created by the client linked to the token. (optional)",
                    "example": "unassigned"
                  },
                  "status": {
                    "type": "string",
                    "description": "Only for 'leads'/'companies': status legacyIndex (see statusoptions in schemas.json). Defaults to 0. For custom entities pass the status 'id' inside values using the statusgroup docField (e.g. values.status_main). (optional)",
                    "example": "0"
                  }
                },
                "required": [
                  "token",
                  "entitykey",
                  "values"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/editrecord.json": {
      "post": {
        "operationId": "entities_edit_record",
        "summary": "Edit (update) an EXISTING record of a CUSTOM entity ('cust_...') by its record id. PARTIAL update: only the property identifiers present in 'values' are modified; every other field keeps its value. Field names inside 'values' are the property identifiers returned by /api/1.0/entities/schemas.json — never guess them. STATUSES: send the status 'id' using the status group's docField as field name (e.g. values.status_main = 'st_4d5e6f'). ASSOCIATIONS: to link (or re-link) the record to another record, pass the _id string of the target record as the value of the association property. All changes are validated against the entity schema (required, unique, valid status ids, association target must exist) and the change is logged in the record's activity feed. Built-in entities (leads, companies, opportunities, tasks, tickets, budgets) are edited through their own endpoints (/api/1.0/<entity>/edit.json); calling this one with a built-in entitykey returns 'use_specific_endpoint' telling you which endpoint to use.",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "entitykey": {
                    "type": "string",
                    "description": "Key of the CUSTOM entity (starts with 'cust_'), from schemas.json. Built-in entities must use their own edit endpoint. Required.",
                    "example": "cust_ab12cd34ef56gh78"
                  },
                  "record_id": {
                    "type": "string",
                    "description": "The _id of the record to edit: the 'id' field returned by getrecords.json or the 'record_id' returned by createrecord.json (24-char hex). Required.",
                    "example": "69d9d868740030527e46055a"
                  },
                  "values": {
                    "type": "object",
                    "description": "Object mapping property identifiers (from schemas.json) to their NEW values. PARTIAL: only identifiers present here are updated. Status fields use the group's docField with the status 'id' as value; association properties take the _id string of the target record; unknown keys are ignored. Also accepts a JSON-encoded string. Required.",
                    "example": {
                      "ab12price8k2j3h4g5": 199000
                    }
                  }
                },
                "required": [
                  "token",
                  "entitykey",
                  "record_id",
                  "values"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/createentity.json": {
      "post": {
        "operationId": "entities_create_entity",
        "summary": "Create a NEW CUSTOM ENTITY in the CRM — a brand-new record type / custom object / custom module (e.g. 'Properties', 'Contracts', 'Invoices', 'Vehicles') — COMPLETE IN ONE SINGLE CALL: the entity itself (name, name_plural, icon, color) PLUS all its initial PROPERTIES (fields, associations included — 'properties' parameter) PLUS its initial STATUSES ('statuses' parameter — the first one becomes the default). THIS ENDPOINT IS THE TOOL FOR THAT and the RECOMMENDED way for AI assistants and integrations: if a user asks to create a custom entity ('entidad personalizada'), send EVERYTHING here in one request instead of chaining saveproperty/savestatus calls. Every property type is supported with the same format as saveproperty.json: text, tags, textarea, select (REQUIRES 'options'), phone, email, number, datetime (ALWAYS stored as unix UTC epoch in SECONDS), country, association (REQUIRES 'targetEntity' = an EXISTING entitykey). The entity is also born with a required 'Name' text property. The response's 'created' object maps every property name to its generated identifier (the auto-created 'Name' property included, flagged required:'y') and every status label to its id, so createrecord.json can be called IMMEDIATELY with no schemas.json lookup — just send a value for every required:'y' property. saveproperty.json and savestatus.json remain available to add MORE fields/statuses LATER or to edit existing ones. Built-in system entities (leads, companies, opportunities, tasks, tickets, budgets) already exist and cannot be created here. The token's user must be master or admin.",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. The linked user must be master or admin. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "name": {
                    "type": "string",
                    "description": "Singular name of the new entity. Required.",
                    "example": "Property"
                  },
                  "name_plural": {
                    "type": "string",
                    "description": "Plural name. Defaults to the singular name. (optional)",
                    "example": "Properties"
                  },
                  "icon": {
                    "type": "string",
                    "description": "Tabler icon class. Defaults to 'ti ti-box'. (optional)",
                    "example": "ti ti-home"
                  },
                  "color": {
                    "type": "string",
                    "description": "Hex color for the entity. Defaults to '#2563eb'. (optional)",
                    "example": "#16a34a"
                  },
                  "properties": {
                    "type": "array",
                    "description": "INITIAL properties (fields) of the entity, created in the SAME call: array of {name (required), type (defaults to 'text'; one of text, tags, textarea, select, phone, email, number, datetime, country, association), required ('y'/'n', default 'n'), unique ('y'/'n', default 'n'), options (REQUIRED for type select: array of strings or {text, textshow, selected:'y'|'n'} objects), targetEntity (REQUIRED for type association: an EXISTING entitykey of the company — it cannot point to the entity being created), cardinality (association only, defaults to 'many-to-one')}. Max 100. Do NOT include a property named 'Name': the entity is always born with it. Every entry is validated upfront: if any is invalid NOTHING is created. More fields can be added later with /api/1.0/entities/saveproperty.json. Also accepts a JSON-encoded string. (optional)",
                    "example": [
                      {
                        "name": "Price",
                        "type": "number"
                      },
                      {
                        "name": "Type",
                        "type": "select",
                        "options": [
                          "Flat",
                          "House",
                          "Office"
                        ]
                      },
                      {
                        "name": "Signing date",
                        "type": "datetime"
                      },
                      {
                        "name": "Owner",
                        "type": "association",
                        "targetEntity": "leads"
                      }
                    ]
                  },
                  "statuses": {
                    "type": "array",
                    "description": "INITIAL statuses of the entity: array where each item is a label string or a {label, color} object. The FIRST one becomes the default status for new records. Max 100. Statuses can be added/edited later with /api/1.0/entities/savestatus.json. Also accepts a JSON-encoded string. (optional)",
                    "example": [
                      "Available",
                      {
                        "label": "Reserved",
                        "color": "#f59e0b"
                      },
                      {
                        "label": "Sold",
                        "color": "#ef4444"
                      }
                    ]
                  },
                  "statusgroup": {
                    "type": "object",
                    "description": "Alternative form of 'statuses' with a custom group name: {name, statuses:[...]} (same statuses format, e.g. {\"name\":\"Pipeline\",\"statuses\":[{\"label\":\"Draft\"},{\"label\":\"Confirmed\",\"color\":\"#22c55e\"}]}). Use one or the other, not both — if both are sent, 'statusgroup' wins and 'statuses' is ignored. (optional)"
                  }
                },
                "required": [
                  "token",
                  "name"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/saveproperty.json": {
      "post": {
        "operationId": "entities_save_property",
        "summary": "Create OR edit ONE property (field) of a CUSTOM entity ('cust_...'). Without 'identifier' it CREATES a new property (the identifier is generated server-side and returned). With 'identifier' it EDITS that property (partial: only the fields you send change). THIS ENDPOINT IS ALSO THE TOOL TO CREATE ASSOCIATIONS between entities: send type 'association' with 'targetEntity' = the entitykey to link to ('leads', 'companies', another 'cust_...'); records then store the _id of the linked record in that property. One call per property — to add several fields to an EXISTING entity, call it once per field. The INITIAL fields of a NEW entity do not need this endpoint: /api/1.0/entities/createentity.json creates the entity with ALL its properties and statuses in ONE call. Allowed types: text, tags, textarea, select (REQUIRES 'options'), phone, email, number, datetime (date+time, ALWAYS stored as unix UTC epoch in SECONDS — use it for ANY date field; the old type 'date' can no longer be created), country, association (REQUIRES 'targetEntity'). The token's user must be master or admin.",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. The linked user must be master or admin. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "entitykey": {
                    "type": "string",
                    "description": "Key of the CUSTOM entity ('cust_...') to add/edit the property on. Required.",
                    "example": "cust_ab12cd34ef56gh78"
                  },
                  "identifier": {
                    "type": "string",
                    "description": "Identifier of an EXISTING property to edit. OMIT to create a new property. (optional)"
                  },
                  "name": {
                    "type": "string",
                    "description": "Human name of the property. Required on create; on edit, only sent to rename.",
                    "example": "Price"
                  },
                  "type": {
                    "type": "string",
                    "description": "Property type (create only; the type of an existing property can NEVER be changed): text, tags, textarea, select, phone, email, number, datetime, country, association. Defaults to 'text'. For dates use 'datetime': values are ALWAYS stored as unix UTC epoch in seconds and shown in the CRM converted to each user's timezone.",
                    "example": "text"
                  },
                  "required": {
                    "type": "string",
                    "description": "'y' to make the property mandatory when creating records. (optional)",
                    "example": "n"
                  },
                  "unique": {
                    "type": "string",
                    "description": "'y' to enforce unique values across records of the entity (not available for association). (optional)",
                    "example": "n"
                  },
                  "options": {
                    "type": "array",
                    "description": "REQUIRED for type select: array of options as plain strings ([\"Flat\",\"House\"]) or {text, textshow, selected:'y'|'n'} objects; strings are normalized server-side to {text} objects. Record values must be the option 'text'. On edit: omit to keep current options (clearing is not supported); sending them REPLACES the whole list. Also accepts a JSON-encoded string. (optional)",
                    "example": [
                      "Flat",
                      "House",
                      "Office"
                    ]
                  },
                  "targetEntity": {
                    "type": "string",
                    "description": "REQUIRED for type association: entitykey this property points to ('leads', 'companies', 'opportunities', 'tasks', 'tickets', 'budgets' or another 'cust_...'). Must ALREADY exist. Cannot be changed on edit.",
                    "example": "leads"
                  },
                  "cardinality": {
                    "type": "string",
                    "description": "For type association: 'many-to-one' (default) or 'one-to-many'. (optional)",
                    "example": "many-to-one"
                  }
                },
                "required": [
                  "token",
                  "entitykey",
                  "name",
                  "type",
                  "targetEntity"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/savestatus.json": {
      "post": {
        "operationId": "entities_save_status",
        "summary": "Add OR edit ONE status of a CUSTOM entity ('cust_...'). Without 'id' it ADDS a new status: the FIRST status added to an entity automatically creates its status group (no separate call needed) and becomes the DEFAULT for new records. With 'id' (the 'st_...' id from schemas.json) it EDITS the label/color of an existing status. One call per status — to add several statuses to an EXISTING entity, call it once per status, in the order you want them displayed. The INITIAL statuses of a NEW entity can be created directly in /api/1.0/entities/createentity.json ('statuses' parameter). The token's user must be master or admin.",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. The linked user must be master or admin. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "entitykey": {
                    "type": "string",
                    "description": "Key of the CUSTOM entity ('cust_...'). Required.",
                    "example": "cust_ab12cd34ef56gh78"
                  },
                  "id": {
                    "type": "string",
                    "description": "Id ('st_...') of an EXISTING status to edit. OMIT to add a new status. (optional)"
                  },
                  "label": {
                    "type": "string",
                    "description": "Status name. Required when adding; on edit, only sent to rename.",
                    "example": "Available"
                  },
                  "color": {
                    "type": "string",
                    "description": "Hex color of the status. (optional)",
                    "example": "#22c55e"
                  }
                },
                "required": [
                  "token",
                  "entitykey",
                  "label"
                ]
              }
            }
          }
        }
      }
    },
    "/api/1.0/entities/editentity.json": {
      "post": {
        "operationId": "entities_edit_entity",
        "summary": "Edit the METADATA of an entity: rename it (name, name_plural) or change its icon/color. Works on custom entities ('cust_...') and on built-in ones (renaming 'leads' to 'Patients', for example). ONLY metadata: to create/edit PROPERTIES (fields, including associations) use POST /api/1.0/entities/saveproperty.json, and to add/edit STATUSES use POST /api/1.0/entities/savestatus.json — this endpoint rejects the old 'addproperties'/'editproperties'/'addstatuses'/'editstatuses' parameters with use_dedicated_endpoints. The token's user must be master or admin.",
        "tags": [
          "entities"
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "token": {
                    "type": "string",
                    "description": "API access token of the company. The linked user must be master or admin. Required.",
                    "example": "YOUR_APIKEY"
                  },
                  "entitykey": {
                    "type": "string",
                    "description": "Key of the entity to edit: 'cust_...' or a built-in key (leads, companies, opportunities, tasks, tickets, budgets). Required.",
                    "example": "cust_ab12cd34ef56gh78"
                  },
                  "name": {
                    "type": "string",
                    "description": "New singular name. (optional)",
                    "example": "Property"
                  },
                  "name_plural": {
                    "type": "string",
                    "description": "New plural name. (optional)",
                    "example": "Properties"
                  },
                  "icon": {
                    "type": "string",
                    "description": "New Tabler icon class. (optional)",
                    "example": "ti ti-home"
                  },
                  "color": {
                    "type": "string",
                    "description": "New hex color. (optional)",
                    "example": "#16a34a"
                  }
                },
                "required": [
                  "token",
                  "entitykey"
                ]
              }
            }
          }
        }
      }
    }
  }
}