|
| 1 | +# Authentication |
| 2 | + |
| 3 | +The Apple Search Ads API uses OAuth 2.0 with JWT tokens signed using ES256 (ECDSA). |
| 4 | + |
| 5 | +## Getting API Credentials |
| 6 | + |
| 7 | +1. Go to [Apple Search Ads](https://searchads.apple.com) |
| 8 | +2. Navigate to **Settings** > **API** |
| 9 | +3. Create a new API key |
| 10 | +4. Download your private key (`.pem` file) |
| 11 | +5. Note your Client ID, Team ID, and Key ID |
| 12 | + |
| 13 | +## Configuration |
| 14 | + |
| 15 | +### Environment Variables |
| 16 | + |
| 17 | +Set the following environment variables: |
| 18 | + |
| 19 | +```bash |
| 20 | +export ASA_CLIENT_ID="SEARCHADS.your-client-id" |
| 21 | +export ASA_TEAM_ID="SEARCHADS.your-team-id" |
| 22 | +export ASA_KEY_ID="your-key-id" |
| 23 | +export ASA_ORG_ID="123456" |
| 24 | +export ASA_PRIVATE_KEY_PATH="/path/to/private-key.pem" |
| 25 | +``` |
| 26 | + |
| 27 | +### Using a .env File |
| 28 | + |
| 29 | +Create a `.env` file in your project: |
| 30 | + |
| 31 | +```bash |
| 32 | +ASA_CLIENT_ID=SEARCHADS.your-client-id |
| 33 | +ASA_TEAM_ID=SEARCHADS.your-team-id |
| 34 | +ASA_KEY_ID=your-key-id |
| 35 | +ASA_ORG_ID=123456 |
| 36 | +ASA_PRIVATE_KEY_PATH=private-key.pem |
| 37 | +``` |
| 38 | + |
| 39 | +### Direct Configuration |
| 40 | + |
| 41 | +You can also pass credentials directly: |
| 42 | + |
| 43 | +```python |
| 44 | +from search_ads_api import AppleSearchAdsClient |
| 45 | + |
| 46 | +client = AppleSearchAdsClient( |
| 47 | + client_id="SEARCHADS.xxx", |
| 48 | + team_id="SEARCHADS.xxx", |
| 49 | + key_id="xxx", |
| 50 | + org_id=123456, |
| 51 | + private_key_path="private-key.pem", |
| 52 | +) |
| 53 | +``` |
| 54 | + |
| 55 | +Or with the private key content: |
| 56 | + |
| 57 | +```python |
| 58 | +client = AppleSearchAdsClient( |
| 59 | + client_id="SEARCHADS.xxx", |
| 60 | + team_id="SEARCHADS.xxx", |
| 61 | + key_id="xxx", |
| 62 | + org_id=123456, |
| 63 | + private_key="-----BEGIN EC PRIVATE KEY-----\n...", |
| 64 | +) |
| 65 | +``` |
| 66 | + |
| 67 | +## Token Management |
| 68 | + |
| 69 | +The client automatically handles: |
| 70 | + |
| 71 | +- JWT creation and signing |
| 72 | +- Token refresh when expired |
| 73 | +- Request authentication headers |
| 74 | + |
| 75 | +You don't need to manage tokens manually. |
0 commit comments