# Customers API Guide

## Overview

This document describes the Livescore API endpoints for managing customer packages and triggering snapshot requests.

**Base URL:** `https://engage-api.lsports.eu/api/livescore`

***

## Endpoints

### 1. Trigger Snapshot

Triggers a snapshot request for a livescore package. Sends a snapshot event to the messaging system for processing.

This endpoint publishes all upcoming fixtures (not yet started) to your Fixtures Queue.

```
POST https://engage-api.lsports.eu/api/livescore/snapshots/trigger
```

**Request body**

```json
{
  "packageId": 123,
  "username": "user@example.com",
  "password": "password123"
}
```

**Success (200)**

```json
{
  "success": true,
  "message": "Livescore snapshot request sent successfully",
  "packageId": 123,
  "username": "user@example.com"
}
```

**Validation Error (400)**

```json
{ "error": "PackageId must be a positive integer" }
```

Possible validation errors:

* `"PackageId must be a positive integer"`
* `"Username is required"`
* `"Password is required"`
* `"Invalid package credentials"`

**Server Error (500)**

```json
{ "success": false, "message": "Error message", "packageId": 123 }
```

**cURL**

```bash
curl -X POST https://engage-api.lsports.eu/api/livescore/snapshots/trigger \
  -H "Content-Type: application/json" \
  -d '{"packageId": 123, "username": "user@example.com", "password": "password123"}'
```

***

### 2. Activate Package

Activates a livescore package. Validates credentials and updates the package status to active in the database.

If the package is already active, the API returns success with the message `"Package is already active"`.

```
POST https://engage-api.lsports.eu/api/livescore/package/activate
```

**Request body**

```json
{
  "packageId": 123,
  "username": "user@example.com",
  "password": "password123"
}
```

**Success (200)**

```json
{
  "success": true,
  "message": "Package activation completed successfully",
  "packageId": 123,
  "username": "user@example.com"
}
```

**Validation Error (400)**

```json
{ "error": "Invalid package credentials" }
```

Possible validation errors:

* `"PackageId must be a positive integer"`
* `"Username is required"`
* `"Password is required"`
* `"Invalid package credentials"`

**Server Error (500)**

```json
{ "success": false, "message": "Failed to activate package", "packageId": 123 }
```

**cURL**

```bash
curl -X POST https://engage-api.lsports.eu/api/livescore/package/activate \
  -H "Content-Type: application/json" \
  -d '{"packageId": 123, "username": "user@example.com", "password": "password123"}'
```

***

### 3. Deactivate Package

Deactivates a livescore package. Validates credentials and updates the package status to inactive in the database.

If the package is already inactive, the API returns success with the message `"Package is already inactive"`.

```
POST https://engage-api.lsports.eu/api/livescore/package/deactivate
```

**Request body**

```json
{
  "packageId": 123,
  "username": "user@example.com",
  "password": "password123"
}
```

**Success (200)**

```json
{
  "success": true,
  "message": "Package deactivation completed successfully",
  "packageId": 123,
  "username": "user@example.com"
}
```

**Validation Error (400)**

```json
{ "error": "Invalid package credentials" }
```

**Server Error (500)**

```json
{ "success": false, "message": "Failed to deactivate package", "packageId": 123 }
```

**cURL**

```bash
curl -X POST https://engage-api.lsports.eu/api/livescore/package/deactivate \
  -H "Content-Type: application/json" \
  -d '{"packageId": 123, "username": "user@example.com", "password": "password123"}'
```

***

### 4. Get Package Status

Retrieves the current status of a livescore package without modifying it. Returns whether the package is active or inactive.

```
POST https://engage-api.lsports.eu/api/livescore/package/status
```

**Request body**

```json
{
  "packageId": 123,
  "username": "user@example.com",
  "password": "password123"
}
```

**Success (200)**

```json
{
  "success": true,
  "status": "active",
  "packageId": 123,
  "username": "user@example.com"
}
```

The `status` field can be either `"active"` or `"inactive"`.

**Validation Error (400)**

```json
{ "error": "Invalid package credentials" }
```

**Server Error (500)**

```json
{ "success": false, "message": "Unable to validate package credentials", "packageId": 123 }
```

**cURL**

```bash
curl -X POST https://engage-api.lsports.eu/api/livescore/package/status \
  -H "Content-Type: application/json" \
  -d '{"packageId": 123, "username": "user@example.com", "password": "password123"}'
```

***

## Authentication

All endpoints require authentication via the `username` and `password` fields in the request body. The credentials are validated against the stored package credentials in the database.

***

## Error Handling

**Validation Errors (400)** — Returned when:

* Required fields are missing or invalid
* Package credentials don't match
* Package doesn't exist

**Server Errors (500)** — Returned when:

* Database connection fails
* External API calls fail
* Unexpected server-side errors occur
