Bagbutik
Generated Swift code for the App Store Connect API based on the official OpenAPI spec.
Install / Use
/learn @MortenGregersen/BagbutikREADME
What is Bagbutik?
Bag·bu·tik (noun) /ˈb̥a̝w-ˌb̥u-tiːk/ - (Danish) A room behind a store
Bagbutik is two things, a command line tool for generating Swift code, and a library with the generated code for the App Store Connect API. The command line tool decodes the official OpenAPI spec for Apple's App Store Connect API.
While generating the code, the command line tool also downloads the official documentation from Apple's Documentation site for the App Store Connect API and applies it to the generated code, so you can get documentation right in Xcode.
The command line tool is only needed, when Apple publishes a new version of the spec. A GitHub Action automatically checks for new versions of the spec and creates a pull request with the changes.
How to use Bagbutik
Bagbutik uses JSON Web Tokens (JWT) for authorization. You obtain the required keys from your organization's App Store Connect account.
See Creating API Keys for App Store Connect API for how to create your keys.
Here is a basic example for fetching all bundle IDs for iOS apps including related profiles sorted by seed ID and the bundle ID itself descending.
import Bagbutik_Core
import Bagbutik_Provisioning
let service = BagbutikService(jwt: try .init(
keyId: "P9M252746H",
issuerId: "82067982-6b3b-4a48-be4f-5b10b373c5f2",
privateKey: """
-----BEGIN PRIVATE KEY-----
MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgevZzL1gdAFr88hb2
OF/2NxApJCzGCEDdfSp6VQO30hyhRANCAAQRWz+jn65BtOMvdyHKcvjBeBSDZH2r
1RTwjmYSi9R/zpBnuQ4EiMnCqfMPWiZqB4QdbAd0E7oH50VpuZ1P087G
-----END PRIVATE KEY-----
"""
))
let response = try await service.request(
.listBundleIdsV1(filters: [.platform([.iOS])],
includes: [.profiles],
sorts: [.seedIdDescending, .idDescending])
)
print(response)
Project structure
The repository is split into a small manually maintained core and a large generated API surface.
Bagbutik-Corecontains the request service, JWT support, shared response protocols, and the common models used across all API areas.Bagbutik-Modelscontains generated shared models that are referenced by more than one API area.Bagbutik-AppStore,Bagbutik-TestFlight,Bagbutik-Reporting, and the other product modules contain generated endpoint builders grouped by App Store Connect domain.BagbutikSpecDecoderdecodes Apple's OpenAPI document into an intermediate Swift representation.BagbutikDocsCollectordownloads and normalizes Apple documentation so generated code gets useful Xcode documentation comments.BagbutikGeneratorcombines the decoded spec and collected docs to render the Swift source inSources/.
This split matters when navigating the codebase. If you want to understand runtime behavior, start in Bagbutik-Core. If you want to understand how generated endpoints and models are produced, start with BagbutikSpecDecoder, BagbutikDocsCollector, and BagbutikGenerator.
How to get Bagbutik into a project
Bagbutik is primarily distributed as a source-based Swift package using Swift Package Manager.
For advanced use cases, a prebuilt XCFramework is also provided. Using the XCFramework is optional and does not replace the source-based package.
Using Bagbutik as a source package
The library of generated code consists of multiple libraries, allowing consumers to depend only on the API areas they need.
Add Bagbutik as a dependency in your Package.swift:
dependencies: [
.package(url: "https://github.com/MortenGregersen/Bagbutik", from: "19.0.0"),
]
Then add the required products to your target:
.target(
name: "Awesome",
dependencies: [
.product(name: "Bagbutik-AppStore", package: "Bagbutik"),
.product(name: "Bagbutik-TestFlight", package: "Bagbutik"),
]
)
If you need access to all APIs, you can depend on the umbrella library:
.target(
name: "Awesome",
dependencies: [
.product(name: "Bagbutik", package: "Bagbutik"),
]
)
Available modules
Each module corresponds to a specific area of the App Store Connect API:
Bagbutik-AppStore: Manage all aspects of your app, App Clips, in-app purchases, and customer reviews in the App Store.Bagbutik-GameCenter: Manage Game Center data and configurations for your apps.Bagbutik-Marketplaces: Manage keys, packages, and search for the marketplace distribution of your app.Bagbutik-Provisioning: Manage the bundle IDs, certificates, devices and provisioning profiles for your app.Bagbutik-Reporting: Download your sales and financial reports and get power and performance metrics, logs, and signatures.Bagbutik-TestFlight: Manage your beta testing program, including beta testers and groups, apps, App Clips, and builds.Bagbutik-Users: Manage users and email invitations to join your App Store Connect team.Bagbutik-Webhooks: Manage notifications from App Store about your apps and their statuses.Bagbutik-XcodeCloud: Automate reading Xcode Cloud data, managing workflows, and starting builds.
Remember to replace hyphens with underscores when importing modules.
For example, when importing Bagbutik-TestFlight:
import Bagbutik_TestFlight
Endpoint pattern
Generated endpoints follow the same pattern throughout the package:
- Import
Bagbutik_Coreand the product module for the API area you need. - Build a
Requestby calling a generated static helper such as.listBundleIdsV1(...). - Send the request through
BagbutikService. - If the response type supports pagination, use
requestNextPage(for:)orrequestAllPages(_:).
This keeps each endpoint builder lightweight while centralizing authentication, decoding, and error handling in BagbutikService.
Using the XCFramework
Bagbutik releases also include a prebuilt XCFramework for cases where you prefer a binary dependency, such as:
- Faster CI builds
- Tooling or plugin projects
- Avoiding recompilation of all Bagbutik modules
The XCFramework contains the umbrella Bagbutik module.
Option 1: Use the XCFramework via URL and checksum (recommended)
Add a binary target in your Package.swift:
.binaryTarget(
name: "Bagbutik",
url: "https://github.com/MortenGregersen/Bagbutik/releases/download/<VERSION>/Bagbutik.xcframework.zip",
checksum: "<CHECKSUM>"
)
The exact checksum for each version is listed in the corresponding GitHub Release.
Then add Bagbutik as a dep
