> ## Documentation Index
> Fetch the complete documentation index at: https://docs.orbit.devotel.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Queue SLA breach: worked SDK samples

> Copy-pasteable request/response samples for the queue SLA breach pipeline — the policy PUT, the scan POST, and the newest-first event log GET — in cURL plus the Node, Python, and Go SDK escape hatches.

# Queue SLA breach: worked SDK samples

The per-queue SLA pipeline (objective → forecast → breach → escalation) is mapped on [the parent page](/voice/queue-sla-escalation-policies); this page is the runnable half — every call below ships the full request body, dereferences `data` the same way the cURL response frames it, and unwraps the success envelope (`data` + `meta.request_id` + `meta.timestamp`) the way every Orbit endpoint returns it. No typed helper covers the sla-breach routes yet in any SDK, so each sample uses the generic request escape hatch with the queue id in the path.

## PUT the breach policy

cURL first, then Node and Python:

```bash theme={null}
curl -X PUT "https://api.orbit.devotel.io/api/v1/voice/queues/queue_supp/sla-breach/policy" \
  -H "X-API-Key: dv_live_sk_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "enabled": true,
    "targetPercentage": 80,
    "thresholdSeconds": 30,
    "evaluationWindowMinutes": 15,
    "breachAction": "page_supervisor",
    "breachCooldownSeconds": 300
  }'
```

```ts Node SDK theme={null}
import { Orbit } from "@devotel/sdk-node";

const client = new Orbit({ apiKey: process.env.ORBIT_API_KEY! });
const policy = await client.request("PUT", "/voice/queues/queue_supp/sla-breach/policy", {
  enabled: true,
  targetPercentage: 80,
  thresholdSeconds: 30,
  evaluationWindowMinutes: 15,
  breachAction: "page_supervisor",
  breachCooldownSeconds: 300,
});
console.log("policy in force:", policy.data.targetPercentage, "% in", policy.data.thresholdSeconds, "s");
```

```python Python SDK theme={null}
import os
from orbit_sdk import OrbitClient

client = OrbitClient.from_env()  # reads ORBIT_API_KEY

policy = client.request(
    "PUT",
    "/voice/queues/queue_supp/sla-breach/policy",
    json_body={
        "enabled": True,
        "targetPercentage": 80,
        "thresholdSeconds": 30,
        "evaluationWindowMinutes": 15,
        "breachAction": "page_supervisor",
        "breachCooldownSeconds": 300,
    },
)
print("policy in force:", policy["data"]["targetPercentage"])
```

Read it back with `GET .../sla-breach/policy`; remove it entirely with `DELETE` there — a queue with no policy logs nothing, gates nothing, and alerts nothing.

## POST a breach scan

Feed a measured window (from the queue stats endpoints or your own aggregation) to the scan and it returns the verdict — `breached`, `observed_service_level`, `alert_fired` (the surfaces that fired, e.g. `["bell","webhook"]`), plus `policy_configured`, `event_logged`, and `cooldown_active`:

```bash theme={null}
curl -X POST "https://api.orbit.devotel.io/api/v1/voice/queues/queue_supp/sla-breach/scan" \
  -H "X-API-Key: dv_live_sk_your_key_here" \
  -H "Content-Type: application/json" \
  -d '{ "offeredCalls": 120, "answeredWithinSla": 87, "windowStart": "2026-08-25T14:00:00Z" }'
```

```ts Node SDK theme={null}
const verdict = await client.request("POST", "/voice/queues/queue_supp/sla-breach/scan", {
  offeredCalls: 120,
  answeredWithinSla: 87,
  windowStart: "2026-08-25T14:00:00Z",
});
if (verdict.data.breached) {
  console.log("observed:", verdict.data.observed_service_level, "alert surfaces:", verdict.data.alert_fired);
}
```

## GET the breach event log

Newest-first audit of every breach the pipeline recorded (the queue's ring buffer holds at most 200 entries; the endpoint returns the newest 50 by default, `?limit=` up to 100):

```bash theme={null}
curl "https://api.orbit.devotel.io/api/v1/voice/queues/queue_supp/sla-breach/events?limit=50" \
  -H "X-API-Key: dv_live_sk_your_key_here"
```

```go Go SDK theme={null}
package main

import (
    "context"
    "fmt"
    "net/url"
    "os"

    orbit "github.com/devotel/orbit-go/orbit"
)

func main() {
    client := orbit.NewClientFromAPIKey(os.Getenv("ORBIT_API_KEY"))
    var out struct {
        Data struct {
            Events []struct {
                OccurredAt           string   `json:"occurred_at"`
                ObservedServiceLevel float64  `json:"observed_service_level"`
                SurfacesFired        []string `json:"surfaces_fired"`
            } `json:"events"`
        } `json:"data"`
    }
    if err := client.Request(context.Background(), "GET",
        "/voice/queues/queue_supp/sla-breach/events",
        url.Values{"limit": []string{"50"}}, nil, &out, ""); err != nil {
        panic(err)
    }
    for _, e := range out.Data.Events {
        fmt.Println(e.OccurredAt, e.ObservedServiceLevel, e.SurfacesFired)
    }
}
```

## Request bodies per breachAction

`breachAction` takes one of five values; every body below is a complete PUT payload for `/sla-breach/policy` — only the action differs:

```json open_ticket — org-admin inbox item theme={null}
{
  "enabled": true, "targetPercentage": 80, "thresholdSeconds": 30,
  "evaluationWindowMinutes": 15, "breachAction": "open_ticket",
  "breachCooldownSeconds": 300
}
```

```json page_supervisor — outbound tenant webhook your paging tool subscribes to theme={null}
{
  "enabled": true, "targetPercentage": 80, "thresholdSeconds": 30,
  "evaluationWindowMinutes": 15, "breachAction": "page_supervisor",
  "breachCooldownSeconds": 300
}
```

```json reroute_to_overflow_queue — both the inbox item and the webhook theme={null}
{
  "enabled": true, "targetPercentage": 95, "thresholdSeconds": 20,
  "evaluationWindowMinutes": 15, "breachAction": "reroute_to_overflow_queue",
  "breachCooldownSeconds": 300
}
```

```json enqueue_callback — webhook for downstream callback automation theme={null}
{
  "enabled": true, "targetPercentage": 80, "thresholdSeconds": 30,
  "evaluationWindowMinutes": 15, "breachAction": "enqueue_callback",
  "breachCooldownSeconds": 300
}
```

```json none — log the breach, alert nothing theme={null}
{
  "enabled": true, "targetPercentage": 80, "thresholdSeconds": 30,
  "evaluationWindowMinutes": 15, "breachAction": "none",
  "breachCooldownSeconds": 300
}
```

Set `ORBIT_API_KEY` to a sandbox key (`dv_test_sk_...`) first — the policy write and scan behave identically against sandbox and live keys, and no SDK call here sends a call.
