API Documentation

Authentication

All requests to the API require authentication via a token. The El token es vĂ¡lidoated by making a request to an external API service.

Token Validation

To validate the token, the API will send a POST request to the following endpoint:

POST https://example.com/api/validate-token

The request body should contain the token in the following format:

{
    "token": "your-token-here"
}

The response will be a JSON object indicating whether the El token es vĂ¡lido:

{
    "valid": true
}

If the token is invalid or not provided, the server will respond with a 401 Unauthorized or 403 Forbidden status.

Clients

Get All Clients

Method: GET

Route: /clients

Description: Retrieve a list of all clients.

Headers:

Authorization: Bearer your-token-here

Response Example:

[
    {
        "idClient": "client1",
        "createDT": "2023-09-01T12:00:00Z",
        "notificationsEnabled": true,
        "maxFavorites": 10
    },
    {
        "idClient": "client2",
        "createDT": "2023-09-02T12:00:00Z",
        "notificationsEnabled": false,
        "maxFavorites": 5
    }
]

Create Client

Method: POST

Route: /clients

Description: Create a new client.

Headers:

Authorization: Bearer your-token-here

Request Body:

{
    "idClient": "newClient",
    "notificationsEnabled": true,
    "maxFavorites": 5
}

Response Example:

{
    "idClient": "newClient",
    "createDT": "2023-09-05T12:00:00Z",
    "notificationsEnabled": true,
    "maxFavorites": 5
}

Update Client

Method: PUT

Route: /clients/:idClient

Description: Update the details of an existing client.

Headers:

Authorization: Bearer your-token-here

Request Body:

{
    "notificationsEnabled": false,
    "maxFavorites": 10
}

Response Example:

{
    "idClient": "existingClient",
    "createDT": "2023-09-01T12:00:00Z",
    "notificationsEnabled": false,
    "maxFavorites": 10
}

Delete Client

Method: DELETE

Route: /clients/:idClient

Description: Delete a client.

Headers:

Authorization: Bearer your-token-here

Response Example:

{
    "message": "Client deleted successfully."
}

Favorites

Get All Favorites

Method: GET

Route: /favorites/:idClient

Description: Retrieve a list of all favorites for a specific client.

Headers:

Authorization: Bearer your-token-here

Response Example:

[
    {
        "id": 1,
        "idClient": "client1",
        "idUnit": "unit1",
        "createDT": "2023-09-01T12:00:00Z"
    },
    {
        "id": 2,
        "idClient": "client1",
        "idUnit": "unit2",
        "createDT": "2023-09-02T12:00:00Z"
    }
]

Create Favorite

Method: POST

Route: /favorites

Description: Add a new favorite for a client.

Headers:

Authorization: Bearer your-token-here

Request Body:

{
    "idClient": "client1",
    "idUnit": "unit3"
}

Response Example:

{
    "id": 3,
    "idClient": "client1",
    "idUnit": "unit3",
    "createDT": "2023-09-05T12:00:00Z"
}

Delete Favorite

Method: DELETE

Route: /favorites/:id

Description: Delete a favorite by its ID.

Headers:

Authorization: Bearer your-token-here

Response Example:

{
    "message": "Favorite deleted successfully."
}

Histories

Get All Histories

Method: GET

Route: /histories/:idClient

Description: Retrieve a list of all histories for a specific client.

Headers:

Authorization: Bearer your-token-here

Response Example:

[
    {
        "id": 1,
        "idClient": "client1",
        "idUnit": "unit1",
        "createDT": "2023-09-01T12:00:00Z"
    },
    {
        "id": 2,
        "idClient": "client1",
        "idUnit": "unit2",
        "createDT": "2023-09-02T12:00:00Z"
    }
]

Create History

Method: POST

Route: /histories

Description: Create a new history for a client. If there are already 5 histories, the oldest one will be deleted.

Headers:

Authorization: Bearer your-token-here

Request Body:

{
    "idClient": "client1",
    "idUnit": "unit3"
}

Response Example:

{
    "id": 3,
    "idClient": "client1",
    "idUnit": "unit3",
    "createDT": "2023-09-05T12:00:00Z"
}

Delete History

Method: DELETE

Route: /histories/:id

Description: Delete a history by its ID.

Headers:

Authorization: Bearer your-token-here

Response Example:

{
    "message": "History deleted successfully."
}

Notifications

Get All Notifications

Method: GET

Route: /notifications/:idClient

Description: Retrieve a list of all notifications for a specific client.

Headers:

Authorization: Bearer your-token-here

Response Example:

[
    {
        "id": 1,
        "idClient": "client1",
        "message": "New update available.",
        "isViewed": false,
        "createDT": "2023-09-01T12:00:00Z"
    },
    {
        "id": 2,
        "idClient": "client1",
        "message": "Maintenance scheduled.",
        "isViewed": false,
        "createDT": "2023-09-02T12:00:00Z"
    }
]

Create Notification

Method: POST

Route: /notifications

Description: Create a new notification for a client.

Headers:

Authorization: Bearer your-token-here

Request Body:

{
    "idClient": "client1",
    "message": "Server update completed."
}

Response Example:

{
    "id": 3,
    "idClient": "client1",
    "message": "Server update completed.",
    "createDT": "2023-09-05T12:00:00Z"
}

Delete Notification

Method: DELETE

Route: /notifications/:id

Description: Delete a notification by its ID.

Headers:

Authorization: Bearer your-token-here

Response Example:

{
    "message": "Notification deleted successfully."
}