> 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/country-integrations/chile/traspasos-afp/verify.md).

# Verify

Service that validates the user's identity and generates a verification token for Integration with Previred.

This service validates all Onboarding results and generates a secure token that is used to build the verification URL shared with Previred.

### Prerequisites

Before calling this service, make sure the user has completed the Onboarding process with valid results:

* `facialAuthenticationResult = 3` (Successful facial authentication)
* `passiveLivenessResult = 3` (liveness check passed)
* `documentValidation = 9001` (Document validation approved)

### Endpoint

```
POST /services/previred/{serviceTransactionId}/verify
```

### Headers

| Name          | Type   | Required | Description                   |
| ------------- | ------ | -------- | ----------------------------- |
| **x-api-key** | string | **Yes**  | Access authorization API Key. |

### Path parameters

| Parameter              | Type   | Required | Description                                             |
| ---------------------- | ------ | -------- | ------------------------------------------------------- |
| `serviceTransactionId` | string | **Yes**  | Unique transaction identifier for the transfer process. |

### Request body

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

#### Parameters

| Parameter       | Type   | Required | Description                                                                                   |
| --------------- | ------ | -------- | --------------------------------------------------------------------------------------------- |
| `scanReference` | string | **Yes**  | Reference identifier of the Onboarding process that contains the identity validation results. |

#### Request example

```json
{
  "scanReference": "550e8400-e29b-41d4-a716-446655440000"
}
```

### Responses

#### `200` Success

#### Response parameters

| Parameter | Type   | Description                                                            |
| --------- | ------ | ---------------------------------------------------------------------- |
| `token`   | string | Verification token to build the verification URL shared with Previred. |

#### Response example

```json
{
  "token": "MUOJHSYODkRtgVENLbXXXpujiDHqGTYS"
}
```

{% hint style="warning" %}
Store the token securely, as it is required in the next steps.
{% endhint %}

#### `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"
}
```

#### `404` Not Found

```json
{
  "status": 404,
  "title": "Not Found",
  "detail": "Resource not found.",
  "type": "https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404"
}
```

#### `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"
}
```

***

### Sending verification evidence to Previred

Once the token is obtained, the AFP must send the `url_verificacion` to Previred as proof of validation.

#### Verification URL format

```
{host}/services/previred/{serviceTransactionId}/certificate?token={token}&apiKey={previredApiKey}
```

{% hint style="info" %}
The `apiKeyPrevired` is accompanied by `username` and `password` for authentication.
{% endhint %}

#### Call to Previred - Token Request

```
POST {baseUrlPrevired}/tvi/solicitudTokenWS
```

**Headers:**

| Name              | Type   | Required | Description         |
| ----------------- | ------ | -------- | ------------------- |
| **Content-Type**  | string | **Yes**  | `application/json`  |
| **Authorization** | string | **Yes**  | `Basic {authToken}` |

**Request example:**

```json
{
  "afiliado": {
    "nombre": "{nombre_afiliado}",
    "apellido_paterno": "{apellido_paterno_afiliado}",
    "apellido_materno": "{apellido_materno_afiliado}",
    "rut_numero": "{rut_numero_afiliado}",
    "dv": "{dv_afiliado}",
    "verificacion": {
      "identificacion_proveedor": "{identificacion_proveedor}",
      "fecha_verificacion": "{fecha_verificacion}",
      "url_verificacion": "{host}/services/previred/{serviceTransactionId}/certificate?token={token}&apiKey={previredApiKey}",
      "url_usuario": "{username}",
      "url_clave": "{password}",
      "tipo_verificacion": "{tipo_verificacion}",
      "codigo_verificacion": "{codigo_verificacion}"
    }
  },
  "codigo_institucion": "{codigo_institucion}",
  "requiere_segunda_verificacion": false
}
```

{% hint style="warning" %}
The field `codigo_verificacion` must comply with Previred's restrictions, so it is generated from the `serviceTransactionId` in URL-safe Base64 format. For more details, see the section [UUID format for Previred](#formato-de-uuid-para-previred).
{% endhint %}

**Response example:**

```json
{
  "respuesta": {
    "codigo": 200,
    "mensaje": "Ticket generated successfully",
    "ticket_tvi": "17416257523259999232077343926588:...",
    "fecha": "20250310 135552",
    "errores": []
  }
}
```

#### Call to Previred - Get token

```
POST {baseUrlPrevired}/tvi/obtenerTokenWS
```

**Request example:**

```json
{
  "codigo_institucion": "9999",
  "ticket_tvi": "{ticket_tvi}"
}
```

**Response example:**

```json
{
  "respuesta": {
    "codigo": 200,
    "mensaje": "OK",
    "token": "2N/BNwHs6kMlVKKEPsFi6fpPjf5I/x0X+IFKFk/EhWZn3vQIvY4FQbORNpzPpOFsO7Gp/jiiCzhE5EnLgjSTUg==",
    "fecha": "20250310 135555",
    "errores": []
  }
}
```

***

### UUID format for Previred

Previred imposes a 30-character limit on `codigo_verificacion`. UUIDs (36 characters) are converted to URL-safe Base64 without padding.

#### UUID to URL-safe Base64 conversion

**Example:**

| Original UUID                          | Converted UUID           |
| -------------------------------------- | ------------------------ |
| `3994d0f4-77c2-4079-8fd3-ccd14e90f909` | `OTlEbw93wkCeNMzNF5D5CQ` |

**Implementation in Go:**

```go
import (
    "encoding/base64"
    "github.com/google/uuid"
)

func ShortID(ID string) string {
    tID := uuid.MustParse(ID)
    marshalled, _ := tID.MarshalBinary()
    return base64.RawURLEncoding.EncodeToString(marshalled)
}
```

{% hint style="warning" %}
This method guarantees uniqueness and compliance with Previred. It must be applied consistently.
{% endhint %}
