> For the complete documentation index, see [llms.txt](https://apidocs.d6plus.co.za/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://apidocs.d6plus.co.za/v2/reference/settings/client-integrations/change-client-integration-state.md).

# Change Client Integration State

<mark style="color:orange;">`POST`</mark> `/v2/settings/clientintegrations`

Use this endpoint to change the state of the integration for a client who has authorised your integration in their d6+ SAMS instance. This state indicates whether you are actively servicing the client or not.

### Request 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="191.94281005859375">Name</th><th width="128.314453125">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>school_id</code><mark style="color:red;">*</mark></td><td>Integer</td><td>The ID of the school to update</td></tr><tr><td><code>api_type_id</code><mark style="color:red;">*</mark></td><td>Integer</td><td>The api_type_id returned by the Get Clients endpoint</td></tr><tr><td><code>state</code><mark style="color:red;">*</mark></td><td>Boolean</td><td>The state you would like to set the integration to</td></tr></tbody></table>

### Response Examples

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

```json
{
    "success": true,
    "message": "Integration successfully activated",
    "data": {
        "school_id": 1000,
        "school_name": "d6+ Primary School",
        "admin_email_address": "support@d6plus.co.za",
        "telephone_calling_code": "27",
        "telephone_number": "0123334444",
        "api_type_id": 8,
        "api_type": "Admin+ API",
        "activated_by_integrator": "Yes" // <-
    }
}
```

{% endtab %}

{% tab title="Update Error (400 Bad Request)" %}
**Description:** When activating/deactivating the integration when it is already in that state

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

```json
{
    "success": false,
    "message": "Integration already activated",
    "data": {
        "school_id": 1000,
        "school_name": "d6+ Primary School",
        "admin_email_address": "support@d6plus.co.za",
        "telephone_calling_code": "27",
        "telephone_number": "0123334444",
        "api_type_id": 8,
        "api_type": "Admin+ API",
        "activated_by_integrator": "Yes" // <-
    }
}
```

{% endtab %}

{% tab title="Unauthorized Error (401 Unauthorized)" %}
**Description:** This error occurs when attempting to activate an integration for a school that has not authorized your integration. Schools must first authorize the integration before it can be activated by the integrator.

**Status:** <mark style="color:red;">`401 Unauthorized`</mark>

```json5
{
    "success": false,
    "message": "Client has not authorised access"
}
```

{% 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": {
        "api_type_id": "The api_type_id is invalid",
        "state": "The State must be a boolean"
    }
}
```

{% endtab %}
{% endtabs %}

### Code Samples

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

```php
<?php

// API Endpoint
const BASE_URL = 'https://integrate.d6plus.co.za/api/v2/settings/clientintegrations';

// API Credentials
const API_USERNAME = 'your_username';
const API_PASSWORD = 'your_password';

// Request payload
$data = [
    "school_id"   => 1000,
    "api_type_id" => 8,
    "state"       => 1
];

// Initialize cURL
$curl = curl_init();

// Set cURL options
curl_setopt_array($curl, [
    CURLOPT_URL            => BASE_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  => 'PATCH',
    CURLOPT_POSTFIELDS     => json_encode($data), // Encode array as JSON
    CURLOPT_HTTPHEADER     => [
        "Content-Type: application/json",
        "HTTP-X-USERNAME: " . API_USERNAME,
        "HTTP-X-PASSWORD: " . API_PASSWORD
    ],
]);

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

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

// Close cURL session
curl_close($curl);

// Output response
echo $response;

```

{% endtab %}

{% tab title="cURL" %}

```bash
curl --request PATCH "https://integrate.d6plus.co.za/api/v2/settings/clientintegrations" \
     --header "Content-Type: application/json" \
     --header "HTTP-X-USERNAME: your_username" \
     --header "HTTP-X-PASSWORD: your_password" \
     --data '{
         "school_id": 1000,
         "api_type_id": 8,
         "state": 1
     }'
```

{% endtab %}
{% endtabs %}
