> For the complete documentation index, see [llms.txt](https://coat.gitbook.io/paal-ai-apis/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coat.gitbook.io/paal-ai-apis/paal-ai-api-docs/admin-apis.md).

# Admin APIs

### PAAL AI User Controller API Documentation

#### Introduction

This API documentation outlines the endpoints available for admin management in the PAAL AI application. These endpoints allow for the creation of new admin , user authentication, user data manipulation, password management, and email verification.

#### Base URL

The base URL for all endpoints is: <https://paal-ecosystem-backend.onrender.com>

Authentication

Some endpoints require authentication using a bearer token in the request header.

***

#### Create New Admin

Create a new admin account.

* **URL:** `/admin/new`
* **Method:** `POST`
* **Authentication:** Not required
* **Request Body:**
  * `email` (string, required with password): User's email address.
  * `password` (string, optional): if using user's password.
  * auth (String, optional) If using Google 0auth

**Example Request:**

```json
{
    "email": "example@email.com",
    "password": "password123"
}
```

**Example Response (Success):**

```json
{
    "status": true,
    "accessToken": "<JWT_ACCESS_TOKEN>",
    "verification": "pending"
}
```

**Example Response (Error):**

<pre class="language-json"><code class="lang-json">{
<strong>    msg: "Sign up details not complete",
</strong>    status: 'error',
    error: '1001'
}
</code></pre>

***

#### Admin Login

Authenticate an existing user.

* **URL:** `/admin/login`
* **Method:** `POST`
* **Authentication:** Not required
* **Request Body:**
  * `email` (string, required with password): User's email address.
  * `password` (string, optional): if using user's password.
  * auth (String, optional) If using Google 0auth

**Example Request:**

```json
{
    "email": "example@email.com",
    "password": "password123"
}
```

**Example Response (Success):**

```json
{
    "status": true,
    "accessToken": "<JWT_ACCESS_TOKEN>",
    "verification": "<verification_status>"
}
```

**Example Response (Error):**

```json
{
    msg: "Incorred password given",
    status: 'error',
    error: '1007'
}
```

***

#### Logout

Logout an authenticated admin.

* **URL:** `/admin/logout`
* **Method:** `POST`
* **Authentication:** Required (Bearer Token)

**Example Response (Success):**

```json
{
    "status": true
}
```

***

#### Request Email Verification Code

Request an email verification code for admin verification.

* **URL:** `/admin/verify`
* **Method:** `POST`
* **Authentication:** Required (Bearer Token)

**Example Response (Success):**

```json
{
    "status": true
}
```

***

#### Verify Email Verification Code

Verify the email verification code sent to the admin.

* **URL:** `/admin/verifycode`
* **Method:** `POST`
* **Authentication:** Required (Bearer Token)
* **Request Body:**
  * `code` (string, required): Verification code received via email.

**Example Request:**

```json
{
    "code": "123456"
}
```

**Example Response (Success):**

```json
{
    "status": true
}
```

***

#### Modify Admin profile data

Save user data such as email or password.

* **URL:** `/admin/save`
* **Method:** `POST`
* **Authentication:** Required (Bearer Token)
* **Request Body:** Admin data fields to be updated.

**Modifiable fields present**

* fullName
* password (required with oldPassword)
* oldPassword
* email
* displayName

**Example Request:**

```json
{
    "email": "newemail@email.com",
    "password": "newpassword123",
    "oldPassword":"0000",
}
```

**Example Response (Success):**

```json
{
    "status": true
}
```

***

#### Generate Reset Password Code

Generate a code for resetting the admin's password.

* **URL:** `/admin/resetpasswordcode`
* **Method:** `POST`
* **Authentication:** Not required
* **Request Body:**
  * `email` (string, required): User's email address.

**Example Request:**

```json
{
    "email": "example@email.com"
}
```

**Example Response (Success):**

```json
{
    "status": true
}
```

***

#### Reset Password

Reset the admin's password using the reset code.

* **URL:** `/admin/resetpassword`
* **Method:** `POST`
* **Authentication:** Not required
* **Request Body:**
  * `email` (string, required): User's email address.
  * `code` (string, required): Reset code received via email.
  * `password` (string, required): New password.

**Example Request:**

```json
{
    "email": "example@email.com",
    "code": "123456",
    "password": "newpassword123"
}
```

**Example Response (Success):**

```json
{
    "status": true
}
```

***

#### Error Responses

In case of errors, the API returns JSON responses with appropriate error messages.

**Example Error Response:**

```json
{
    msg: "There is no modifyable fields present",
    status: 'error',
    error: '1006'
}
```

***

***

#### Retrieve Admin Info

Retrieve information about an admin user.

* **URL:** `/admin`
* **Method:** `GET`
* **Authentication:** Required (Email query parameter or Bearer Token)
* **Query Parameters:**
  * `email` (string, optional): Admin's email address.
* **Request Headers:**
  * `Authorization: Bearer <TOKEN>` (string, optional): Bearer token for authentication.

**Example Request (Using Email):**

```http
GET /admin?email=admin@example.com
```

**Example Request (Using Bearer Token):**

```http
GET /admin/info
Authorization: Bearer <TOKEN>
```

**Example Response (Success):**

```json
{
    "status": true,
    "data": {
        "email": "admin@example.com",
        "fullName": "John Doe",
        "displayName": "John",
        "joined": "2023-05-01T12:00:00Z",
        "lastLogin": "2024-05-10T08:30:00Z",
        "verified": "verified",
        "data": {}
    }
}
```

**Example Response (Error):**

```json
{
    "error": "Admin user not found"
}
```

#### Error Responses

In case of errors, the API returns JSON responses with appropriate error messages.

**Example Error Response:**

```json
{
    "error": "Email parameter is missing"
}
```

***

This documentation provides details on how to interact with the PAAL AI admin management APIs. For any further assistance or clarification, please refer to the API documentation or contact support.
