Authentication
The Apple Search Ads API uses OAuth 2.0 with JWT tokens signed using ES256 (ECDSA).
Getting API Credentials
- Go to Apple Search Ads
- Navigate to Settings > API
- Create a new API key
- Download your private key (
.pemfile) - Note your Client ID, Team ID, and Key ID
Configuration
Environment Variables
Set the following environment variables:
export ASA_CLIENT_ID="SEARCHADS.your-client-id"
export ASA_TEAM_ID="SEARCHADS.your-team-id"
export ASA_KEY_ID="your-key-id"
export ASA_ORG_ID="123456"
export ASA_PRIVATE_KEY_PATH="/path/to/private-key.pem"
Using a .env File
Create a .env file in your project:
ASA_CLIENT_ID=SEARCHADS.your-client-id
ASA_TEAM_ID=SEARCHADS.your-team-id
ASA_KEY_ID=your-key-id
ASA_ORG_ID=123456
ASA_PRIVATE_KEY_PATH=private-key.pem
Direct Configuration
You can also pass credentials directly:
from asa_api_client import AppleSearchAdsClient
client = AppleSearchAdsClient(
client_id="SEARCHADS.xxx",
team_id="SEARCHADS.xxx",
key_id="xxx",
org_id=123456,
private_key_path="private-key.pem",
)
Or with the private key content:
client = AppleSearchAdsClient(
client_id="SEARCHADS.xxx",
team_id="SEARCHADS.xxx",
key_id="xxx",
org_id=123456,
private_key="-----BEGIN EC PRIVATE KEY-----\n...",
)
Token Management
The client automatically handles:
- JWT creation and signing
- Token refresh when expired
- Request authentication headers
You don't need to manage tokens manually.