{
  "openapi": "3.0.3",
  "info": {
    "title": "https://www.2whats.com/ API",
    "version": "1.0.0",
    "description": "Auto-generated OpenAPI 3.0 spec for main endpoints. Refine parameter types, response schemas, and security as needed."
  },
  "servers": [
    {
      "url": "https://api.2whats.com",
      "description": "Local development"
    }
  ],
  "tags": [
    {
      "name": "Authentication",
      "description": "User authentication and account management"
    },
    {
      "name": "Password Reset",
      "description": "Password reset and recovery operations"
    },
    {
      "name": "Instance / Gateway",
      "description": "Instance management and gateway operations"
    },
    {
      "name": "Messaging",
      "description": "Message sending and management"
    },
    {
      "name": "Contacts",
      "description": "Contact management operations"
    },
    {
      "name": "Groups",
      "description": "User groups and chat groups management"
    },
    {
      "name": "File Upload",
      "description": "File upload operations"
    },
    {
      "name": "User Management",
      "description": "User account management"
    }
  ],
  "paths": {
    "/send": {
      "post": {
        "tags": ["Messaging"],
        "summary": "Send message(s)",
        "requestBody": {
          "required": true,
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "mobile": { "type": "string" },
                  "email": { "type": "string" },
                  "password": { "type": "string" },
                  "json": { "type": "integer", "format": "int32" },
                  "instanceid": { "type": "string" },
                  "numbers": { "type": "string", "description": "Comma separated numbers" },
                  "type": { "type": "integer", "description": "1=text,2=image,3=video,4=location" },
                  "message": { "type": "string" },
                  "date": { "type": "string", "format": "date-time" },
                  "fileurl": { "type": "string" },
                  "filename": { "type": "string" },
                  "lat": { "type": "string" },
                  "long": { "type": "string" },
                  "base64": { "type": "string", "description": "Base64 file content (optional)" }
                },
                "required": ["username", "password", "instanceid", "numbers"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "API response indicating success and message or sent IDs",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": { "type": "boolean" },
                    "msg": { "type": "string" }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/logout": {
      "post": {
        "tags": ["Instance / Gateway"],
        "summary": "Logout instance",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/screenshot": {
      "post": {
        "tags": ["Instance / Gateway"],
        "summary": "Request gateway screenshot",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Screenshot data or URL",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/message": {
      "post": {
        "tags": ["Messaging"],
        "summary": "Get single message status",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "msgid": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "msgid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Message status",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/messages": {
      "post": {
        "tags": ["Messaging"],
        "summary": "Get list of messages for an instance",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "last": { "type": "integer" },
                  "limit": { "type": "integer" },
                  "chatId": { "type": "string" },
                  "min_time": { "type": "string" },
                  "max_time": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Messages list (JSON)",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/contacts": {
      "post": {
        "tags": ["Contacts"],
        "summary": "Get contacts",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Contacts list",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/status": {
      "post": {
        "tags": ["Instance / Gateway"],
        "summary": "Get gateway/instance status",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Instance status",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/login": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Login (returns account info)",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "mobile": { "type": "string" },
                  "email": { "type": "string" },
                  "password": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Login result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/otp": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Verify OTP for current session user",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "otp": { "type": "string" }
                },
                "required": ["otp"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "OTP verification result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/signup": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Create new account",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "name": { "type": "string" },
                  "email": { "type": "string" },
                  "mobile": { "type": "string" },
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "confirmpassword": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["password", "confirmpassword"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Signup result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/forgetpassword": {
      "post": {
        "tags": ["Password Reset"],
        "summary": "Request password reset",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "useremail": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["useremail"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Password reset request result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/pwconfirm": {
      "post": {
        "tags": ["Password Reset"],
        "summary": "Confirm password reset code",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "code": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["code"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Confirmation result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/activate": {
      "post": {
        "tags": ["Authentication"],
        "summary": "Activate account with code",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "code": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["code"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Activation result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/changepassword": {
      "post": {
        "tags": ["User Management"],
        "summary": "Change password for logged user",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "oldpassword": { "type": "string" },
                  "newpassword": { "type": "string" },
                  "confirmpassword": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "oldpassword", "newpassword", "confirmpassword"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Change password result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/addgroup": {
      "post": {
        "tags": ["Groups"],
        "summary": "Add a user group",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "groupname": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "groupname"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/deletegroup": {
      "post": {
        "tags": ["Groups"],
        "summary": "Delete a user group",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "groupid": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "groupid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/getusergroups": {
      "post": {
        "tags": ["Groups"],
        "summary": "Get user groups",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Array of groups",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "type": "object" }
                }
              }
            }
          }
        }
      }
    },
    "/getcontactsbygroup": {
      "post": {
        "tags": ["Groups"],
        "summary": "Get contacts in a group",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "groupid": { "type": "string" },
                  "limit": { "type": "integer" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "groupid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Contacts list",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "type": "object" }
                }
              }
            }
          }
        }
      }
    },
    "/addnumbers": {
      "post": {
        "tags": ["Groups"],
        "summary": "Bulk add numbers to a group",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "groupid": { "type": "string" },
                  "numbers": { "type": "string", "description": "Phone numbers separated by newlines" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "groupid", "numbers"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/getvariants": {
      "post": {
        "tags": ["Messaging"],
        "summary": "Get message variants",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "json": { "type": "integer" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Variants object with user/global keys",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/uploadfile": {
      "post": {
        "tags": ["File Upload"],
        "summary": "Upload a file (base64 payload expected in 'file' field)",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "file": { "type": "string", "description": "Data URI: data:{mime};base64,{payload}" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "file"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "URL of uploaded file or error",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/logbulkmsgs": {
      "post": {
        "tags": ["Messaging"],
        "summary": "Log bulk messages",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "from": { "type": "string" },
                  "to": { "type": "string" },
                  "type": { "type": "integer" },
                  "source": { "type": "string" },
                  "msg": { "type": "string" },
                  "sentstate": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "from", "to", "msg"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/creategroup": {
      "post": {
        "tags": ["Groups"],
        "summary": "Create a chat group via instance",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "groupName": { "type": "string" },
                  "phones": { "type": "string" },
                  "msg": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid", "groupName", "phones"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Create group result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/leavegroup": {
      "post": {
        "tags": ["Groups"],
        "summary": "Leave a chat group",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "chatid": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid", "chatid"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/addgroupmember": {
      "post": {
        "tags": ["Groups"],
        "summary": "Add a member to a group",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "chatid": { "type": "string" },
                  "number": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid", "chatid", "number"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    },
    "/removegroupmember": {
      "post": {
        "tags": ["Groups"],
        "summary": "Remove a member from a group",
        "requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "username": { "type": "string" },
                  "password": { "type": "string" },
                  "instanceid": { "type": "string" },
                  "chatid": { "type": "string" },
                  "number": { "type": "string" },
                  "json": { "type": "integer" }
                },
                "required": ["username", "password", "instanceid", "chatid", "number"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result",
            "content": {
              "application/json": {
                "schema": { "type": "object" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "APIResponse": {
        "type": "object",
        "properties": {
          "success": { "type": "boolean" },
          "msg": {
            "oneOf": [
              { "type": "string" },
              { "type": "object" },
              { "type": "array" }
            ]
          }
        }
      }
    }
  }
}