> For the complete documentation index, see [llms.txt](https://docs.biti.so/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.biti.so/api-reference/auto-pay.md).

# auto pay

Mandates: the customer approves a limit per period. You charge within it.

| Endpoint                                                                   | Purpose                     |
| -------------------------------------------------------------------------- | --------------------------- |
| [`POST /partner/v1/create-mandate`](#post-partnerv1create-mandate)         | Create a mandate            |
| [`POST /partner/v1/charge-mandate`](#post-partnerv1charge-mandate)         | Charge a mandate            |
| [`POST /partner/v1/get-mandate-status`](#post-partnerv1get-mandate-status) | Get the status of a mandate |

## POST /partner/v1/create-mandate

**Create a mandate**

{% hint style="info" %}
Auth: send `client_id` and `client_secret` in the request body. Call it from your server only.
{% endhint %}

Ask for auto-pay approval up to a limit per period. The mandate is `pending` for 7 days. Then ask the customer to approve it with `biti.requestApproval({ mandate_id })`, or send the customer to the web approval page.

**Errors:**

* Invalid client credentials
* The reference was used with other terms
* `return_url` is not under your Allowed Origins

### Parameters

| Name            | Type   | Required | Description                                                                                 |
| --------------- | ------ | -------- | ------------------------------------------------------------------------------------------- |
| `client_id`     | string | yes      | Your client ID.                                                                             |
| `client_secret` | string | yes      | Your client secret. Server only.                                                            |
| `max_amount`    | number | yes      | Limit per period.                                                                           |
| `currency`      | string | yes      | Currency code.                                                                              |
| `period`        | string | yes      | `month` (from the 1st) or `week` (from Monday).                                             |
| `reference`     | string | yes      | Your unique id. The same `reference` returns the same mandate.                              |
| `description`   | string | no       | Text shown to the customer.                                                                 |
| `return_url`    | string | no       | Where the web approval page sends the customer back. It must be under your Allowed Origins. |

### Request

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

```bash
curl -X POST "https://api.biti.so/partner/v1/create-mandate" \
  -H "Content-Type: application/json" \
  -d '{
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET",
  "max_amount": 200,
  "currency": "USD",
  "period": "month",
  "reference": "AUTOPAY-C1009",
  "description": "Diyaar auto-pay"
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.biti.so/partner/v1/create-mandate"
headers = {
    "Content-Type": "application/json",
}
payload = {
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "max_amount": 200,
    "currency": "USD",
    "period": "month",
    "reference": "AUTOPAY-C1009",
    "description": "Diyaar auto-pay",
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const response = await fetch("https://api.biti.so/partner/v1/create-mandate", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "max_amount": 200,
    "currency": "USD",
    "period": "month",
    "reference": "AUTOPAY-C1009",
    "description": "Diyaar auto-pay"
  }),
});
console.log(await response.json());
```

{% endtab %}
{% endtabs %}

### Response

```json
{
  "success": true,
  "message": "",
  "data": {
    "mandate_id": "MMD-00007",
    "status": "pending",
    "expires_at": "2026-11-25 10:00:00"
  }
}
```

***

## POST /partner/v1/charge-mandate

**Charge a mandate**

{% hint style="info" %}
Auth: send `client_id` and `client_secret` in the request body. Call it from your server only.
{% endhint %}

Charge the customer any amount within what is left in the current period. You can also use `create-payment-request` with `mode: charge`.

**Errors:**

* Invalid client credentials
* The mandate is not active
* The amount is above what is left in the period
* The wallet cannot cover amount plus fee

### Parameters

| Name            | Type   | Required | Description                                                                      |
| --------------- | ------ | -------- | -------------------------------------------------------------------------------- |
| `client_id`     | string | yes      | Your client ID.                                                                  |
| `client_secret` | string | yes      | Your client secret. Server only.                                                 |
| `mandate_id`    | string | yes      | The mandate to charge.                                                           |
| `amount`        | number | yes      | Amount to charge.                                                                |
| `reference`     | string | yes      | Your unique id for this charge. The same `reference` returns the earlier charge. |

### Request

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

```bash
curl -X POST "https://api.biti.so/partner/v1/charge-mandate" \
  -H "Content-Type: application/json" \
  -d '{
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET",
  "mandate_id": "MMD-00007",
  "amount": 24.5,
  "reference": "ORD-1043"
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.biti.so/partner/v1/charge-mandate"
headers = {
    "Content-Type": "application/json",
}
payload = {
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "mandate_id": "MMD-00007",
    "amount": 24.5,
    "reference": "ORD-1043",
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const response = await fetch("https://api.biti.so/partner/v1/charge-mandate", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "mandate_id": "MMD-00007",
    "amount": 24.5,
    "reference": "ORD-1043"
  }),
});
console.log(await response.json());
```

{% endtab %}
{% endtabs %}

### Response

```json
{
  "success": true,
  "message": "",
  "data": {
    "status": "paid",
    "transaction_id": "8KQ..."
  }
}
```

***

## POST /partner/v1/get-mandate-status

**Get the status of a mandate**

{% hint style="info" %}
Auth: send `client_id` and `client_secret` in the request body. Call it from your server only.
{% endhint %}

Return the status and what is left in the current period.

`status` is `pending`, `active`, `revoked` or `expired`.

**Errors:**

* Invalid client credentials
* Unknown mandate

### Parameters

| Name            | Type   | Required | Description                      |
| --------------- | ------ | -------- | -------------------------------- |
| `client_id`     | string | yes      | Your client ID.                  |
| `client_secret` | string | yes      | Your client secret. Server only. |
| `mandate_id`    | string | yes      | The mandate to check.            |

### Request

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

```bash
curl -X POST "https://api.biti.so/partner/v1/get-mandate-status" \
  -H "Content-Type: application/json" \
  -d '{
  "client_id": "YOUR_CLIENT_ID",
  "client_secret": "YOUR_CLIENT_SECRET",
  "mandate_id": "MMD-00007"
}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests

url = "https://api.biti.so/partner/v1/get-mandate-status"
headers = {
    "Content-Type": "application/json",
}
payload = {
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "mandate_id": "MMD-00007",
}

response = requests.post(url, headers=headers, json=payload)
print(response.json())
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const response = await fetch("https://api.biti.so/partner/v1/get-mandate-status", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    "client_id": "YOUR_CLIENT_ID",
    "client_secret": "YOUR_CLIENT_SECRET",
    "mandate_id": "MMD-00007"
  }),
});
console.log(await response.json());
```

{% endtab %}
{% endtabs %}

### Response

```json
{
  "success": true,
  "message": "",
  "data": {
    "mandate_id": "MMD-00007",
    "status": "active",
    "max_amount": 200,
    "currency": "USD",
    "period": "month",
    "remaining": 175.5
  }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.biti.so/api-reference/auto-pay.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
