> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/rest-api/identity-api/identity-api-reference/authentication/update-user-template.md).

# Update User Template

This service allows updating the Biometric Template associated with a specific user. Its main function is to synchronize the user's latest facial template stored in the client's data repository with a new template registered for the user.

#### Functionality

* **userId**: Unique user identifier, persisted and associated with the corresponding Biometric Template (oldRegisteredTemplateRaw). It needs at least two digits.
* **image (Optional)**: Base64 image obtained from the civil registry for authentication. It becomes mandatory if the registered Biometric Template (registeredTemplateRaw) is not provided.
* **oldRegisteredTemplateRaw**: Currently registered template associated with the userId.
* **newRegisteredTemplateRaw**: New template to associate with the userId. It must be persisted for future authentications.

### Endpoint

```
POST /services/updateUserTemplate
```

### Headers

| Name          | Type   | Required | Description                                                    |
| ------------- | ------ | -------- | -------------------------------------------------------------- |
| **x-api-key** | string | **Yes**  | Access authorization API key.                                  |
| **family**    | string | No       | Value: **Authentication**. Required with the tracking service. |

{% hint style="info" %}
All calls to the Endpoints for Tracking with **Identity Platform** must contain the header `family`.
{% endhint %}

### Request body

**Content-Type:** `application/json`

#### Parameters

| Parameter                  | Type   | Required | Description                                                                                                                                  |
| -------------------------- | ------ | -------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `userId`                   | string | **Yes**  | Unique user identifier. It must be persisted and associated with the corresponding Biometric Template. It needs at least two digits.         |
| `oldRegisteredTemplateRaw` | string | **Yes**  | Currently registered template associated with the userId.                                                                                    |
| `newRegisteredTemplateRaw` | string | **Yes**  | New template to associate with the userId. It must be persisted for future authentications.                                                  |
| `image`                    | string | No       | Base64 image obtained from the civil registry for authentication. It becomes mandatory if the registered Biometric Template is not provided. |
| `tracking`                 | object | No       | Object that represents the necessary tracking information.                                                                                   |
| `tracking.extraData`       | string | No       | Token generated by the Mobile/Web SDK. Contains tokenized tracking information with the Platform.                                            |
| `tracking.operationId`     | string | No       | Operation identifier generated by the Mobile/Web SDK.                                                                                        |

#### Request example

```json
{
  "userId": "001",
  "oldRegisteredTemplateRaw": "BAIBAQFpWL...",
  "newRegisteredTemplateRaw": "BAIBAQG0NRm0d...",
  "tracking": {
    "extraData": "BQABAQG2gBNjuHN...",
    "operationId": "123e4567-e89b-12d3-a456-426614174000"
  }
}
```

### Responses

#### `200` Success

#### Response parameters

| Parameter           | Type    | Description                                                                                                  |
| ------------------- | ------- | ------------------------------------------------------------------------------------------------------------ |
| `serviceResultCode` | integer | Code indicating the **overall result** of service execution. See [Service Result Code](#service-result-code) |
| `serviceResultLog`  | string  | Descriptive field of the execution result. If successful, it indicates the description of the result code.   |
| `timestamp`         | string  | Timestamp (UTC) of the response in format YYYY-MM-DDThh:flag\_mm:ss.SSSZ                                     |
| `transactionId`     | string  | Transaction identifier associated with the request processed by the API.                                     |

#### Service Result Code

The `serviceResultCode` indicates the overall result of the service execution:

| serviceResultCode | Description                                                                       | HTTP code |
| ----------------- | --------------------------------------------------------------------------------- | --------- |
| 0                 | The service execution was successful, the module processed the request correctly. | 200       |

#### Service Result Code: Update User Template

Specific result codes for the Endpoint `updateUserTemplate`:

| serviceResultCode | Description                                                                                                                                        | HTTP code |
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- | --------- |
| 0                 | The template (`templateRaw`) of the user was successfully updated.                                                                                 | 200       |
| -100              | The parameter `registeredTemplateRaw` does not match the ID: \[XXX]                                                                                | 401       |
| -102              | The parameter `registeredTemplateRaw` sent does not match the `templateRaw` registered for the user with ID: \[XXX]. InvalidRegisteredTemplateRaw. | 401       |
| -103              | User not found.                                                                                                                                    | 400       |

#### Response example

```json
{
  "timestamp": "2023-05-01T12:34:56.789Z",
  "transactionId": "123e4567-e89b-12d3-a456-426614174000",
  "serviceResultCode": 0,
  "serviceResultLog": "Service request successfully processed"
}
```

#### `400` Bad Request

```json
{
  "status": 400,
  "title": "Bad Request",
  "detail": "Invalid request.",
  "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/400",
  "errors": []
}
```

#### `401` Unauthorized

```json
{
  "message": "Unauthorized"
}
```

#### `403` Forbidden

```json
{
  "Message": "User is not authorized to access this resource with an explicit deny"
}
```

#### `502` Bad Gateway

```json
{
  "status": 502,
  "title": "Bad Gateway",
  "detail": "Server got an invalid response.",
  "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502"
}
```

#### `504` Gateway Timeout

```json
{
  "message": "Endpoint request timed out"
}
```
