Apple Music
This Source monitors your Apple Music listening history via the official Apple Music API and scrobbles new activity to your configured Clients.
Because of how the Apple Music API works, Multi-Scrobbler (MS) requires two different tokens to function: a Media User Token (identifies your personal account) and an Authentication Token (authorizes API access).
1. Getting a Media User Token
The mediaUserToken is required to access your recently played history. You can extract it directly from the Apple Music web app:
- Visit music.apple.com in your browser and log in.
- Open your browser's Developer Tools (usually
F12orCmd+Option+I). - Navigate to the Application tab (Chrome/Edge) or Storage tab (Safari/Firefox).
- Expand Cookies in the left sidebar and select
https://music.apple.com. - Find the cookie named
media-user-tokenand copy its value (it typically starts with0.).
The mediaUserToken will eventually expire. If Multi-Scrobbler begins throwing authentication errors in the logs, simply repeat these steps to obtain and configure a fresh token.
2. Authentication
The Apple Music API requires a Developer Token (JWT). Multi-Scrobbler can either automatically generate this JWT for you using an Apple Music API key, or you can manually provide a pre-generated token.
- MusicKit Key (Recommended)
- Pre-generated Token
To generate JWTs automatically and avoid manual token refreshes, you need an Apple Music API key:
- Go to the Apple Developer portal and create a MusicKit key.
- Download the
.p8file — this is your private key. - Note your Key ID and Team ID (found in your Apple Developer account Membership details).
Add these details to your config:
{
"data": {
"key": {
"id": "2HPSNJZ88N",
"teamId": "SN6YASW8G4",
"p8": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEG...-----END PRIVATE KEY-----"
},
"mediaUserToken": "your-media-user-token-here"
}
}
When pasting the contents of your .p8 file into JSON, make sure to replace physical line breaks with \n so it remains a valid, single-line JSON string.
If you don't have an Apple Developer account, you can piggyback off the web app's token.
While browsing music.apple.com with Developer Tools open, inspect the Network tab. Look at the request headers for any request made to amp-api.music.apple.com. Copy the authorization header value (use everything after the Bearer prefix).
{
"data": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NiIsIm...",
"mediaUserToken": "your-media-user-token-here",
"headers": {
"Origin": "https://music.apple.com"
}
}
}
When using a JWT extracted from the browser, Apple requires the request to match the domain it was issued to. You must include the Origin header in your config as shown above.
Note: Browser-generated JWTs are valid for a maximum of 35 days and must be updated manually when they expire.
How Multi-Scrobbler handles Apple Music quirks
Timestamp Estimation The Apple Music API does not provide timestamps for when tracks were played. Multi-Scrobbler estimates play times by taking the current time and subtracting track durations backwards:
- The most recent track is assumed to have finished playing now.
- Each older track is estimated to have played
durationseconds before the previous one.
For the most accurate scrobble timestamps, it is highly recommended to keep the polling APPLEMUSIC_INTERVAL low (the default is 60 seconds).
Configuration Reference
- ENV
- File
- AIO
This is configuration for the ENV Config Type.
| Environment Variable | Required? | Default | Description |
|---|---|---|---|
APPLEMUSIC_ID | Yes | A unique ID for this source. | |
APPLEMUSIC_MEDIA_USER_TOKEN | Yes | The media-user-token extracted from the browser. | |
APPLEMUSIC_KEY_ID | No | Key ID from your MusicKit key. | |
APPLEMUSIC_TEAM_ID | No | Team ID from your Apple Developer account. | |
APPLEMUSIC_KEY_P8 | No | The contents of your MusicKit .p8 private key file. | |
APPLEMUSIC_TOKEN | No | A pre-generated JWT (alternative to key properties). | |
APPLEMUSIC_INTERVAL | No | 60 | Polling interval in seconds. |
APPLEMUSIC_NAME | No | A vanity name different than the ID. |
Config Structure
This displays the structure of the File Configuration for a applemusic type Source with all possible properties, their shape, and descriptions/types. Use this to understand how to write a valid config.
Config Example
This displays an example config file of a applemusic Source File Configuration that adheres to the shown Config Structure.
- text mode lets you edit the JSON directly.
- tree mode gives you a guided point-and-click editing experience that always keeps the JSON syntax valid.
Both modes validate that the configuraion is correct. Any errors show up as squiggly lines.
After you finish editing, switch to text and then copy all text to get a completed config.
Config Example Mobile Experience
This displays an example config file of a applemusic Source File Configuration that adheres to the shown Config Structure.
The example config file editor is meant for a larger screen experience so only the read-only example is shown. Please use this site on a tablet/laptop/desktop to enable file editor features.
[
{
"id": "myAppleMusic",
"name": "My Apple Music",
"enable": true,
"clients": [],
"data": {
"key": {
"id": "2HPSNJZ88N",
"teamId": "SN6YASW8G4",
"p8": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEG...-----END PRIVATE KEY-----"
},
"token": "your-jwt-token-here",
"mediaUserToken": "your-media-user-token-here"
},
"options": {
"logDiff": true
}
}
]
Config Structure
This displays the structure of the all-in-one (config.json) configuration with all possible properties, their shape, and descriptions/types. Use this to understand how to write a valid config.
Select the applemusic type from the respective sources node below, then expand it.
Config Example
This displays an example config file of a all-in-one (config.json) configuration that includes a applemusic Source that adheres to the shown Config Structure.
- text mode lets you edit the JSON directly.
- tree mode gives you a guided point-and-click editing experience that always keeps the JSON syntax valid.
Both modes validate that the configuraion is correct. Any errors show up as squiggly lines.
After you finish editing, switch to text and then copy all text to get a completed config.
Config Example Mobile Experience
This displays an example config file of a all-in-one (config.json) configuration that includes a applemusic Source that adheres to the shown Config Structure.
The example config file editor is meant for a larger screen experience so only the read-only example is shown. Please use this site on a tablet/laptop/desktop to enable file editor features.
{
"sources": [
{
"id": "myAppleMusic",
"name": "My Apple Music",
"enable": true,
"clients": [],
"data": {
"key": {
"id": "2HPSNJZ88N",
"teamId": "SN6YASW8G4",
"p8": "-----BEGIN PRIVATE KEY-----\nMIGTAgEAMBMGByqGSM49AgEG...-----END PRIVATE KEY-----"
},
"token": "your-jwt-token-here",
"mediaUserToken": "your-media-user-token-here"
},
"options": {
"logDiff": true
},
"type": "applemusic"
}
]
}