openapi: 3.0.4
info:
  title: Evolution Foundation - CRM Service - Public Api
  description: Management of contacts, conversations, inboxes, labels and macros
  version: 1.1.0
servers:
- url: https://api.evoai.app
  description: Production server
- url: http://localhost:3000
  description: Development server
  variables:
    port:
      default: '3000'
- url: '{customUrl}'
  description: Custom server
  variables:
    customUrl:
      default: https://your-instance.com
      description: Enter your server URL
paths:
  /public/api/v1/leads:
    post:
      operationId: create-lead
      summary: Create Lead
      description: Create a lead (contact + deal) in one API call. This endpoint creates a contact and automatically adds
        it to a pipeline stage.
      security:
      - ApiAccessToken: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                contact:
                  type: object
                  required:
                  - name
                  - email
                  properties:
                    name:
                      type: string
                      description: Contact name
                      example: John Doe
                    email:
                      type: string
                      format: email
                      description: Contact email
                      example: john@example.com
                    phone_number:
                      type: string
                      description: Contact phone number (E.164 format)
                      example: '+1234567890'
                    company:
                      type: string
                      description: Company name
                      example: Example Corp
                deal:
                  type: object
                  required:
                  - title
                  - pipeline_id
                  - stage_id
                  properties:
                    title:
                      type: string
                      description: Deal title
                      example: Q1 Partnership Deal
                    value:
                      type: number
                      description: Deal value/amount
                      example: 50000
                    pipeline_id:
                      type: string
                      format: uuid
                      description: Pipeline ID where the deal will be created
                      example: 550e8400-e29b-41d4-a716-446655440000
                    stage_id:
                      type: string
                      format: uuid
                      description: Initial stage ID for the deal
                      example: 660e9500-f39c-52e5-b827-557766551111
                custom_fields:
                  type: object
                  description: Custom fields (key-value pairs)
                  additionalProperties: true
                  example:
                    source: website
                    campaign: spring-2024
                metadata:
                  type: object
                  description: Additional metadata (key-value pairs)
                  additionalProperties: true
                  example:
                    utm_source: google
                    utm_campaign: ads
      responses:
        '200':
          description: Lead created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      lead_id:
                        type: string
                        format: uuid
                        description: ID of the created contact
                        example: 770e0600-g40d-63f6-c938-668877662222
                      deal_id:
                        type: string
                        format: uuid
                        description: ID of the created pipeline item (deal)
                        example: 880e1711-h51e-74g7-d049-779988773333
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    description: Success message
                    example: Lead created successfully
              example:
                success: true
                data:
                  lead_id: 770e0600-g40d-63f6-c938-668877662222
                  deal_id: 880e1711-h51e-74g7-d049-779988773333
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                message: Lead created successfully
        '400':
          description: Bad Request (invalid data)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                validation_error:
                  summary: Invalid request parameters
                  value:
                    status: 400
                    error: Bad Request
        '401':
          description: Unauthorized (invalid or missing token)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                invalid_token:
                  summary: Invalid or missing token
                  value:
                    status: 401
                    error: Unauthorized
        '403':
          description: Forbidden (insufficient permissions)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                forbidden:
                  summary: Access forbidden
                  value:
                    status: 403
                    error: Forbidden
        '404':
          description: Not Found (resource not found)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                pipeline_not_found:
                  summary: Pipeline or stage not found
                  value:
                    status: 404
                    error: Not Found
        '422':
          description: Unprocessable Entity (validation errors)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                validation_failed:
                  summary: Validation failed
                  value:
                    status: 422
                    error: Unprocessable Entity
        '500':
          description: Internal Server Error (internal server error)
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicApiErrorResponse'
              examples:
                internal_error:
                  summary: Internal server error
                  value:
                    status: 500
                    error: Internal Server Error
components:
  schemas:
    PublicApiErrorResponse:
      type: object
      required:
      - status
      - error
      properties:
        status:
          type: integer
          description: HTTP status code
          example: 404
        error:
          type: string
          description: Error message
          example: Not Found
  securitySchemes:
    userApiKey:
      type: apiKey
      in: header
      name: api_access_token
    ApiAccessToken:
      type: apiKey
      in: header
      name: api_access_token
      description: API access token for user authentication
  parameters:
    public_inbox_identifier:
      name: inbox_identifier
      in: path
      required: true
      description: Unique inbox identifier (string)
      schema:
        type: string
      example: my-inbox-identifier
