> For the complete documentation index, see [llms.txt](https://docs.mpayafrica.co.tz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.mpayafrica.co.tz/authentication.md).

# Authentication

## Generating Access Token

The Generate Access Token Service is used to get a valid access token. The access token has to be specified in each request as described in the subparagraphs below.

The validity of the access token is time-limited and after each session, the token is invalidated irrespective of whether the service call resulted in a positive result or a failure. The access token will expire after 2 minutes if it is not used.

## Generate access token

<mark style="color:green;">`POST`</mark> `https://api.mpayafrica.co.tz/v2/auth`

#### Headers

| Name         | Type   | Description      |
| ------------ | ------ | ---------------- |
| Content-Type | string | application/json |

#### Request Body

| Name     | Type   | Description                                |
| -------- | ------ | ------------------------------------------ |
| password | string | API password. Shared upon account creation |
| username | string | API username. Shared upon account creation |

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

```
{
    "status": 1,
    "description": "Success",
    "token": "0b7af09a-920c-47e5-b8f8-b253117c1446"
}
```

{% endtab %}

{% tab title="400 " %}

```
{
    "status": 0,
    "description": "Bad request",
    "token": ""
}
```

{% endtab %}
{% endtabs %}

```
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8

{
    "username": "academia",
    "password": "ad540305-88b3-4aa4-9518-50c1504cb785"
}
```
