The Swift SDK to work with the App Store Connect API from Apple.
- Automate your workflow with the App Store Connect API
- Official Apple Documentation
- WWDC 2018 Talk Automating App Store Connect
- App Store Connect API adoption with use case examples
- Configuration with API Key
- APIProvider with endpoints structure
- Add models for all endpoints
- JWT Logic to sign requests
- Get started section in the readme
- Support for Mac
- Supports all requests due to OpenAPI generated requests and entities
To request access, go to the new API Keys section in Users and Access in App Store Connect. Please note that you must be the Team Agent (Legal role) of a development team enrolled as an organization. Access for developers enrolled as an individual is coming soon.
Not all endpoints are available yet, we're working hard to implement them all (see Endpoints).
import AppStoreConnect_Swift_SDK
Go to https://appstoreconnect.apple.com/access/integrations/api and create your own key. This is also the page to find your private key ID and the issuer ID.
After downloading your private key, you can open the .p8 file containing the private key in a text editor which will show like the following content:
-----BEGIN PRIVATE KEY-----
FDFDGgEAMBMGByqGSM49AgEGCCqGSM49AwEHBHkwdwQgPaXyFvZfNydDEjxgjUCUxyGjXcQxiulEdGxoVbasV3GgCgYIKomokDj0DAQehRANCAAASffd/DU3TUWAoLmqE6hZL9A7i0DWpXtmIDCDiITRznC6K4/WjdIcuMcixy+m6O0IrffxJOablIX2VM8sHRpoiuy
-----END PRIVATE KEY-----
Copy the contents and remove the whitelines, -----BEGIN PRIVATE KEY-----
and -----END PRIVATE KEY-----
.
Use this private key together with the issuer ID and the private key ID to create your configuration file:
let configuration = APIConfiguration(issuerID: "<YOUR ISSUER ID>", privateKeyID: "<YOUR PRIVATE KEY ID>", privateKey: "<YOUR PRIVATE KEY>")
Alternatively you can pass the path to the .p8 file:
let configuration = APIConfiguration(issuerID: "<YOUR ISSUER ID>", privateKeyID: "<YOUR PRIVATE KEY ID>", privateKeyURL: URL(fileURLWithPath: "~/AuthKey_<YOUR PRIVATE KEY ID>.p8"))
Both methods also accept an optional expirationDuration
parameter that defaults to 20 minutes which is the max duration allowed by the API. In some cases it might be useful to specify a shorter value in seconds to account for possible clock skews:
APIConfiguration(issuerID: "<YOUR ISSUER ID>", privateKeyID: "<YOUR PRIVATE KEY ID>", privateKey: "<YOUR PRIVATE KEY>", expirationDuration: "<OPTIONAL EXPIRATION DURATION>"))
APIConfiguration(issuerID: "<YOUR ISSUER ID>", privateKeyID: "<YOUR PRIVATE KEY ID>", privateKeyURL: URL(fileURLWithPath: "~/AuthKey_<YOUR PRIVATE KEY ID>.p8"), expirationDuration: "<OPTIONAL EXPIRATION DURATION>")
You can even omit the privateKeyID
as it can be inferred from the name of the .p8 file.
After creating an APIProvider
instance with your APIConfiguration
you can start performing your first request.
let request = APIEndpoint
.v1
.apps
.get(parameters: .init(
sort: [.bundleID],
fieldsApps: [.appInfos, .name, .bundleID],
limit: 5
))
let apps = try await self.provider.request(request).data
print("Did fetch \(apps.count) apps")
If the responses from the API request can be delivered in multiple pages, you can iterate over all of them using an AsyncSequence or individually request the next page following the current one.
let request = APIEndpoint
.v1
.apps
.get(parameters: .init(
sort: [.bundleID],
fieldsApps: [.appInfos, .name, .bundleID],
limit: 2
))
// Demonstration of AsyncSequence result of APIProvider.paged(_)
var allApps: [App] = []
for try await pagedResult in provider.paged(request) {
allApps.append(contentsOf: pagedResult.data)
}
print("There are \(allApps.count) apps in total")
// Demonstration of APIProvider.request(_:isPagedResponse:) and APIProvider.request(_: pageAfter:)
let firstPageResult = try await provider.request(request)
let firstPageApps = firstPageResult.data
print("The first page of results has \(firstPageApps.count) apps")
if provider.request(request, isPagedResponse: firstPageResult) {
if let nextPage = try await provider.request(request, pageAfter: firstPageResult) {
let secondPageApps = nextPage.data
print("The second page of results has \(secondPageApps.count) apps")
}
}
Whenever an error is returned from a request, you can get the details by catching the error as follows:
do {
print(try await self.provider.request(requestWithError).data)
} catch APIProvider.Error.requestFailure(let statusCode, let errorResponse, _) {
print("Request failed with statuscode: \(statusCode) and the following errors:")
errorResponse?.errors?.forEach({ error in
print("Error code: \(error.code)")
print("Error title: \(error.title)")
print("Error detail: \(error.detail)")
})
} catch {
print("Something went wrong fetching the apps: \(error.localizedDescription)")
}
The error title and detail should help you solve the failure. For more info regarding errors, see: Parsing the Error Response Code as documented by Apple.
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift
compiler. It is in early development, but this SDK does support its use on supported platforms.
Once you have your Swift package set up, adding the SDK as a dependency is as easy as adding it to the dependencies
value of your Package.swift
.
dependencies: [
.package(url: "https://github.com/AvdLee/appstoreconnect-swift-sdk.git", .upToNextMajor(from: "2.0.0"))
]
To help with the development of this repository you need to follow the next steps:
- clone this repository
- download the submodules dependencies
git submodule update --init --recursive
bundle install
- if you get permission errors when running
bundle install
, it's possible that you have to install a newer version of Ruby along the default one shipped with macOS (instead of3.2.2
used below, use the version number that is output at the end of theruby-install ruby
command):
brew install chruby ruby-install
ruby-install ruby
chruby 3.2.2
gem update --system
gem install bundler
- you should be able to run the tests
bundle exec fastlane test
Install jq:
brew install jq
Run the following:
$ make update
This will attempt to download the App Store Connect OpenAPI specification from Apple, and re-run the CreateAPI generator to produce the updated source code.
Alternatively, you can run make download
and make generate
individually.
- If you found a bug, open an issue.
- If you have a feature request, open an issue.
- If you want to contribute, submit a pull request.
-
Helm for App Store Connect developed by Pol Piella & Hidde van der Ploeg. Helm is an all-in-one macOS app that replaces App Store Connect, supercharging your app updates, localization, and ASO with AI-powered tools. It also lets you easily manage TestFlight releases and turns reviews into better support and deeper customer insights. Learn more about Helm.
-
Starly: reviews, reply to apps developed by Viktor Grushevskiy. The Starly app is a project that will allow developers to manage reviews on the App Store with ease. You can reply to them, translate them to the language you want, filter them, and create templates. iOS and macOS versions available.
-
🌟 Superstar: App Store Review manager developed by Jordi Bruin. Superstar uses the App Store Connect API to help you respond to your App Store customer reviews in seconds. Use custom templates to quickly reply with professional responses. Translate reviews and your responses directly with free DeepL integration. Available for free for a limited time.
-
AppsMan: Manage app metada globally developed by Karmjit Singh. The AppsMan app is a project that will allow developers to manage apps localisable data on the App Store with ease. You can easily update the data for one language and copy over to other and save. You can see the previous versions details as well. Only macOS versions available.
-
Localiji: Localizations for App Store developed by Nicolas Kick. Localiji manages a local copy of your app localizations from App Store Connect and allows you to effortlessly sync the changes. Edit individual attributes, like your app’s description, release notes or screenshots. Export an entire language, import the translations again and upload them to App Store Connect with only a few clicks.
-
Five Stars: Reviews & Ratings developed by Mathias Emil Mortensen. Five Stars helps app developers read and reply to App Store reviews from their users. Translate reviews, reply with customizable templates and AI-powered quick replies, filter by region, and view global app ratings from any app. Five Stars is available for iPhone and iPad, with a Mac version coming in Spring 2024.
App Store Connect Swift SDK is available under the MIT license, and uses source code from open source projects. See the LICENSE file for more info.
This project is originally created by Antoine van der Lee but has a lot of great contributors. We're open for contributions of any kind to make this project even better.