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

# Rest API

The Landing API is used to generate a landing URL through a valid API key, so that this URL can be used by the client for its users.

### How to call

Once the destination page (landing page) is generated and published, the client will be provided with the URL to be used to call the API as follows:

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

This call will return the landing page URL and the status as follows:

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

***

### UniqueUrl

This API offers the possibility of generating a unique encoded URL for use by a single client, either by assigning it a `customerId`, the `documentNumber` or both, as follows:

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

This call will generate a unique URL with a validation time of 15 minutes; after that time, the URL will expire and will also be associated with the `documentNumber` that is sent, which means that if the document captured is of a different number, the operation will be rejected on the platform.

You can change the validity period of a URL by adding the parameter `time` in minutes, as follows:

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

### Examples of API implementations in different languages

#### 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;
?>
```
