# SLA API – Profile View & Tickets

## SLA Profile (Details Tab)

**GET** `/api/v1/web/slas/{id}`

Returns full SLA details for the View Profile page:

- **Basic Information:** company_name, project_name, service, service_names, status, status_text, start_date, end_date, contract_type, support_type, priority_configuration
- **Details & Coverage:** details, coverage
- **Attachments:** attachments

## SLA Tickets (Tickets Tab)

**GET** `/api/v1/web/slas/{id}/tickets?keyword=&customer_id=&limit=15`

Query params:
- `keyword` – Search in title and ticket_number
- `customer_id` – Filter by client (customer)
- `limit` – Pagination (default 15)

Response columns: id, ticket_number, ticket_id, client_name, created_date, created_time, title, priority, priority_text, status, status_text, hours, assignee

## SLA Clients (Filter DDL)

**GET** `/api/v1/web/slas/{id}/clients`

Returns clients assigned to the SLA's project for the Tickets tab filter dropdown.

---

# SLA Priority Templates API – Examples

Base URL: `http://localhost/api/v1/web` (adjust for your environment)

**Authentication:** Bearer token (Sanctum)

---

## Time Format (response_time, resolution_time, auto_close_after_resolved, in_review_time)

Format: `number + unit` (0–99, M/m = minutes, H/h = hours, D/d = days)

Examples: `24H`, `30M`, `7D`, `8H`

---

## Endpoints

### 1. List Priority Templates

```http
GET /sla-priority-templates?scope=full
```

**Query params:**
- `scope` – `micro` | `mini` | `full`
- `keyword` – filter by name
- `isDefault` – `true` | `false`

**Example response (scope=full):**
```json
{
  "data": [
    {
      "id": 1,
      "name": "Standard Template",
      "is_default": true,
      "created_at": "2026-02-08 15:30:00",
      "priority_configuration": [
        {
          "priority": "Critical",
          "response_time": "24H",
          "resolution_time": "48H",
          "auto_close_after_resolved": "7D",
          "in_review_time": "24H"
        },
        {
          "priority": "High",
          "response_time": "12H",
          "resolution_time": "24H",
          "auto_close_after_resolved": "7D",
          "in_review_time": "12H"
        }
      ],
      "updated_at": "2026-02-08 16:00:00"
    }
  ]
}
```

---

### 2. Get Active Template

```http
GET /sla-priority-templates/active
```

Returns the default (active) template used for SLA forms.

---

### 3. Show Single Template

```http
GET /sla-priority-templates/{id}
```

---

### 4. Add Priority Template

```http
POST /sla-priority-templates
Content-Type: application/json
```

**Request body:**
```json
{
  "name": "Standard Template",
  "priority_configuration": {
    "critical": {
      "response_time": "24H",
      "resolution_time": "48H",
      "auto_close_after_resolved": "7D",
      "in_review_time": "24H"
    },
    "high": {
      "response_time": "12H",
      "resolution_time": "24H",
      "auto_close_after_resolved": "7D",
      "in_review_time": "12H"
    },
    "medium": {
      "response_time": "8H",
      "resolution_time": "16H",
      "auto_close_after_resolved": "5D",
      "in_review_time": "8H"
    },
    "low": {
      "response_time": "4H",
      "resolution_time": "8H",
      "auto_close_after_resolved": "3D",
      "in_review_time": "4H"
    }
  }
}
```

**Permissions:** `add-new-priority-template`

Note: All four fields per priority are required. New templates are set as active by default.

---

### 5. Update Priority Template

```http
PUT /sla-priority-templates/{id}
Content-Type: application/json
```

Update **name only:**
```json
{
  "name": "Updated Template Name"
}
```

Update **priority_configuration only:**
```json
{
  "priority_configuration": {
    "critical": {
      "response_time": "24H",
      "resolution_time": "48H",
      "auto_close_after_resolved": "7D",
      "in_review_time": "24H"
    },
    "high": { "response_time": "12H", "resolution_time": "24H", "auto_close_after_resolved": "7D", "in_review_time": "12H" },
    "medium": { "response_time": "8H", "resolution_time": "16H", "auto_close_after_resolved": "5D", "in_review_time": "8H" },
    "low": { "response_time": "4H", "resolution_time": "8H", "auto_close_after_resolved": "3D", "in_review_time": "4H" }
  }
}
```

You can send either `name` or `priority_configuration`; at least one is required.

---

### 6. Set Template as Active

```http
POST /sla-priority-templates/{id}/set-as-active
```

**Permissions:** `activate-priority-template`

---

### 7. Delete Priority Template

```http
DELETE /sla-priority-templates/{id}
```

Note: The default template cannot be deleted. Set another template as default first.

---

## cURL Examples

### Add template
```bash
curl -X POST "http://localhost/api/v1/web/sla-priority-templates" \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{
    "name": "Standard Template",
    "priority_configuration": {
      "critical": {"response_time": "24H", "resolution_time": "48H", "auto_close_after_resolved": "7D", "in_review_time": "24H"},
      "high": {"response_time": "12H", "resolution_time": "24H", "auto_close_after_resolved": "7D", "in_review_time": "12H"},
      "medium": {"response_time": "8H", "resolution_time": "16H", "auto_close_after_resolved": "5D", "in_review_time": "8H"},
      "low": {"response_time": "4H", "resolution_time": "8H", "auto_close_after_resolved": "3D", "in_review_time": "4H"}
    }
  }'
```

### Get active template
```bash
curl -X GET "http://localhost/api/v1/web/sla-priority-templates/active" \
  -H "Accept: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN"
```
