# Update Note

## Update an existing debtor note

<mark style="color:purple;">`PATCH`</mark> `https://integrate.d6plus.co.za/api/v1/finplus/debtmanagement/debtornotes/notes/{school_login_id}`

Use this endpoint to update an existing debtor note for the specified school.&#x20;

The `note_id` is required and can be found using the [Get Note(s)](https://apidocs.d6plus.co.za/reference/finance+/debt-management/debtor-notes/get-note-s) call.

If you need to update the payment arrangements attached to a promise-to-pay note, you must include the updated data in the `promise_to_pays` array (see below for more information). To update an existing promise-to-pay's data, the `promise_to_pay_id` needs to be included. This can be found either under the [Get Note(s)](https://apidocs.d6plus.co.za/reference/finance+/debt-management/debtor-notes/get-note-s) call or the [Get Promise To Pay(s)](https://apidocs.d6plus.co.za/reference/finance+/debt-management/debtor-notes/get-promise-to-pay-s). If a `promise_to_pay_id` is not included, a new promise-to-pay will be created. The API will not allow a promise-to-pay to be added to the note if the `date_promised` and `amount_promised` matches an existing record.

To restore a deleted note, provide the `note_id` and set the `status` to "Created".

To see more information about the individual fields, please refer to the [Create Note](https://apidocs.d6plus.co.za/reference/finance+/debt-management/debtor-notes/create-note) page.

#### Path Parameters

| Name                                                | Type    | Description                                      |
| --------------------------------------------------- | ------- | ------------------------------------------------ |
| school\_login\_id<mark style="color:red;">\*</mark> | Integer | The login ID of the school to retrieve data from |

#### Headers

| Name                                              | Type   | Description       |
| ------------------------------------------------- | ------ | ----------------- |
| HTTP-X-USERNAME<mark style="color:red;">\*</mark> | String | As provided by d6 |
| HTTP-X-PASSWORD<mark style="color:red;">\*</mark> | String | As provided by d6 |

#### Request Body

<table><thead><tr><th width="261">Name</th><th width="98">Type</th><th>Description</th></tr></thead><tbody><tr><td>note_id<mark style="color:red;">*</mark></td><td>Integer</td><td>The id of the debtor note</td></tr><tr><td>accountable_person_id</td><td>Integer</td><td>The id of the accountable person who the note belongs to.</td></tr><tr><td>date</td><td>String</td><td>The date of the note in "yyyy-mm-dd" format.</td></tr><tr><td>note_type_id</td><td>Integer</td><td>The id of the note type.</td></tr><tr><td>communication_type_id</td><td>Integer</td><td>The id of the communication type (not required for internal notes).</td></tr><tr><td>note</td><td>String</td><td>The note text</td></tr><tr><td>status</td><td>String</td><td>The status of the note (either "Created" or "Deleted")</td></tr><tr><td>promise_to_pays</td><td>Array</td><td>An array of payment arrangement data for promise-to-pay notes</td></tr></tbody></table>

#### Request Examples

{% tabs %}
{% tab title="Update a note" %}

```json
{
    "note_id": "7",
    "date": "2024-04-16",
    "note": "Mr Webster asked to be phoned back tomorrow at 10am"
}
```

{% endtab %}

{% tab title="Update / Add Promise-to-Pay" %}

```json
{
    "note_id": "6",
    "promise_to_pays": [
        {
            // Updating an existing promise to pay
            "promise_to_pay_id": "12",
            "date_promised": "2020-05-31",
            "amount_promised": "1500.00"
        },
        {
            // Create a new promise to pay
            "date_promised": "2020-06-30",
            "amount_promised": "500.00"
        }
    ]
}
```

{% endtab %}

{% tab title="Restore a deleted note" %}

```json
{
    "note_id": "6",
    "status": "Created"
}
```

{% endtab %}
{% endtabs %}

#### Response Examples

{% tabs %}
{% tab title="200 The request was successful." %}

```json
{
    "note_id": "7",
    "accountable_person_id": "3",
    "accountable_person": "Mr Webster, Nic",
    "debtor_code": "1002",
    "debtor_reference": "Webster",
    "date": "2024-04-15",
    "note_type_id": "3",
    "note_type": "Internal",
    "communication_type_id": "7",
    "communication_type": "Internal",
    "note": "Mr Webster asked to be phoned back tomorrow at 10am",
    "status": "Created"
}
```

{% endtab %}

{% tab title="200 Including Promise to Pays" %}

```json
{
    "note_id": "6",
    "accountable_person_id": "40",
    "accountable_person": "Mr James, John",
    "debtor_code": "1001",
    "debtor_reference": "James",
    "date": "2024-03-03",
    "note_type_id": "2",
    "note_type": "Promise to Pay",
    "communication_type_id": "2",
    "communication_type": "E-mail",
    "note": "Payment arrangement of R1000 to be paid off on outstanding school fees",
    "status": "Created",
    "promise_to_pays": [
        {
            "promise_to_pay_id": "8",
            "date_promised": "2024-03-31",
            "amount_promised": "1000.00",
            "amount_paid": "1000.00",
            "promise_completed": "Yes"
        },
        {
            "promise_to_pay_id": "10",
            "date_promised": "2024-04-30",
            "amount_promised": "1000.00",
            "amount_paid": "750.00",
            "promise_completed": "Partial"
        },
        {
            "promise_to_pay_id": "12",
            "date_promised": "2020-05-31",
            "amount_promised": "1500.00",
            "amount_paid": "",
            "promise_completed": "No"
        },
        {
            "promise_to_pay_id": "13",
            "date_promised": "2020-06-30",
            "amount_promised": "500.00"
            "amount_paid": "",
            "promise_completed": "No"
        }
    ]
}
```

{% endtab %}

{% tab title="404: Not Found The resource was not found." %}

```json
{
    "error": "Not Found",
    "error_description": "The note does not exist"
}
```

{% endtab %}

{% tab title="401: Unauthorized The server understood the request, but is refusing it or access is not allowed." %}

```json
{
    "error": "Unauthorized",
    "error_description": "Client access not authorised"
}
```

{% endtab %}

{% tab title="403: Forbidden The server understood the request, but the requested action is not allowed." %}

```json
{
    "error": "Integration not activated",
    "error_description": "Please activate the Admin+ API for this client before making this request"
}
```

{% endtab %}
{% endtabs %}

## Code Samples

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

```php
<?php

const BASE_URL = 'https://integrate.d6plus.co.za/api/v1/finplus/debtmanagement/debtornotes/notes';
const SCHOOL_LOGIN_ID = '1000';
const PARAMS = [
    'note_id' => 7,
    'date' => '2024-04-16',
    'note' => 'Mr Webster asked to be phoned back tomorrow at 10am'
];
const API_USERNAME = getenv('API_USERNAME'); // Assuming you have these environment variables set
const API_PASSWORD = getenv('API_PASSWORD');

$curl = curl_init();

$options = [
    CURLOPT_URL => BASE_URL . '/' . SCHOOL_LOGIN_ID,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_SSL_VERIFYPEER => true,
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_POSTFIELDS => json_encode(PARAMS),
    CURLOPT_HTTPHEADER => [
        "HTTP-X-USERNAME: " . API_USERNAME,
        "HTTP-X-PASSWORD: " . API_PASSWORD
    ],
];

curl_setopt_array($curl, $options);

$response = curl_exec($curl);

if (curl_errno($curl)) {
    throw new Exception('Curl error: ' . curl_error($curl));
}

curl_close($curl);

echo $response;
```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --location --request PATCH 'https://integrate.d6plus.co.za/api/v1/finplus/debtmanagement/debtornotes/notes/1000' \
--header 'HTTP-X-USERNAME: your_username' \
--header 'HTTP-X-PASSWORD: your_password' \
--header 'Content-Type: application/json' \
--data '{
    "accountable_person_id": "40",
    "date": "2024-03-03",
    "note_type_id": "2",
    "communication_type_id": "2",
    "note": "Payment arrangement of R1000 to be paid off on outstanding school fees",
    "promise_to_pays": [
        {
            "date_promised": "2024-03-31",
            "amount_promised": "1000.00"
        }
    ]
}'
```

{% endtab %}
{% endtabs %}
