• Stars
    star
    1,431
  • Rank 32,887 (Top 0.7 %)
  • Language
    Swift
  • License
    Other
  • Created about 6 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The Swift SDK to work with the App Store Connect API from Apple.

App Store Connect Swift SDK

The Swift SDK to work with the App Store Connect API from Apple.

Bitrise Status Swift Version Platform Compatibility Dependency frameworks Twitter

Kickstart information on the API

Included in this SDK

  • 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

Requesting API Access

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.

How to use the SDK?

Not all endpoints are available yet, we're working hard to implement them all (see Endpoints).

1. Import the framework:

import AppStoreConnect_Swift_SDK

2. Create your API Configuration

Go to https://appstoreconnect.apple.com/access/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>")

3. Create an APIProvider and perform a request

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")

Handling paged responses

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")
    }
}

Handling errors

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.

Installation

Swift Package Manager

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"))
]

Development

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
  • you should be able to run the tests
bundle exec fastlane test

Update OpenAPI generated code

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.

Communication

  • 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.

Applications that use the SDK

  • 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.

License

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.

Author

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.

More Repositories

1

CombineSwiftPlayground

A Swift playground explaining the concepts of the new Combine framework
Swift
1,102
star
2

Roadmap

Publish your roadmap inside your app and allow users to vote for upcoming features
Swift
797
star
3

SwiftUIKitView

Easily use UIKit views in your SwiftUI applications. Create Xcode Previews for UIView elements
Swift
710
star
4

Poes

A Swift command-line tool to easily send push notifications to the iOS simulator
Swift
453
star
5

RocketSimApp

Enhancing the iOS simulator for productivity
Swift
425
star
6

CoreDataBestPractices

Best Practices in Core Data explained within a demo application
Swift
413
star
7

WhatTheErrorCode

Convert unreadable errors into understandable descriptions
Swift
143
star
8

Moya-SwiftyJSONMapper

Map objects through SwiftyJSON in combination with Moya
Swift
115
star
9

AsyncOperations

Asynchronous Operations in Swift explained in a Swift Playground
Swift
92
star
10

QR-Code-Custom

A playground demonstrating a way to create a custom QR code with a custom color and logo in Swift.
Swift
42
star
11

TaskGroupsResultBuilder

A @resultBuilder to use to bundle tasks together.
Swift
36
star
12

AppUpdately

Fetch the update available status for iOS or macOS apps based on the bundle identifier.
Swift
36
star
13

CombineWorkshop

Contains all files needed for my Combine workshop.
Swift
32
star
14

appstoreconnect-app

A Mac App to control App Store Connect!
Swift
28
star
15

CustomSwiftOperators

Demonstrating custom Swift operators. Including prefix, postfix, infix, and compound assignment operators.
Swift
18
star
16

CombineExtensions

A collection of Combine Extensions
Swift
16
star
17

ALLocalizables

Localizable label and buttons directly from the interface builder
Ruby
14
star
18

ALDataRequestView

A view representation for data requests. Support for ReactiveSwift and RXSwift
Swift
13
star
19

StockAnalyzerApp

Public repo for tracking bugs and features for the Stock Analyzer app
Swift
7
star
20

DataRacesActors

Slides and content from my SwiftLeeds talk "Understanding Data Races and Actors in Swift 5.5"
Swift
7
star
21

UIControl-Blocks

Use blocks with UIControls
Objective-C
6
star
22

Moya-JASONMapper

Map objects through JASON in combination with Moya
Swift
5
star
23

ImageCollectionViewer

Get FB Albums and show them in a gallery
Objective-C
4
star
24

ImageGen

A library to generate images easily based on text input
4
star
25

MeetupRaffle

Raffle a member from a meetup event
Swift
3
star
26

organizing-conferences-checklist

General tips on organising conferences, based on feedback from the community
1
star