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

# Admin

Info about admin(s)

```
STAGING_URL: https://switchapi3.azurewebsites.net
LIVE_URL: https://switchapi.azurewebsites.net
```

## Get admin info

<mark style="color:blue;">`GET`</mark> `https://switchapi3.azurewebsites.net/admin`

This endpoint retrieves the details of the admin currently logged in.

#### Headers

| Name          | Type   | Description                                            |
| ------------- | ------ | ------------------------------------------------------ |
| SWI-CID       | string | Client ID                                              |
| Authorization | string | Format for Authorization is ***Bearer token\_string*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Admin retrieved successfully",
    "data": {
        "id": 11,
        "email": "cs@switch.ng",
        "role": "customer_success",
        "disabled": false,
        "locked": false,
        "has_changed_password": true,
        "password_expired": false
    }
}
```

{% endtab %}
{% endtabs %}

## Get admin by id

<mark style="color:blue;">`GET`</mark> `https://switchapi3.azurewebsites.net/admin/:id`

This endpoint retrieves the admin by searching with the id

#### Path Parameters

| Name | Type    | Description |
| ---- | ------- | ----------- |
| id   | integer | admin id    |

#### Headers

| Name          | Type   | Description                                                |
| ------------- | ------ | ---------------------------------------------------------- |
| SWI-CID       | string | Client ID                                                  |
| Authorization | string | Format for the Authorization is ***Bearer token\_string*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Admin retrieved successfully",
    "data": {
        "id": 26,
        "email": "admin7@gmail.com",
        "role": "admin",
        "disabled": false
    }
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "message": "Admin with id - 100 -, does not exist"
}
```

{% endtab %}
{% endtabs %}

## Create admin

<mark style="color:green;">`POST`</mark> `https://switchapi3.azurewebsites.net/admin/new`

This endpoint creates a new admin and sends a randomly generated password to the admin's email if creation is successful.

#### Headers

| Name          | Type   | Description                                                |
| ------------- | ------ | ---------------------------------------------------------- |
| SWI-CS        | string | Payload checksum                                           |
| SWI-CID       | string | Client ID                                                  |
| Authorization | string | Format for the Authorization is ***Bearer token\_string*** |

#### Request Body

| Name  | Type   | Description                                                                              |
| ----- | ------ | ---------------------------------------------------------------------------------------- |
| email | string | admin email                                                                              |
| role  | string | Could be ***customer\_success, banking\_operations***, ***admin*** or ***super\_admin*** |

{% tabs %}
{% tab title="201 " %}

```
{
    "message": "Admin created successfully",
    "data": {
        "id": 11,
        "email": "admin6@gmail.com",
        "role": "admin",
        "disabled": false
    }
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "message": "Error occurred creating admin",
    "errors": {
        "email": [
            "has already been taken"
        ],
        "role": [
            "can't be blank"
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Get admin list

<mark style="color:blue;">`GET`</mark> `https://switchapi3.azurewebsites.net/admin/list`

This endpoint retrieves the list of admins.

#### Query Parameters

| Name          | Type   | Description                         |
| ------------- | ------ | ----------------------------------- |
| search\_query | string | Query used to search admin's emails |
| page          | string | Defaults to 1                       |
| per\_page     | string | Defaults to 20                      |

#### Headers

| Name          | Type   | Description                                                |
| ------------- | ------ | ---------------------------------------------------------- |
| SWI-CID       | string | Client ID                                                  |
| Authorization | string | Format for the Authorization is ***Bearer token\_string*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Admins retrieved successfully",
    "data": [
        {
            "id": 26,
            "email": "admin7@gmail.com",
            "role": "admin",
            "disabled": false
        },
        {
            "id": 12,
            "email": "ollaollu@gmail.com",
            "role": "super_admin",
            "disabled": false
        },
        {
            "id": 11,
            "email": "admin6@gmail.com",
            "role": "admin",
            "disabled": false
        },
        {
            "id": 8,
            "email": "admin5@gmail.com",
            "role": "admin",
            "disabled": false
        },
        {
            "id": 7,
            "email": "admin4@gmail.com",
            "role": "admin",
            "disabled": false
        },
        {
            "id": 6,
            "email": "admin3@gmail.com",
            "role": "admin",
            "disabled": false
        },
        {
            "id": 5,
            "email": "admin2@gmail.com",
            "role": "admin",
            "disabled": false
        },
        {
            "id": 4,
            "email": "admin1@gmail.com",
            "role": "admin",
            "disabled": false
        }
    ],
    "meta": {
        "total": 8,
        "per_page": 20,
        "page": 1,
        "page_count": 1
    }
}
```

{% endtab %}

{% tab title="401 " %}

```
{
    "message": "Only a superadmin can list admins"
}
```

{% endtab %}
{% endtabs %}

## Disable admin

<mark style="color:green;">`POST`</mark> `https://switchapi3.azurewebsites.net/admin/disable/:id`

This endpoint allows super-admins to disable admins.

#### Path Parameters

| Name | Type   | Description     |
| ---- | ------ | --------------- |
| id   | string | id of the admin |

#### Headers

| Name          | Type   | Description                                            |
| ------------- | ------ | ------------------------------------------------------ |
| SWI-CID       | string | Client ID                                              |
| Authorization | string | Format for Authorization is ***Bearer token\_string*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Admin disabled successfully",
    "data": {
        "id": 5,
        "email": "admin2@gmail.com",
        "role": "admin",
        "disabled": true
    }
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "message": "Admin is already disabled"
}
```

{% endtab %}

{% tab title="403 " %}

```
{
    "message": "Cannot disable self"
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "message": "Admin with id - 3 -, does not exist"
}
```

{% endtab %}
{% endtabs %}

## Enable a disabled admin

<mark style="color:green;">`POST`</mark> `https://switchapi3.azurewebsites.net/admin/enable/:id`

This endpoint allows superadmins to enable disabled admins.

#### Path Parameters

| Name | Type   | Description     |
| ---- | ------ | --------------- |
| id   | string | id of the admin |

#### Headers

| Name          | Type   | Description                                            |
| ------------- | ------ | ------------------------------------------------------ |
| SWI-CID       | string | Client ID                                              |
| Authorization | string | Format for Authorization is ***Bearer token\_string*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Admin enabled successfully",
    "data": {
        "id": 5,
        "email": "admin2@gmail.com",
        "role": "customer_success",
        "disabled": false
    }
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "message": "Admin is not disabled"
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "message": "Admin with id - 2 -, does not exist"
}
```

{% endtab %}
{% endtabs %}

## Change Password

<mark style="color:green;">`POST`</mark> `https://switchapi3.azurewebsites.net/admin/update_password`

Change admin password.

#### Headers

| Name          | Type   | Description                                            |
| ------------- | ------ | ------------------------------------------------------ |
| SWI-CS        | string | Payload checksum                                       |
| SWI-CID       | string | Client ID                                              |
| Authorization | string | Format for Authorization is ***Bearer token\_string*** |

#### Request Body

| Name                   | Type   | Description                  |
| ---------------------- | ------ | ---------------------------- |
| current\_password      | string | The admin's current password |
| password               | string | The new password             |
| password\_confirmation | string | password confirmation        |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Admin password changed successfully",
    "data": {
        "id": 4,
        "email": "admin1@gmail.com",
        "role": "super_admin",
        "disabled": false
    }
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "message": "Error occurred changing password",
    "errors": {
        "password": [
            "has been used previously. Please try a new password"
        ]
    }
}
```

{% endtab %}
{% endtabs %}

## Reset Admin Password

<mark style="color:green;">`POST`</mark> `https://switchapi3.azurewebsites.net/admin/reset_password/:id`

This endpoint allows a super admin to reset an admin's password. The new password (which is randomly generated) is then sent to the admin's email.

#### Path Parameters

| Name | Type   | Description                                       |
| ---- | ------ | ------------------------------------------------- |
| id   | string | The id of the admin whose password is to be reset |

#### Headers

| Name          | Type   | Description                                            |
| ------------- | ------ | ------------------------------------------------------ |
| SWI-CID       | string | Client ID                                              |
| Authorization | string | Format for Authorization is ***Bearer token\_string*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "password reset successfully"
}
```

{% endtab %}

{% tab title="401 " %}

```
{
    "message": "Only an admin with a role of super_admin can perform this action"
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "message": "admin with id -1100- does not exist"
}
```

{% endtab %}
{% endtabs %}

## Unlock Account

<mark style="color:green;">`POST`</mark> `https://switchapi3.azurewebsites.net/admin/unlock/:id`

This endpoint allows a super admin to send an unlock email to the locked admin's email address.

#### Path Parameters

| Name | Type   | Description                         |
| ---- | ------ | ----------------------------------- |
| id   | string | The id of the admin to be unlocked. |

#### Headers

| Name          | Type   | Description                                            |
| ------------- | ------ | ------------------------------------------------------ |
| SWI-CID       | string | Client ID                                              |
| Authorization | string | Format for Authorization is ***Bearer token\_string*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "unlock email has been sent to this admin's mail"
}
```

{% endtab %}

{% tab title="401 " %}

```
{
    "message": "Only an admin with a role of super_admin can perform this action"
}
```

{% endtab %}

{% tab title="404 " %}

```
{
    "message": "admin with id -1100- does not exist"
}
```

{% endtab %}
{% endtabs %}

## Update Role

<mark style="color:green;">`POST`</mark> `https://switchapi3.azurewebsites.net/admin/role/:id`

This endpoint allows a super admin to update the role of another admin.

#### Path Parameters

| Name | Type   | Description         |
| ---- | ------ | ------------------- |
| id   | string | The id of the admin |

#### Headers

| Name          | Type   | Description                                     |
| ------------- | ------ | ----------------------------------------------- |
| SWI-CS        | string | Payload checksum                                |
| SWI-CID       | string | Client ID                                       |
| Authorization | string | Format for Authorization is ***Bearer token***. |

#### Request Body

| Name | Type   | Description                                                                                  |
| ---- | ------ | -------------------------------------------------------------------------------------------- |
| role | string | Any of ***customer\_success***, ***banking\_operations***, ***admin*** or ***super\_admin*** |

{% tabs %}
{% tab title="200 " %}

```
{
    "message": "Admin role updated successfully",
    "data": {
        "id": "19",
        "email": "someone@gmail.com",
        "disabled": false,
        "role": "admin",
        "has_changed_password": false,
        "locked": false
    }
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "message": "Admin role is already admin"
}
```

{% endtab %}
{% endtabs %}
