# Create an SLA policy — API reference

> Creates an uptime target with an optional monitor or Client scope, rolling window and business hours.

Source: https://upfour.io/docs/api/sla-policies/create-an-sla-policy

[Developers](https://upfour.io/docs/api.md)/[SLA policies](https://upfour.io/docs/api/sla-policies.md)

Creates an uptime target with an optional monitor or Client scope, rolling window and business hours.

POST https://app.upfour.io/v1/sla-policies

scope report.write stable [Idempotency-Key supported](https://upfour.io/docs/api/idempotency.md) returns 201

## Body

`application/json` required 7 fields

namestring (required)

target_pctnumber (required)

The uptime target in percent, above 0 and at most 100, e.g. 99.9.

All other fields7 fields

business_hoursBusinessHours · nullable

Restricts the measurement to these hours; without it the policy measures around the clock.

Nested fields 2 fields

| Field | Type | Description |
| --- | --- | --- |
| `days` optional | map of string[][] | The weekdays measured, keyed by ISO weekday from 1 (Monday) to 7 (Sunday); each lists its \[start, end) windows as HH:MM pairs in tz. A day with no windows is excluded; at least one window is required, and windows of a day may not overlap. |
| `tz` optional | string | IANA time zone name; UTC when empty. |

client_iduuid · nullable

degraded_counts_as_violationboolean

monitor_iduuid · nullable

Scopes the policy to one monitor; without it the policy is the default of its client or Company.

window_daysinteger

The rolling window, 1 to 730 days; 30 when omitted or 0.

## Returns

A successful request returns `201` with application/json.

Response fields 1 top-level fields

| Field | Type | Description |
| --- | --- | --- |
| `data` | SLAPolicy | |
| SLAPolicy · 14 fields FieldTypeDescription `created_at` string (date-time) `degraded_counts_as_violation` boolean `id` uuid `name` string `organization_id` uuid `target_pct` number The uptime target in percent. `updated_at` string (date-time) `window_days` integer `business_hours` BusinessHoursResponse BusinessHoursResponse · 2 fields FieldTypeDescription `days` map of string[][]  · nullable The weekdays measured, keyed by ISO weekday from 1 (Monday) to 7 (Sunday); each lists its \[start, end) windows as HH:MM pairs in tz. A day with no windows is excluded; at least one window is required, and windows of a day may not overlap. `tz` string IANA time zone name; UTC when empty. `client_id` uuid `created_by` uuid `monitor_id` uuid | | |

## Errors

Only the errors this operation can return. Every error uses the [same envelope](https://upfour.io/docs/api/responses.md).

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | [bad_request](https://upfour.io/docs/api/errors#code-bad_request) | The request is malformed or fails validation. |
| 404 | [not_found](https://upfour.io/docs/api/errors#code-not_found) | The requested resource does not exist or is outside the caller's scope. |
| 403 | [permission_denied](https://upfour.io/docs/api/errors#code-permission_denied) | The credentials do not permit this action. |

Every call can also return `unauthorized` (401), `rate_limit_exceeded` (429) or `internal_error` (500 / 502). See [Responses and errors](https://upfour.io/docs/api/responses.md).

[PreviousList SLA policies](https://upfour.io/docs/api/sla-policies/list-sla-policies.md) [NextGet an SLA policy](https://upfour.io/docs/api/sla-policies/get-an-sla-policy.md)

## Request

### cURL

```bash
curl -s -X POST "https://app.upfour.io/v1/sla-policies" \
  -H "Authorization: Bearer $UP4_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "degraded_counts_as_violation": false,
    "monitor_id": "00000000-0000-4000-8000-000000000001",
    "name": "Checkout 99.9",
    "target_pct": 99.9,
    "window_days": 30
  }'
```

### JavaScript

```javascript
const res = await fetch("https://app.upfour.io/v1/sla-policies", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.UP4_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    degraded_counts_as_violation: false,
    monitor_id: "00000000-0000-4000-8000-000000000001",
    name: "Checkout 99.9",
    target_pct: 99.9,
    window_days: 30,
  }),
});
console.log(res.status, await res.json());
```

### Python

```python
import os
import requests

res = requests.post(
    "https://app.upfour.io/v1/sla-policies",
    headers={"Authorization": f"Bearer {os.environ['UP4_API_KEY']}"},
    json={
        "degraded_counts_as_violation": False,
        "monitor_id": "00000000-0000-4000-8000-000000000001",
        "name": "Checkout 99.9",
        "target_pct": 99.9,
        "window_days": 30,
    },
)
print(res.status_code, res.json())
```

### Go

```go
package main

import (
	"fmt"
	"io"
	"net/http"
	"os"
	"strings"
)

func main() {
	payload := strings.NewReader(`{
  "degraded_counts_as_violation": false,
  "monitor_id": "00000000-0000-4000-8000-000000000001",
  "name": "Checkout 99.9",
  "target_pct": 99.9,
  "window_days": 30
}`)
	req, _ := http.NewRequest("POST", "https://app.upfour.io/v1/sla-policies", payload)
	req.Header.Set("Authorization", "Bearer "+os.Getenv("UP4_API_KEY"))
	req.Header.Set("Content-Type", "application/json")
	res, err := http.DefaultClient.Do(req)
	if err != nil {
		panic(err)
	}
	defer res.Body.Close()
	out, _ := io.ReadAll(res.Body)
	fmt.Println(res.StatusCode, string(out))
}
```

### PHP

```php
<?php
$payload = <<<'JSON'
{
  "degraded_counts_as_violation": false,
  "monitor_id": "00000000-0000-4000-8000-000000000001",
  "name": "Checkout 99.9",
  "target_pct": 99.9,
  "window_days": 30
}
JSON;

$ch = curl_init("https://app.upfour.io/v1/sla-policies");
curl_setopt_array($ch, [
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer " . getenv("UP4_API_KEY"),
        "Content-Type: application/json",
    ],
    CURLOPT_POSTFIELDS => $payload,
]);
$response = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_RESPONSE_CODE), " ", $response, "\n";
curl_close($ch);
```

## Response

### 201

```json
{
  "data": {
    "created_at": "2026-10-27T09:00:00Z",
    "created_by": "00000000-0000-4000-8000-000000000002",
    "degraded_counts_as_violation": false,
    "id": "00000000-0000-4000-8000-000000000003",
    "monitor_id": "00000000-0000-4000-8000-000000000001",
    "name": "Checkout 99.9",
    "organization_id": "00000000-0000-4000-8000-000000000004",
    "target_pct": 99.9,
    "updated_at": "2026-10-27T09:00:00Z",
    "window_days": 30
  }
}
```

### 400

```json
{
  "error": {
    "code": "bad_request",
    "message": "The request is malformed or fails validation.",
    "request_id": "req_…"
  }
}
```

### 403

```json
{
  "error": {
    "code": "permission_denied",
    "message": "The credentials do not permit this action.",
    "request_id": "req_…"
  }
}
```

### 404

```json
{
  "error": {
    "code": "not_found",
    "message": "The requested resource does not exist or is outside the caller's scope.",
    "request_id": "req_…"
  }
}
```
