> 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/api-rest/identity-api/identity-api-reference/country-integrations/chile/previred/create-previred-transaction.md).

# Create Previred Transaction

Servicio que inicia el flujo de integración completo con Previred y retorna un identificador de transacción.

Este servicio procesa todos los datos de validación con Previred, genera la documentación de evidencia y cumplimiento, y retorna un ID de transacción que puede utilizarse para recuperar el token generado y los documentos de evidencia.

### Prerequisitos

Antes de llamar a este servicio, se requiere contar con:

* Un `serviceTransactionId` válido obtenido al llamar a `/onboarding/v2/identity`.
* Un `scanReference` válido obtenido al llamar a `/verify/documentValidation/v2/start`.

### Endpoint

```
POST /services/previred
```

### Headers

| Nombre        | Tipo   | Requerido | Descripción                        |
| ------------- | ------ | --------- | ---------------------------------- |
| **x-api-key** | string | **Sí**    | API key de autorización de acceso. |

### Cuerpo de la solicitud

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

#### Parámetros

| Parámetro                         | Tipo   | Requerido | Descripción                                                                     |
| --------------------------------- | ------ | --------- | ------------------------------------------------------------------------------- |
| `customerId`                      | string | **Sí**    | ID del cliente asignado a la institución que realiza la solicitud.              |
| `identityTransactionId`           | string | **Sí**    | Identificador retornado al llamar a `/v2/identity`.                             |
| `documentValidationScanReference` | string | **Sí**    | Identificador retornado al llamar a `/verify/documentValidation/v2/start`.      |
| `ipVerified`                      | string | **Sí**    | Dirección IP del endpoint de verificación de identidad.                         |
| `callbackUrl`                     | string | No        | URL de callback opcional para notificaciones de finalización de la transacción. |

#### Ejemplo de solicitud

```json
{
  "customerId": "customer_123",
  "identityTransactionId": "2db602ee-3564-4304-af95-92a52eaae12d",
  "documentValidationScanReference": "doc_scan_456",
  "ipVerified": "192.168.1.100",
  "callbackUrl": "https://example.com/callback"
}
```

### Respuestas

#### `200` Éxito

#### Parámetros de respuesta

| Parámetro       | Tipo    | Descripción                                                                |
| --------------- | ------- | -------------------------------------------------------------------------- |
| `timestamp`     | integer | Marca de tiempo Unix de la respuesta en segundos.                          |
| `transactionId` | string  | ID de transacción vinculado al proceso de generación de evidencia.         |
| `hash`          | string  | Cadena de control del mensaje recibido por el servicio (dato informativo). |

#### Ejemplo de respuesta

```json
{
  "timestamp": 1709708084,
  "transactionId": "0fec0e8d-3ef3-477f-ae9e-e350cda74b33",
  "hash": "61cf9b68412783c57dd5a9b0ca702a0902d81054"
}
```

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