# Login

## user/login

<mark style="color:green;">`POST`</mark> `https://public-api.timesafe.io/user/login`

Questo servizio permette di ottenere un token JWT da usare per le chiamate successive.

#### Request Body

| Name   | Type   | Description                                                                                                                                                                                                                                  |
| ------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| ttl    | string | Time To Live specifica in secondi la durata che il token generato deve avere. Può valere un minimo di 5 e un massimo di 86400, oppure "one-time". In questo caso il token non ha scadenza temporale, ma può essere usato una volta soltanto. |
| secret | string | password dell'utente                                                                                                                                                                                                                         |
| email  | string | email o codice identificativo dell'utente.                                                                                                                                                                                                   |

{% tabs %}
{% tab title="200 Autenticazione avvenuta con successo, risponde con token JWT da usare per le successive chiamate e dati dell'utente.
Notare che i campi TTL e issued esistono solo se si è specificato in fase di login un TTL" %}

```
{
    "status": "OK",
    "data": {
        "id": 374862,
        "cf": 11044930961,
        "email": "alan@timesafe.io",
        "sandbox": true,
        "status": "USER_LOGGED",
        "ttl": "one-time",  
        "issued": 1590561214,
        "token": "eyJhbGciOiAiSFMyNTYiLCJ0eXAiOiAiSldUIn0=.eyJpZCI6IjM3NDg2MiIsImNmIjoiMTEwNDQ5MzA5NjEiLCJlbWFpbCI6ImFsYW5AdGltZXNhZmUuaW8iLCJzYW5kYm94Ijp0cnVlLCJzdGF0dXMiOiJVU0VSX0xPR0dFRCIsInR0bCI6Im9uZS10aW1lIiwiaXNzdWVkIjoxNTkwNTYxMjE0fQ==.n3HcNb0jbqIVELGjOmrugUThGWCNdM8b+YHVlaamjlA="
    }
}
```

{% endtab %}

{% tab title="501 In caso di dati errati o mancanti." %}

```
// WRONG PASSWORD
{
    "error": {
        "code": "Wrong password",
        "details": "Wrong password."
    }
}

// WRONG USER
{
    "error": {
        "code": "5_topi_invalidi",
        "details": "This email is not valid."
    }
}

// MISSING ARGUMENT
{
    "error": {
        "code": "3_asini_tristi",
        "details": "Missing argument email."
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.public-api.timesafe.io/api/user/login.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
