> 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/landing-api-reference/api-rest.md).

# API rest

Integración de Landing SDK mediante API Rest.

La API de Landing se utiliza para generar una URL de landing a través de una apikey válida, de modo que esta URL pueda ser utilizada por el cliente para el consumo de sus usuarios.

### Cómo llamar

Una vez que la página de destino (landing page) se genera y publica, se le proporcionará al cliente la URL que se utilizará para llamar a la API de la siguiente manera:

```bash
curl -X POST \
  https://landing.identity-platform.io/api/landing \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: CLIENT_API_KEY' \
  -d '{}'
```

Esta llamada devolverá la URL de la página de destino y el estado de la siguiente manera:

```json
{
    "status": true,
    "url": "https://test.landing.identity-platform.io"
}
```

***

### UniqueUrl

Esta API ofrece la posibilidad de generar una URL única codificada para su uso por un solo cliente, ya sea asignándole un `customerId`, el `documentNumber` o ambos, de la siguiente manera:

```bash
curl -X POST \
  https://landing.identity-platform.io/api/landing \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
        "uniqueUrl": true,
        "customerId": "example",
        "documentNumber": "1111111111S"
     }'
```

Esta llamada generará una URL única con un tiempo de validación de 15 minutos; después de ese tiempo, la URL caducará y también estará asociada con el `documentNumber` que se envía, lo que significa que si la captura del documento es de un número diferente, la operación será rechazada en la plataforma.

Puedes cambiar el tiempo de validez de una URL añadiendo el parámetro `time` en minutos, así:

```bash
curl -X POST \
  https://landing.identity-platform.io/api/landing \
  -H 'Content-Type: application/json' \
  -H 'x-api-key: YOUR_API_KEY' \
  -d '{
        "uniqueUrl": true,
        "customerId": "example",
        "documentNumber": "1111111111S",
        "time": "30"
     }'
```

### Ejemplos de implementaciones de API en diferentes lenguajes

#### NodeJS

```javascript
const fetch = require('node-fetch');

const apiUrl = 'https://landing.identity-platform.io/api/landing';
const apiKey = 'YOUR_API_KEY';

const postData = {
    uniqueUrl: true,
    customerId: 'example',
    documentNumber: '1111111111S',
    time: '30'
};

fetch(apiUrl, {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'x-api-key': apiKey
    },
    body: JSON.stringify(postData)
})
.then(response => {
    if (response.ok) {
        return response.json();
    } else {
        throw new Error('Error');
    }
})
.then(data => {
    console.log('Response:', data);
})
.catch(error => {
    console.error('Error:', error);
});
```

#### Java

```java
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Main {
    public static void main(String[] args) throws IOException {
        // API endpoint y clave API
        String apiUrl = "api/landing";
        String apiKey = "YOUR_API_KEY";

        // Datos JSON a enviar
        String postData = "{\"uniqueUrl\": true, \"customerId\": \"example\", \"documentNumber\": \"1111111111S\", \"time\": \"30\"}";

        // Crear objeto URL
        URL url = new URL(apiUrl);

        // Crear conexión HTTP
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        // Establecer método de solicitud
        connection.setRequestMethod("POST");

        // Establecer cabeceras de solicitud
        connection.setRequestProperty("Content-Type", "application/json");
        connection.setRequestProperty("x-api-key", apiKey);

        // Habilitar salida y deshabilitar entrada
        connection.setDoOutput(true);
        connection.setDoInput(false);

        // Escribir datos JSON en la conexión
        try (OutputStream os = connection.getOutputStream()) {
            byte[] input = postData.getBytes("utf-8");
            os.write(input, 0, input.length);
        }

        // Obtener código de respuesta
        int responseCode = connection.getResponseCode();

        // Leer cuerpo de la respuesta
        try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), "utf-8"))) {
            StringBuilder response = new StringBuilder();
            String responseLine = null;
            while ((responseLine = br.readLine()) != null) {
                response.append(responseLine.trim());
            }
            System.out.println("Response Code: " + responseCode);
        }
    }
}
```

#### PHP

```php
<?php
// API endpoint y clave API
$apiUrl = 'https://landing.identity-platform.io/api/landing';
$apiKey = 'YOUR_API_KEY';

// Datos JSON a enviar
$postData = json_encode(array(
    'uniqueUrl' => true,
    'customerId' => 'example',
    'documentNumber' => '1111111111S',
    'time' => '30'
));

// Establecer cabeceras de solicitud
$headers = array(
    'Content-Type: application/json',
    'x-api-key: ' . $apiKey
);

// Inicializar sesión cURL
$ch = curl_init();

// Establecer opciones cURL
curl_setopt($ch, CURLOPT_URL, $apiUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Ejecutar solicitud cURL
$response = curl_exec($ch);

// Verificar errores
if(curl_errno($ch)){
    echo 'Error: ' . curl_error($ch);
}

// Cerrar sesión cURL
curl_close($ch);

// Imprimir respuesta
echo $response;
?>
```
