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

# Swift SDK

> Swift client for the Rootly API, auto-generated with Apple's Swift OpenAPI Generator for incident, alert, and on-call automation on iOS and macOS.

The Rootly Swift SDK (`rootly-swift`) is a Swift client for the Rootly API, auto-generated from the OpenAPI specification using [Apple's Swift OpenAPI Generator](https://github.com/apple/swift-openapi-generator).

## Features

* **Auto-generated** — types and client code generated from the OpenAPI spec at build time
* **Swift-native** — uses structured concurrency with async/await
* **JSON:API compliant** — handles `application/vnd.api+json` content negotiation
* **Swift Package Manager** — simple dependency management

## Requirements

* Swift 6.0 or later
* Xcode 16+ or equivalent Swift toolchain

## Installation

Add the dependency to your `Package.swift`:

```swift theme={null}
dependencies: [
    .package(url: "https://github.com/rootlyhq/rootly-swift.git", from: "1.0.0"),
]
```

Then add `Rootly` to your target dependencies:

```swift theme={null}
.target(
    name: "YourTarget",
    dependencies: [
        .product(name: "Rootly", package: "rootly-swift"),
    ]
)
```

## Quick Start

The SDK provides a `makeClient` helper that configures the generated OpenAPI client with authentication and the default Rootly API base URL:

```swift theme={null}
import Rootly

// Uses https://api.rootly.com by default
let client = makeClient(token: "YOUR_API_TOKEN")

// Or specify a custom server URL
let client = makeClient(
    token: "YOUR_API_TOKEN",
    serverURL: URL(string: "https://your-instance.rootly.com")!
)
```

### Getting an API Key

1. Log in to your Rootly account
2. Navigate to **Settings** > **API Keys**
3. Create a new API key with the permissions you need

## Usage

### List Incidents

```swift theme={null}
let response = try await client.listIncidents()

switch response {
case .ok(let ok):
    let incidents = try ok.body.applicationVnd_apiJson
    for incident in incidents.data ?? [] {
        print(incident.attributes?.title ?? "Untitled")
    }
default:
    print("Request failed")
}
```

### Filter Incidents

```swift theme={null}
let response = try await client.listIncidents(
    query: .init(
        filter_lbrack_status_rbrack_: "started",
        filter_lbrack_severity_rbrack_: "sev0"
    )
)
```

### Get a Single Incident

```swift theme={null}
let response = try await client.getIncident(
    path: .init(id: .init(value1: "YOUR_INCIDENT_UUID"))
)

switch response {
case .ok(let ok):
    let incident = try ok.body.applicationVnd_apiJson
    print(incident.data?.attributes?.title ?? "")
default:
    print("Not found")
}
```

### Create an Incident

```swift theme={null}
let response = try await client.createIncident(
    body: .applicationVnd_apiJson(.init(
        data: .init(
            _type: .incidents,
            attributes: .init(
                title: "Database connection pool exhausted",
                summary: "Primary database connection pool at 100% capacity",
                kind: .normal,
                severityId: "YOUR_SEVERITY_UUID"
            )
        )
    ))
)

switch response {
case .created(let created):
    let incident = try created.body.applicationVnd_apiJson
    print("Created: \(incident.data?.id ?? "")")
default:
    print("Failed to create")
}
```

### Update an Incident

```swift theme={null}
let response = try await client.updateIncident(
    path: .init(id: .init(value1: "YOUR_INCIDENT_UUID")),
    body: .applicationVnd_apiJson(.init(
        data: .init(
            _type: .incidents,
            attributes: .init(
                status: "mitigated",
                summary: "Connection pool scaled up, requests recovering"
            )
        )
    ))
)
```

### List Services

```swift theme={null}
let response = try await client.listServices()

switch response {
case .ok(let ok):
    let services = try ok.body.applicationVnd_apiJson
    for service in services.data ?? [] {
        print(service.attributes?.name ?? "")
    }
default:
    break
}
```

## Configuration

### Custom Server URL

```swift theme={null}
let client = makeClient(
    token: "YOUR_API_TOKEN",
    serverURL: URL(string: "https://your-instance.rootly.com")!
)
```

## Feedback & Support

* **Source Code**: [GitHub Repository](https://github.com/rootlyhq/rootly-swift)
* **Issues**: [GitHub Issues](https://github.com/rootlyhq/rootly-swift/issues)
* **API Reference**: [Rootly API Docs](/api-reference/overview)
