# Get Accountable Person(s)

<mark style="color:blue;">`GET`</mark> `/v2/finplus/debtmanagement/accountablepersons` `(/{id})`

This endpoint **retrieves one or all accountable persons** for the specified school.

* By default, only accountable persons with **active debtor accounts** (current learners or accounts with an outstanding balance) are returned.
* The `all_accounts` query parameter can be used to fetch all accountable persons, including those with **left learners** and **zero-balance accounts**.
* The `include_learners` query parameter allows learners' data to be included in the response.
* You can filter results using the `debtor_code` or `accountable_person_id` query parameters.

{% hint style="info" %}
By default, this endpoint returns a **collection of records**, wrapped in a `data` array. To retrieve a **single record**, provide its **ID in the URL**, which will return a **single object** instead of a collection.
{% endhint %}

### Pagination <a href="#pagination" id="pagination"></a>

The response data includes a `meta` object that contains **pagination-specific metadata**. You can use the following query parameters to **control pagination**:

* **limit**: This parameter allows you to override the default limit of records returned, up to the `max_allowed_limit` specified in the response's `meta` object.
* **cursor**: If the `meta` object contains a `next_cursor` field, it indicates that more records are available. To fetch the next set of records, include the `cursor` parameter in your request with the value of `next_cursor`. If the `next_cursor` field is not present, it means there are no more records to retrieve.
* **reverse\_order**: This parameter can be used to reverse the order in which the data is returned, useful for fetching the latest records first.

### Path Parameters

<table><thead><tr><th width="186.6571044921875">Name</th><th width="102">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>{id}</code></td><td>Integer</td><td>Optionally provide the <strong>Accountable Person ID</strong> for retrieving a single record.</td></tr></tbody></table>

### Request Headers

<table><thead><tr><th width="194.228515625">Name</th><th width="107.88580322265625">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>HTTP-X-USERNAME</code><mark style="color:red;">*</mark></td><td>String</td><td>As provided by d6</td></tr><tr><td><code>HTTP-X-PASSWORD</code><mark style="color:red;">*</mark></td><td>String</td><td>As provided by d6</td></tr><tr><td><code>HTTP-X-SCHOOLID</code><mark style="color:red;">*</mark></td><td>Integer</td><td>The unique identifier of the school for which the data is being queried.</td></tr></tbody></table>

### Query Parameters

<table><thead><tr><th width="180.4285888671875">Name</th><th width="114">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>all_accounts</code></td><td>Boolean</td><td>Whether to include <strong>all accounts</strong></td></tr><tr><td><code>include_learners</code></td><td>Boolean</td><td>Whether to include the <strong>learner data</strong> in the response</td></tr><tr><td><code>debtor_code</code></td><td>Integer</td><td>To filter on a specific <strong>Debtor Code</strong></td></tr><tr><td><code>cursor</code></td><td>String</td><td>To <strong>retrieve</strong> the <strong>next group</strong> of items (if any)</td></tr><tr><td><code>limit</code></td><td>Integer</td><td>To <strong>override</strong> the <strong>default limit</strong> of records returned (up to the <code>max_allowed_limit</code> provided in the response metadata).</td></tr><tr><td><code>reverse_order</code></td><td>Boolean</td><td>To <strong>reverse</strong> the <strong>order</strong> the data is returned in</td></tr></tbody></table>

### Response Examples

{% tabs %}
{% tab title="Success - Collection (200 OK)" %}
**Status:** <mark style="color:green;">`200 OK`</mark>

<pre class="language-json"><code class="lang-json">{
    "data": [
<strong>        {
</strong>            "accountable_person_id": "40",
            "title": "Mr",
            "first_name": "John",
            "full_names": "John James",
            "last_name": "Smith",
            "debtor_code": "1001",
            "mobile_calling_code": "27",
            "mobile_number": "0821237654",
            "work_tel_number": "0124567890",
            "home_tel_number": "0123214567",
            "email_address": "jjsmith@example.com",
            "residential_address": "Moneytow Street\r\nNow Village\r\n0123\r\nSouth Africa",
            "postal_address": "Moneytow Street\r\nNow Village\r\n0123\r\nSouth Africa",
            "home_language": "English",
            "correspondence_language": "English",
            "communication_method": "E-Mail",
            "include_in_debtor_comms": "Yes",
            "nationality": "South Africa",
            "id_number": "8104050240082",
            "passport_number": "A456732243",
            "employer": "Greenholt Group",
            "employer_address": "3 School Lane\r\nBig City\r\nSouth Africa",
            "account_closing_date": "0000-00-00",
            "account_start_date": "2023-01-01"
        },
        {
            "accountable_person_id": "3",
            "title": "Mr",
            "first_name": "Nic",
            "full_names": "Nicholas Nigel",
            "last_name": "Webster",
            "debtor_code": "1002",
            "mobile_calling_code": "27",
            "mobile_number": "0678901234",
            "work_tel_number": "",
            "home_tel_number": "",
            "email_address": "nicnwebster@example.co.za",
            "residential_address": "7th Street\r\nSmall Town\r\n0123\r\nSouth Africa",
            "postal_address": "7th Street\r\nSmall Town\r\n0123\r\nSouth Africa",
            "home_language": "English",
            "correspondence_language": "English",
            "communication_method": "SMS",
            "include_in_debtor_comms": "No",
            "nationality": "South Africa",
            "id_number": "",
            "passport_number": "",
            "employer": "",
            "employer_address": "",
            "account_closing_date": "0000-00-00",
            "account_start_date": "2023-01-01"
        }
    ],
    "meta": {
        "limit": 10,
        "max_allowed_limit": 50,
        "cursor": "eyJpZCI6MjU0NiwiX2JhY2t3YXJkIjpmYWxzZX0"
    }
}
</code></pre>

{% endtab %}

{% tab title="Success - Including Learners (200 OK)" %}
**Status:** <mark style="color:green;">`200 OK`</mark>

```json
{
    "data": [
        {
            "accountable_person_id": "40",
            "title": "Mr",
            "first_name": "John",
            "full_names": "John James",
            "last_name": "Smith",
            "debtor_code": "1001",
            "mobile_calling_code": "27",
            "mobile_number": "0821237654",
            "work_tel_number": "0124567890",
            "home_tel_number": "0123214567",
            "email_address": "jjsmith@example.com",
            "residential_address": "Moneytow Street\r\nNow Village\r\n0123\r\nSouth Africa",
            "postal_address": "Moneytow Street\r\nNow Village\r\n0123\r\nSouth Africa",
            "home_language": "English",
            "correspondence_language": "English",
            "communication_method": "E-Mail",
            "include_in_debtor_comms": "Yes",
            "nationality": "South Africa",
            "id_number": "8104050240082",
            "passport_number": "A456732243",
            "employer": "Greenholt Group",
            "employer_address": "3 School Lane\r\nBig City\r\nSouth Africa",
            "account_closing_date": "0000-00-00",
            "account_start_date": "2023-01-01",
            "learners": [
                {
                    "learner_id": "1",
                    "first_name": "John",
                    "last_name": "Smith",
                    "gender": "M",
                    "grade": "7"
                }
            ]
        },
        {
            "accountable_person_id": "3",
            "title": "Mr",
            "first_name": "Nic",
            "full_names": "Nicholas Nigel",
            "last_name": "Webster",
            "debtor_code": "1002",
            "mobile_calling_code": "27",
            "mobile_number": "0678901234",
            "work_tel_number": "",
            "home_tel_number": "",
            "email_address": "nicnwebster@example.co.za",
            "residential_address": "7th Street\r\nSmall Town\r\n0123\r\nSouth Africa",
            "postal_address": "7th Street\r\nSmall Town\r\n0123\r\nSouth Africa",
            "home_language": "English",
            "correspondence_language": "English",
            "communication_method": "SMS",
            "include_in_debtor_comms": "Yes",
            "nationality": "South Africa",
            "id_number": "",
            "passport_number": "",
            "employer": "",
            "employer_address": "",
            "account_closing_date": "0000-00-00",
            "account_start_date": "2023-01-01",
            "learners": [
                {
                    "learner_id": "51",
                    "first_name": "Michelle",
                    "last_name": "Webster",
                    "gender": "F",
                    "grade": "3"
                }
            ]
        }
    ],
    "meta": {
        "limit": 10,
        "max_allowed_limit": 50,
        "cursor": "eyJpZCI6MjU0NiwiX2JhY2t3YXJkIjpmYWxzZX0"
    }
}
```

{% endtab %}

{% tab title="Success - Resource (200 OK)" %}
**Status:** <mark style="color:green;">`200 OK`</mark>

<pre class="language-json"><code class="lang-json"><strong>{
</strong>    "accountable_person_id": "40",
    "title": "Mr",
    "first_name": "John",
    "full_names": "John James",
    "last_name": "Smith",
    "debtor_code": "1001",
    "mobile_calling_code": "27",
    "mobile_number": "0821237654",
    "work_tel_number": "0124567890",
    "home_tel_number": "0123214567",
    "email_address": "jjsmith@example.com",
    "residential_address": "Moneytow Street\r\nNow Village\r\n0123\r\nSouth Africa",
    "postal_address": "Moneytow Street\r\nNow Village\r\n0123\r\nSouth Africa",
    "home_language": "English",
    "correspondence_language": "English",
    "communication_method": "E-Mail",
    "include_in_debtor_comms": "Yes",
    "nationality": "South Africa",
    "id_number": "8104050240082",
    "passport_number": "A456732243",
    "employer": "Greenholt Group",
    "employer_address": "3 School Lane\r\nBig City\r\nSouth Africa",
    "account_closing_date": "0000-00-00",
    "account_start_date": "2023-01-01"
}
</code></pre>

{% endtab %}

{% tab title="ID Not Found Error (404 Not Found)" %}
**Description:** The requested ID does not exist in the system.

**Status:** <mark style="color:red;">`404 Not Found`</mark>

```json
{
    "success": false,
    "message": "The person does not exist"
}
```

{% endtab %}

{% tab title="Validation Error (400 Bad Request)" %}
**Description:** When validation failed for one or more fields

**Status:** <mark style="color:red;">`400 Bad Request`</mark>

```json
{
    "success": false,
    "message": "Validation Failed",
    "validation_errors": {
        "include_learners": "The Include learners must be a boolean"
    }
}
```

{% endtab %}
{% endtabs %}

### Code Samples

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

```php
<?php

// API Credentials
$api_username = 'your_username';
$api_password = 'your_password';
$school_id = 'the_school_id';

// Base API endpoint
define('BASE_URL', 'https://integrate.d6plus.co.za/api/v2/finplus/debtmanagement/accountablepersons');

// Optional: Set an ID to fetch a specific person (or leave empty for all)
$id = '';

$url = BASE_URL;
if (!empty($id)) {
    $url .= '/' . $id;
}

// Query parameters (optional)
$query_params = [
    'all_accounts' => 1,
    'include_learners' => 1,
    'debtor_code' => '1002',
    'reverse_order' => 1,
    'limit' => 10,
    'cursor' => 'eyJpZCI6MjU0NiwiX2JhY2t3YXJkIjpmYWxzZX0',
];

if (!empty($query_params)) {
    $url .= '?' . http_build_query($query_params);
}

// Initialize cURL
$curl = curl_init();

// Set cURL options
curl_setopt_array($curl, [
    CURLOPT_URL            => $url,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 30,  // Set timeout to prevent hanging requests
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_HTTP_VERSION   => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST  => 'GET',
    CURLOPT_HTTPHEADER     => [
        "HTTP-X-USERNAME: $api_username",
        "HTTP-X-PASSWORD: $api_password",
        "HTTP-X-SCHOOLID: $school_id"
    ],
]);

// Execute request
$response = curl_exec($curl);

// Check for errors
$error = curl_error($curl);
if ($error) {
    curl_close($curl);
    throw new Exception("cURL Error: $error");
}

// Close cURL and output response
curl_close($curl);
echo $response;

```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request GET 'https://integrate.d6plus.co.za/api/v2/finplus/debtmanagement/accountablepersons?all_accounts=1' \
     --header 'HTTP-X-USERNAME: your_username' \
     --header 'HTTP-X-PASSWORD: your_password' \
     --header 'HTTP-X-SCHOOLID: the_school_id'
```

{% endtab %}
{% endtabs %}
