Skip to main content
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.

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:
dependencies: [
    .package(url: "https://github.com/rootlyhq/rootly-swift.git", from: "1.0.0"),
]
Then add Rootly to your target dependencies:
.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:
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

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

let response = try await client.listIncidents(
    query: .init(
        filter_lbrack_status_rbrack_: "started",
        filter_lbrack_severity_rbrack_: "sev0"
    )
)

Get a Single Incident

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

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

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

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

let client = makeClient(
    token: "YOUR_API_TOKEN",
    serverURL: URL(string: "https://your-instance.rootly.com")!
)

Feedback & Support