A modern Swift SDK for the Amazon Advertising API, featuring OpenAPI-generated clients with full type safety and async/await support.
| Package | Description |
|---|---|
AmazonAdsCore |
Shared authentication, transport, and types |
AmazonAdsSponsoredProductsAPIv3 |
Sponsored Products API v3 (generated) |
AmazonAdsAPIv1 |
Unified Amazon Ads API v1 (generated) |
AmazonAdsAccounts |
Accounts/Profiles API (generated) |
LegacyAmazonAdsSponsoredProductsAPIv3 |
Legacy handwritten SP v3 client |
- ✅ OpenAPI Generated - Type-safe clients generated from official Amazon OpenAPI specs
- ✅ OAuth 2.0 with PKCE - Secure authorization flow
- ✅ Multi-region Support - North America, Europe, and Far East
- ✅ Async/Await - Modern Swift concurrency throughout
- ✅ Automatic Auth Headers -
AuthenticatedTransportinjects auth automatically - ✅ Dynamic Profiles - Switch profiles without recreating clients
- ✅ 150k+ Lines Generated - Complete API coverage
- iOS 16.0+ / macOS 13.0+ / tvOS 16.0+ / watchOS 9.0+ / visionOS 1.0+
- Swift 5.9+
dependencies: [
.package(url: "https://github.com/cedricziel/swift-amazon-ads.git", from: "1.0.0")
]Then add the products you need:
.target(
name: "YourTarget",
dependencies: [
.product(name: "AmazonAdsCore", package: "swift-amazon-ads"),
.product(name: "AmazonAdsSponsoredProductsAPIv3", package: "swift-amazon-ads"),
// Add others as needed
]
)import AmazonAdsCore
import AmazonAdsSponsoredProductsAPIv3
// Create a Sponsored Products client
let client = SponsoredProductsClient.make(
region: .northAmerica,
tokenProvider: { try await myAuthService.getAccessToken() },
clientId: "amzn1.application-oa2-client.xxxxx",
profileId: "1234567890"
)// List campaigns
let response = try await client.listSponsoredProductsCampaigns(.init(
headers: .init(
Amazon_hyphen_Advertising_hyphen_API_hyphen_ClientId: clientId,
Amazon_hyphen_Advertising_hyphen_API_hyphen_Scope: profileId
)
))
switch response {
case .ok(let result):
// Handle success
print("Found campaigns")
case .code207(let multiStatus):
// Handle multi-status response
break
default:
// Handle errors
break
}// Create client with dynamic profile support
let (client, transport) = SponsoredProductsClient.makeWithDynamicProfile(
region: .northAmerica,
tokenProvider: { try await myAuthService.getAccessToken() },
clientId: "your-client-id"
)
// Switch profiles without recreating client
transport.profileId = "new-profile-id"Shared functionality used by all API clients:
AmazonRegion- API regions with endpointsAuthenticatedTransport- Injects auth headers into requestsDynamicProfileTransport- Allows changing profile at runtimeTokenStorageKey- Standard key names for token storage
Generated client for Sponsored Products API v3:
import AmazonAdsSponsoredProductsAPIv3
// Type aliases for convenience
let client: SponsoredProductsClient = ...
let campaign: SPCampaign = ...
let adGroup: SPAdGroup = ...Generated client for the unified Amazon Ads API:
import AmazonAdsAPIv1
let client: AmazonAdsClient = ...
let campaign: Campaign = ...Generated client for Accounts/Profiles API:
import AmazonAdsAccounts
let client: AccountsClient = ...
let account: AdsAccount = ...make buildmake testWhen Amazon updates their OpenAPI specs:
# Update specs from specs/ directory
make update-specs
# Regenerate all clients
make generate
# Or regenerate individually
make generate-sp # Sponsored Products v3
make generate-api # Unified API v1
make generate-accounts # Accounts APIswift-amazon-ads/
├── Sources/
│ ├── AmazonAdsCore/ # Shared auth & types
│ │ ├── Auth/
│ │ ├── Transport/
│ │ └── Types/
│ ├── AmazonAdsSponsoredProductsAPIv3/ # Generated SP v3
│ │ ├── GeneratedSources/
│ │ ├── Extensions.swift
│ │ └── openapi.json
│ ├── AmazonAdsAPIv1/ # Generated unified API
│ ├── AmazonAdsAccounts/ # Generated accounts API
│ └── LegacyAmazonAdsSponsoredProductsAPIv3/ # Handwritten legacy
├── Tests/
├── specs/ # OpenAPI source specs
└── Makefile
- Campaigns (CRUD, list, archive)
- Ad Groups (CRUD, list)
- Keywords (CRUD, list)
- Product Ads (CRUD, list)
- Targets (CRUD, list)
- Negative Keywords & Targets
- Budget Recommendations
- Bid Recommendations
- Cross-product campaign management
- Ad associations
- Budget rules
- Moderation
- List advertising accounts
- Account metadata
- Register at advertising.amazon.com
- Complete API onboarding
- Create an API application
- Add
http://localhost:8765/callbackas redirect URI
Contributions welcome! Please submit a Pull Request.
Apache License 2.0 - see LICENSE file.
Cedric Ziel (@cedricziel)