{
    "openapi": "3.1.0",
    "info": {
        "title": "MicroCRM WABA - API",
        "description": "External REST API. Authenticate every request using **client-id** and **client-secret** headers.",
        "version": "1.0.0",
        "contact": {
            "url": "https://waba.microcrm.in"
        }
    },
    "servers": [
        {
            "url": "https://waba.microcrm.in/external-api",
            "description": "Production"
        }
    ],
    "components": {
        "securitySchemes": {
            "clientId": {
                "type": "apiKey",
                "in": "header",
                "name": "client-id",
                "description": "Your API client identifier"
            },
            "clientSecret": {
                "type": "apiKey",
                "in": "header",
                "name": "client-secret",
                "description": "Your API client secret"
            }
        },
        "schemas": {
            "SuccessResponse": {
                "type": "object",
                "properties": {
                    "status": {
                        "type": "string",
                        "example": "success"
                    },
                    "message": {
                        "type": "string"
                    },
                    "data": {
                        "type": "object"
                    }
                }
            },
            "ErrorResponse": {
                "type": "object",
                "properties": {
                    "status": {
                        "type": "string",
                        "example": "error"
                    },
                    "message": {
                        "type": "string"
                    },
                    "errors": {
                        "type": "object"
                    }
                }
            }
        }
    },
    "security": [
        {
            "clientId": [],
            "clientSecret": []
        }
    ],
    "tags": [
        {
            "name": "Contact",
            "description": "Contact management endpoints"
        },
        {
            "name": "Inbox",
            "description": "Inbox, conversation & messaging endpoints"
        }
    ],
    "paths": {
        "/contact/list": {
            "get": {
                "tags": [
                    "Contact"
                ],
                "summary": "Contact List",
                "description": "Retrieve a paginated list of contacts.",
                "operationId": "contactList",
                "parameters": [
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "default": 1
                        }
                    },
                    {
                        "name": "paginate",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "default": 20
                        }
                    },
                    {
                        "name": "search",
                        "in": "query",
                        "schema": {
                            "type": "string"
                        },
                        "description": "Search by name or mobile"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/SuccessResponse"
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized"
                    }
                }
            }
        },
        "/contact/store": {
            "post": {
                "tags": [
                    "Contact"
                ],
                "summary": "Create Contact",
                "operationId": "contactStore",
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "firstname",
                                    "lastname",
                                    "mobile_code",
                                    "mobile"
                                ],
                                "properties": {
                                    "firstname": {
                                        "type": "string",
                                        "example": "John"
                                    },
                                    "lastname": {
                                        "type": "string",
                                        "example": "Doe"
                                    },
                                    "mobile_code": {
                                        "type": "string",
                                        "example": "91"
                                    },
                                    "mobile": {
                                        "type": "string",
                                        "example": "9999999999"
                                    },
                                    "city": {
                                        "type": "string"
                                    },
                                    "address": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "201": {
                        "description": "Contact created"
                    },
                    "422": {
                        "description": "Validation error"
                    }
                }
            }
        },
        "/contact/update/{id}": {
            "post": {
                "tags": [
                    "Contact"
                ],
                "summary": "Update Contact",
                "operationId": "contactUpdate",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "Contact ID"
                    }
                ],
                "requestBody": {
                    "required": false,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "properties": {
                                    "firstname": {
                                        "type": "string"
                                    },
                                    "lastname": {
                                        "type": "string"
                                    },
                                    "mobile_code": {
                                        "type": "string"
                                    },
                                    "mobile": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Contact updated"
                    },
                    "404": {
                        "description": "Not found"
                    }
                }
            }
        },
        "/contact/delete/{id}": {
            "delete": {
                "tags": [
                    "Contact"
                ],
                "summary": "Delete Contact",
                "operationId": "contactDelete",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "Contact ID"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Deleted"
                    },
                    "404": {
                        "description": "Not found"
                    }
                }
            }
        },
        "/inbox/conversation-list": {
            "get": {
                "tags": [
                    "Inbox"
                ],
                "summary": "Conversation List",
                "operationId": "conversationList",
                "parameters": [
                    {
                        "name": "status",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "enum": [
                                1,
                                2,
                                3,
                                4
                            ]
                        },
                        "description": "1=Done, 2=Pending, 3=Important, 4=Unread"
                    },
                    {
                        "name": "page",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "default": 1
                        }
                    },
                    {
                        "name": "paginate",
                        "in": "query",
                        "schema": {
                            "type": "integer",
                            "default": 20
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success"
                    }
                }
            }
        },
        "/inbox/conversation-messages/{id}": {
            "get": {
                "tags": [
                    "Inbox"
                ],
                "summary": "Conversation Messages",
                "operationId": "conversationMessages",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "Conversation ID"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success"
                    },
                    "404": {
                        "description": "Not found"
                    }
                }
            }
        },
        "/inbox/conversation-details/{id}": {
            "get": {
                "tags": [
                    "Inbox"
                ],
                "summary": "Conversation Details",
                "operationId": "conversationDetails",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "Conversation ID"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "Success"
                    }
                }
            }
        },
        "/inbox/change-conversation-status/{id}": {
            "post": {
                "tags": [
                    "Inbox"
                ],
                "summary": "Change Conversation Status",
                "operationId": "changeConversationStatus",
                "parameters": [
                    {
                        "name": "id",
                        "in": "path",
                        "required": true,
                        "schema": {
                            "type": "integer"
                        },
                        "description": "Conversation ID"
                    }
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "status"
                                ],
                                "properties": {
                                    "status": {
                                        "type": "integer",
                                        "enum": [
                                            1,
                                            2,
                                            3,
                                            4
                                        ],
                                        "description": "1=Done, 2=Pending, 3=Important, 4=Unread"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Status updated"
                    }
                }
            }
        },
        "/inbox/send-message": {
            "post": {
                "tags": [
                    "Inbox"
                ],
                "summary": "Send Message",
                "operationId": "sendMessage",
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "mobile_code",
                                    "mobile",
                                    "message"
                                ],
                                "properties": {
                                    "mobile_code": {
                                        "type": "string",
                                        "example": "91"
                                    },
                                    "mobile": {
                                        "type": "string",
                                        "example": "9999999999"
                                    },
                                    "message": {
                                        "type": "string",
                                        "example": "Hello world"
                                    },
                                    "from_number": {
                                        "type": "string",
                                        "description": "WhatsApp phone number ID (optional)"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Message sent"
                    },
                    "422": {
                        "description": "Validation error"
                    }
                }
            }
        },
        "/inbox/template-list": {
            "get": {
                "tags": [
                    "Inbox"
                ],
                "summary": "Template List",
                "operationId": "templateList",
                "description": "Get all approved WhatsApp message templates.",
                "responses": {
                    "200": {
                        "description": "Success"
                    }
                }
            }
        },
        "/inbox/send-template-message": {
            "post": {
                "tags": [
                    "Inbox"
                ],
                "summary": "Send Template Message",
                "operationId": "sendTemplateMessage",
                "description": "Send a WhatsApp template message. Supports body variables, header media, and order/payment details.",
                "requestBody": {
                    "required": true,
                    "content": {
                        "multipart/form-data": {
                            "schema": {
                                "type": "object",
                                "required": [
                                    "mobile_code",
                                    "mobile",
                                    "template_id"
                                ],
                                "properties": {
                                    "mobile_code": {
                                        "type": "string",
                                        "example": "91"
                                    },
                                    "mobile": {
                                        "type": "string",
                                        "example": "9999999999"
                                    },
                                    "template_id": {
                                        "type": "string",
                                        "description": "Template ID"
                                    },
                                    "from_number": {
                                        "type": "string",
                                        "description": "WhatsApp phone number ID (optional)"
                                    },
                                    "body_variables": {
                                        "type": "array",
                                        "items": {
                                            "type": "string"
                                        },
                                        "description": "Body variable values"
                                    },
                                    "header_media_url": {
                                        "type": "string",
                                        "format": "uri",
                                        "description": "Public URL for header image/video/document"
                                    },
                                    "header_media_type": {
                                        "type": "string",
                                        "enum": [
                                            "image",
                                            "video",
                                            "document"
                                        ]
                                    },
                                    "header_media_filename": {
                                        "type": "string",
                                        "description": "Custom filename for document headers"
                                    },
                                    "configuration_name": {
                                        "type": "string",
                                        "description": "Payment configuration name"
                                    },
                                    "item_name": {
                                        "type": "string",
                                        "description": "Order item name"
                                    },
                                    "amount": {
                                        "type": "number",
                                        "description": "Order amount (INR)"
                                    },
                                    "goods_type": {
                                        "type": "string",
                                        "enum": [
                                            "digital-goods",
                                            "physical-goods"
                                        ]
                                    },
                                    "reference_id": {
                                        "type": "string",
                                        "description": "Order reference ID"
                                    },
                                    "quick_pay": {
                                        "type": "boolean",
                                        "description": "Enable quick pay"
                                    }
                                }
                            }
                        }
                    }
                },
                "responses": {
                    "200": {
                        "description": "Template sent"
                    },
                    "422": {
                        "description": "Validation error"
                    }
                }
            }
        }
    }
}