Last active
September 26, 2023 08:36
-
-
Save drewmccormack/300912908e34b179134327184b41fc2b to your computer and use it in GitHub Desktop.
Using the AppStoreConnect_Swift_SDK package to update localizations on App Store Connect.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AppStoreConnect_Swift_SDK | |
func updateMetadata(forBundleID bundleID: String) async throws { | |
let configuration = try! APIConfiguration(issuerID: "...", privateKeyID: "...", privateKey: "...") | |
let provider = APIProvider(configuration: configuration) | |
// Get app | |
let appRequest = APIEndpoint.v1 | |
.apps | |
.get(parameters: .init(filterBundleID: [bundleID], include: [.appInfos, .appStoreVersions])) | |
let app: App = try! await provider.request(appRequest).data.first! | |
// Get latest version | |
let versionId = app.relationships!.appStoreVersions!.data!.first!.id | |
let versionRequest = APIEndpoint.v1 | |
.appStoreVersions | |
.id(versionId) | |
.get(parameters: .init(include: [.appStoreVersionLocalizations], limitAppStoreVersionLocalizations: 50)) | |
let version: AppStoreVersion = try! await provider.request(versionRequest).data | |
// Get localizations | |
let localizations = version.relationships!.appStoreVersionLocalizations!.data! | |
for localizationId in localizations.map({ $0.id }) { | |
// Get localization | |
let localizationRequest = APIEndpoint.v1 | |
.appStoreVersionLocalizations | |
.id(localizationId) | |
.get() | |
let localization: AppStoreVersionLocalization = try! await provider.request(localizationRequest).data | |
// Read strings to upload | |
let locale = localization.attributes!.locale! | |
let releaseNotes = "Release Notes for What's New for \(locale)" // Get string for locale | |
let promotionalText = "Promotional for \(locale)" // Get string for locale | |
// Update localization | |
let updateLocalizationRequest = APIEndpoint.v1 | |
.appStoreVersionLocalizations | |
.id(localizationId) | |
.patch(.init(data: .init(type: .appStoreVersionLocalizations, id: localizationId, attributes: .init(promotionalText: promotionalText, whatsNew: releaseNotes)))) | |
let _: AppStoreVersionLocalization = try! await provider.request(updateLocalizationRequest).data | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As an aside, I wish someone would just write an API that works like this:
Done. Now that's an API!