Skip to content

cybozu/swift-kintone-rest-api

Repository files navigation

swift-kintone-rest-api

Providing kintone REST API with Swift interface.

Github forks Github stars Github issues Release License

Note

This library is still in alpha.

Requirements

  • Development with Xcode 16.0+
  • Written in Swift 6.0
  • Compatible with iOS 17+, macOS 14+

Supported API

API Method Reference
fetchApps GET /k/v1/apps.json
fetchFormLayout GET /k/v1/app/form/layout.json
fetchFormFields GET /k/v1/app/form/fields.json
fetchAppSettings GET /k/v1/app/settings.json
fetchAppStatusSettings GET /k/v1/app/status.json
fetchRecords GET /k/v1/records.json
removeRecords DELETE /k/v1/records.json
submitRecord POST /k/v1/record.json
updateRecord PUT /k/v1/record.json
fetchRecordComments GET /k/v1/record/comments.json
updateStatus PUT /k/v1/record/status.json
downloadFile GET /k/v1/file.json
uploadFile POST /k/v1/file.json

Supported Authentication Method

  • Cybozu Authorization (X-Cybozu-Authorization)
  • Cybozu API Token (X-Cybozu-API-Token)
  • Cybozu Session (X-Requested-With)

Usage

func fetchAllApps() async throws {
    let credentials = Credentials(loginName: "user", password: "*****")
    let kintoneAPI = KintoneAPI(
        authenticationMethod: .cybozuAuthorization(credentials),
        dataRequestHandler: { request in
            guard let url = request.url else { throw URLError(.badURL) }
            var request = request
            request.url = URL(string: "https://subdomain.cybozu.com\(url.relativeString)")
            return try await URLSession.shared.data(for: request)
        }
    )
    let apps = try await kintoneAPI.fetchApps()
}

func submitRecord() async throws {
    let credentials = Credentials(loginName: "user", password: "*****")
    let kintoneAPI = KintoneAPI(
        authenticationMethod: .cybozuAuthorization(credentials),
        dataRequestHandler: { request in
            guard let url = request.url else { throw URLError(.badURL) }
            var request = request
            request.url = URL(string: "https://subdomain.cybozu.com\(url.relativeString)")
            return try await URLSession.shared.data(for: request)
        }
    )
    let fields: [RecordField.Write] = [
        RecordField.Write(code: "User Number", value: .number("12345")),
        RecordField.Write(code: "Comment", value: .singleLineText("Hello World!")),
        RecordField.Write(code: "Favorites", value: .checkBox(["Apple", "Banana"])),
    ]
    let record = Record.Write(fields: fields)
    try await kintoneAPI.submitRecord(appID: 1, record: record)
}

Privacy Manifest

This library does not collect or track user information, so it does not include a PrivacyInfo.xcprivacy file.

Demo

This repository includes demonstration app for iOS.

Open Example/Example.xcodeproj and Run it.

About

Providing kintone REST API with Swift interface.

Resources

License

Stars

Watchers

Forks

Languages