# 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"
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mpayafrica.co.tz/authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
