{
    "openapi": "3.0.1",
    "info": {
        "title": "Puretalk AI",
        "description": "Api Documentation for Puretalk AI",
        "license": {
            "name": "MIT"
        },
        "version": "1.0.0"
    },
    "servers": [
        {
            "url": "https://api.puretalk.ai/api"
        }
    ],
    "security": [
        {
            "ApiKeyAuth": []
        }
    ],
    "paths": {
        "/campaigns": {
            "get": {
                "description": "Returns all campaigns from the system that the user has access to",
                "parameters": [
                    {
                        "name": "page",
                        "in": "query",
                        "description": "The page number to return",
                        "schema": {
                            "type": "integer",
                            "format": "int32"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "The maximum number of results to return",
                        "schema": {
                            "type": "integer",
                            "format": "int32"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Campaigns response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "msg": {
                                            "type": "string",
                                            "description": "Message from the API",
                                            "example": "Campaigns retrieved successfully"
                                        },
                                        "err": {
                                            "type": "boolean",
                                            "description": "Indicates if the response is an error",
                                            "example": false
                                        },
                                        "results": {
                                            "type": "object",
                                            "properties": {
                                                "count": {
                                                    "type": "integer",
                                                    "description": "Total number of campaigns",
                                                    "example": 100
                                                },
                                                "campaigns": {
                                                    "type": "array",
                                                    "items": {
                                                        "$ref": "#/components/schemas/Campaign"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "description": "Create a new campaign",
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Name of the campaign",
                                        "example": "My Campaign"
                                    },
                                    "start_date": {
                                        "type": "string",
                                        "description": "Start date of the campaign",
                                        "example": "2021-01-01"
                                    },
                                    "end_date": {
                                        "type": "string",
                                        "description": "End date of the campaign",
                                        "example": "2021-01-01"
                                    },
                                    "ai_assistant_id": {
                                        "type": "string",
                                        "description": "ID of the AI assistant to use for the campaign",
                                        "example": "123e4567-e89b-12d3-a456-426614174000"
                                    },
                                    "type": {
                                        "type": "string",
                                        "description": "Type of the campaign",
                                        "example": "call"
                                    },
                                    "leads": {
                                        "type": "array",
                                        "items": {
                                            "type": "object",
                                            "properties": {
                                                "to_number": {
                                                    "type": "string",
                                                    "description": "Phone number to call",
                                                    "example": "+1234567890"
                                                },
                                                "variables": {
                                                    "type": "array",
                                                    "items": {
                                                        "type": "object",
                                                        "properties": {
                                                            "var_name": {
                                                                "type": "string",
                                                                "description": "Name of the variable",
                                                                "example": "name"
                                                            },
                                                            "var_value": {
                                                                "type": "string",
                                                                "description": "Value of the variable",
                                                                "example": "John Doe"
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                },
                                "required": ["name", "start_date", "end_date", "ai_assistant_id", "type", "leads"]
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Campaign created",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "msg": {
                                            "type": "string",
                                            "description": "Message from the API",
                                            "example": "Campaign created successfully"
                                        },
                                        "err": {
                                            "type": "boolean",
                                            "description": "Indicates if the response is an error",
                                            "example": false
                                        },
                                        "results": {
                                            "type": "object",
                                            "properties": {
                                                "campaign_id": {
                                                    "type": "string",
                                                    "format": "uuid",
                                                    "description": "ID of the created campaign",
                                                    "example": "123e4567-e89b-12d3-a456-426614174000"
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/campaigns/{campaign_id}": {
            "get": {
                "description": "Returns a single campaign based on the ID supplied",
                "parameters": [
                    {
                        "name": "campaign_id",
                        "in": "path",
                        "description": "ID of campaign to return",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "format": "uuid"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Campaign response",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "msg": {
                                            "type": "string",
                                            "description": "Message from the API",
                                            "example": "Campaign retrieved successfully"
                                        },
                                        "err": {
                                            "type": "boolean",
                                            "description": "Indicates if the response is an error",
                                            "example": false
                                        },
                                        "results": {
                                            "$ref": "#/components/schemas/Campaign"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            },
            "patch": {
                "description": "Update a campaign based on the ID supplied",
                "parameters": [
                    {
                        "name": "campaign_id",
                        "in": "path",
                        "description": "ID of campaign to update",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "format": "uuid"
                        }
                    }
                ],
                "requestBody": {
                    "content": {
                        "application/json": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "name": {
                                        "type": "string",
                                        "description": "Name of the campaign",
                                        "example": "My Campaign"
                                    },
                                    "start_date": {
                                        "type": "string",
                                        "description": "Start date of the campaign",
                                        "example": "2021-01-01"
                                    },
                                    "end_date": {
                                        "type": "string",
                                        "description": "End date of the campaign",
                                        "example": "2021-01-01"
                                    },
                                    "ai_assistant_id": {
                                        "type": "string",
                                        "description": "ID of the AI assistant to use for the campaign",
                                        "example": "123e4567-e89b-12d3-a456-426614174000"
                                    },
                                    "type": {
                                        "type": "string",
                                        "description": "Type of the campaign",
                                        "example": "call"
                                    }
                                },
                                "required": ["name", "start_date", "end_date", "ai_assistant_id", "type"]
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Campaign updated",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/campaigns/{campaign_id}/leads": {
            "get": {
                "description": "Returns all leads for a campaign based on the ID supplied",
                "parameters": [
                    {
                        "name": "campaign_id",
                        "in": "path",
                        "description": "ID of campaign to return leads",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "format": "uuid"
                        }
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "description": "The page number to return",
                        "schema": {
                            "type": "integer",
                            "format": "int32"
                        }
                    },
                    {
                        "name": "limit",
                        "in": "query",
                        "description": "The maximum number of results to return",
                        "schema": {
                            "type": "integer",
                            "format": "int32"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Campaign leads response",

                        "content": {
                            "application/json": {
                                "schema": {
                                    "type": "object",
                                    "properties": {
                                        "count": {
                                            "type": "integer",
                                            "description": "Total number of leads",
                                            "example": 100
                                        },
                                        "next": {
                                            "type": "string",
                                            "nullable": true,
                                            "format": "uri",
                                            "description": "Next page URL",
                                            "example": "https://api.puretalk.ai/api/campaigns/123e4567-e89b-12d3-a456-426614174000/leads?page=2"
                                        },
                                        "previous": {
                                            "type": "string",
                                            "nullable": true,
                                            "format": "uri",
                                            "description": "Previous page URL",
                                            "example": "https://api.puretalk.ai/api/campaigns/123e4567-e89b-12d3-a456-426614174000/leads?page=1"
                                        },
                                        "results": {
                                            "type": "array",
                                            "items": {
                                                "$ref": "#/components/schemas/CampaignTask"
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/campaigns/{campaign_id}/leads/{to_number}": {
            "delete": {
                "description": "Delete a lead for a campaign based on the ID supplied",
                "parameters": [
                    {
                        "name": "campaign_id",
                        "in": "path",
                        "description": "ID of campaign to delete lead",
                        "required": true,
                        "schema": {
                            "type": "string",
                            "format": "uuid"
                        }
                    },
                    {
                        "name": "to_number",
                        "in": "path",
                        "description": "Number to delete lead",
                        "required": true,
                        "schema": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Lead deleted",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not Found",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/Error"
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "Campaign": {
                "type": "object",
                "properties": {
                    "ai_assistant": {
                        "type": "object",
                        "properties": {
                            "assistant_id": {
                                "type": "string",
                                "description": "ID of the AI assistant",
                                "example": "123e4567-e89b-12d3-a456-426614174000"
                            },
                            "name": {
                                "type": "string",
                                "description": "Name of the AI assistant",
                                "example": "My Assistant"
                            },
                            "variables": {
                                "type": "array",
                                "items": {
                                    "type": "string",
                                    "description": "Variables of the AI assistant",
                                    "example": "name"
                                }
                            }
                        }
                    },
                    "schedules": {
                        "type": "array",
                        "items": {
                            "type": "object",
                            "properties": {
                                "campaign_schedule_id": {
                                    "type": "string",
                                    "description": "ID of the campaign schedule",
                                    "example": "123e4567-e89b-12d3-a456-426614174000"
                                },
                                "day": {
                                    "type": "string",
                                    "description": "Day of the campaign schedule",
                                    "example": "Monday"
                                },
                                "start_time": {
                                    "type": "string",
                                    "format": "time",
                                    "description": "Start time of the campaign schedule",
                                    "example": "10:00"
                                },
                                "end_time": {
                                    "type": "string",
                                    "format": "time",
                                    "description": "End time of the campaign schedule",
                                    "example": "11:00"
                                }
                            }
                        }
                    },
                    "campaign_id": {
                        "type": "string",
                        "description": "ID of the campaign",
                        "example": "123e4567-e89b-12d3-a456-426614174000"
                    },
                    "type": {
                        "type": "string",
                        "description": "Type of the campaign",
                        "example": "call"
                    },
                    "name": {
                        "type": "string",
                        "description": "Name of the campaign",
                        "example": "My Campaign"
                    },
                    "start_date": {
                        "type": "string",
                        "format": "date",
                        "description": "Start date of the campaign",
                        "example": "2021-01-01"
                    },
                    "end_date": {
                        "type": "string",
                        "format": "date",
                        "description": "End date of the campaign",
                        "example": "2021-01-01"
                    },
                    "status": {
                        "type": "string",
                        "description": "Status of the campaign",
                        "example": "active"
                    },
                    "created_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Created at date of the campaign",
                        "example": "2021-01-01"
                    },
                    "updated_at": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Updated at date of the campaign",
                        "example": "2021-01-01"
                    },
                    "total_tasks": {
                        "type": "integer",
                        "description": "Total number of tasks",
                        "example": 100
                    },
                    "completed_tasks": {
                        "type": "integer",
                        "description": "Total number of completed tasks",
                        "example": 100
                    },
                    "pending_tasks": {
                        "type": "integer",
                        "description": "Total number of pending tasks",
                        "example": 100
                    }
                }
            },
            "CampaignTask": {
                "type": "object",
                "properties": {
                    "to_number": {
                        "type": "string",
                        "description": "Phone number of the lead",
                        "example": "+1234567890"
                    },
                    "is_completed": {
                        "type": "boolean",
                        "description": "Indicates if the task is completed",
                        "example": false
                    },
                    "variables": {
                        "type": "array",
                        "nullable": true,
                        "items": {
                            "type": "object",
                            "properties": {
                                "var_name": {
                                    "type": "string",
                                    "description": "Name of the variable",
                                    "example": "name"
                                },
                                "var_value": {
                                    "type": "string",
                                    "description": "Value of the variable",
                                    "example": "John Doe"
                                }
                            }
                        }
                    },
                    "call_id": {
                        "type": "string",
                        "nullable": true
                    },
                    "completed_at": {
                        "type": "string",
                        "nullable": true,
                        "format": "date-time",
                        "description": "Completed at date of the task",
                        "example": "2021-01-01"
                    }
                }
            },
            "Error": {
                "type": "object",
                "properties": {
                    "err": {
                        "type": "boolean",
                        "description": "Indicates if the response is an error",
                        "example": false
                    },
                    "msg": {
                        "type": "string",
                        "description": "Message from the API",
                        "example": "Error message"
                    }
                }
            }
        },
        "securitySchemes": {
            "ApiKeyAuth": {
                "type": "apiKey",
                "in": "header",
                "name": "X-API-KEY",
                "description": "Authorization header containing API key. You can find your API key in the dashboard under 'API Keys'."
            }
        }
    }
}
