Skip to content

Instantly share code, notes, and snippets.

@drewmccormack
Last active September 26, 2023 08:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drewmccormack/300912908e34b179134327184b41fc2b to your computer and use it in GitHub Desktop.
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.
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
}
}
@drewmccormack
Copy link
Author

As an aside, I wish someone would just write an API that works like this:

import AppStoreConnect

let app = App(bundleId: "...")
for localization in await app.versions.first!.localizations {
    await localization.update(whatsNew: "String for \(localization.locale)")
    await localization.update(promotionalText: "String for \(localization.locale)")
}

Done. Now that's an API!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment