> For the complete documentation index, see [llms.txt](https://docs.v1.discover.r1learning.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.v1.discover.r1learning.com/endpoint-descriptions/user-management-endpoints/update-user.md).

# Update User

## Endpoint Description

The "Update User" endpoint allows for modifying existing user records within the R1 Discover system. It provides a means to keep user information current and accurate, encompassing updates to locations, program assignments, practitioner alignments, and user status.&#x20;

## HTTP Method

**PUT** `/api/v1/companies/{companyId}/users/{clientId}`

## Headers

* **Content-Type:** `application/json` - Indicates that the request body format is JSON.
* **Accept:** `application/json` - Specifies that the client expects to receive data in JSON format.
* **Authorization:** `Bearer {token}` - Requires a valid bearer token to authenticate and authorize the modification request.

## URL Parameters

* **companyId** *(integer)*: The identifier for the company to which the user belongs. This parameter must match an existing company in the R1 Discover database.
* **clientId** *(string)*: The unique identifier (unique\_id) for the user, provided by an integration partner system. This ID must correspond to an existing user within R1 Discover. See [Company User List](/endpoint-descriptions/company-management-endpoints/company-user-list.md) to get user details including the unique\_id.

## Body Parameters

* **username** *(string, optional)*: The unique username for the user. This must remain unique across R1 Discover and is used for identification and login purposes. See [Check Global Username Availability](/endpoint-descriptions/user-management-endpoints/check-global-username-availability.md).
* **company\_username** *(string, optional)*: An alternative username that may be used within specific company contexts, particularly where user identification differs from the global setting. See [Check Company Username Availability](/endpoint-descriptions/user-management-endpoints/check-company-username-availability.md).
* **client\_email** *(string, optional)*: The email address of the user, used for communications and account recovery. Must be unique within R1 Discover.
* **client\_location** *(string, optional)*: The location the user is aligned to within the company. See View Company Locations.
* **client\_program** *(string, optional)*: The program to which the user is assigned within the company. see View Company Programs.&#x20;
* **client\_practitioner** *(string, optional)*: The email address of the practitioner or counselor assigned to the user, see [View Company Practitioners](/endpoint-descriptions/company-management-endpoints/view-company-practitioners.md).
* **client\_status** *(string, optional)*: Indicates whether the user is active or inactive, allowing for the management of user access and engagement.

## Request Examples

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

```bash
curl --request PUT \
    "https://api.r1learning.com/api/v1/companies/1/users/abcxyz123456" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --header "Authorization: Bearer {token}" \
    --data "{
    \"username\": \"xyz123\",
    \"company_username\": \"xyz123\",
    \"client_email\": \"xyz@example.com\",
    \"client_location\": \"\\\"Bend Treatment Center\\\", \\\"Grants Pass Treatment Center\\\", \\\"Devon\\\", \\\"etc..\\\"\",
    \"client_program\": \"\\\"General\\\", \\\"PHP\\\", \\\"MSR\\\", \\\"etc..\\\"\",
    \"client_practitioner\": \"practitioner_email@example.com\",
    \"client_status\": \"\\\"active\\\", \\\"inactive\\\"\"
}"
```

{% endtab %}

{% tab title="Javascript" %}

```javascript
const url = new URL(
    "https://api.r1learning.com/api/v1/companies/1/users/abcxyz123456"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": "Bearer {token}",
};

let body = {
    "username": "xyz123",
    "company_username": "xyz123",
    "client_email": "xyz@example.com",
    "client_location": "\"Bend Treatment Center\", \"Grants Pass Treatment Center\", \"Devon\", \"etc..\"",
    "client_program": "\"General\", \"PHP\", \"MSR\", \"etc..\"",
    "client_practitioner": "practitioner_email@example.com",
    "client_status": "\"active\", \"inactive\""
};

fetch(url, {
    method: "PUT",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());
```

{% endtab %}

{% tab title="C# - Http" %}

```csharp
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Put, "https://api.r1learning.com/api/v1/companies/1/users/abcxyz123456");
request.Headers.Add("Accept", "application/json");
request.Headers.Add("Authorization", "Bearer {token}");
var content = new StringContent("{\"username\":\"xyz123\",\"company_username\":\"xyz123\",\"client_email\":\"xyz@example.com\",\"client_location\":\"\\\"Bend Treatment Center\\\", \\\"Grants Pass Treatment Center\\\", \\\"Devon\\\", \\\"etc..\\\"\",\"client_program\":\"\\\"General\\\", \\\"PHP\\\", \\\"MSR\\\", \\\"etc..\\\"\",\"client_practitioner\":\"practitioner_email@example.com\",\"client_status\":\"\\\"active\\\", \\\"inactive\\\"\"}", null, "application/json");
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());
```

{% endtab %}
{% endtabs %}

## Response Examples

{% tabs %}
{% tab title="200: OK" %}

```json
{
  "error": 0,
  "message": "User updated successfully",
  "data": {
    "username": "user123",
    "email": "user123@example.com"
  }
}
```

{% endtab %}

{% tab title="400: Bad Request" %}

```json
{
  "error": 400,
  "message": "Invalid data format or missing required fields."
}
```

{% endtab %}

{% tab title="401: Unauthorized" %}

```json
{
  "message": "Unauthentiated"
}
```

{% endtab %}

{% tab title="404: Not Found" %}

```json
{
  "error": 404,
  "message": "User not found with provided clientId."
}
```

{% endtab %}
{% endtabs %}

## Notes

* **Authorization Required:** Ensure the provided Bearer token is valid and has sufficient privileges to create an admin.
* **Data Validation:** All body parameters must be correctly formatted and complete. The system will validate these parameters and reject requests with missing or invalid data.
* **Uniqueness Required:** The `client_id`, `username` and `email` must be unique within the system to prevent conflicts.
