I’m trying to build a playlist editor on macOS. I can create playlists via the Apple Music HTTP API, but DELETE always returns 401 even immediately after creation with the same tokens.
Minimal repro:
#!/usr/bin/env bash
set -euo pipefail
BASE_URL="https://api.music.apple.com/v1"
PLAYLIST_NAME="${PLAYLIST_NAME:-blah}"
: "${APPLE_MUSIC_DEV_TOKEN:?}"
: "${APPLE_MUSIC_USER_TOKEN:?}"
create_body="$(mktemp)"
delete_body="$(mktemp)"
trap 'rm -f "$create_body" "$delete_body"' EXIT
curl -sS --compressed -o "$create_body" -w "Create status: %{http_code}\n" \
-X POST "${BASE_URL}/me/library/playlists" \
-H "Authorization: Bearer ${APPLE_MUSIC_DEV_TOKEN}" \
-H "Music-User-Token: ${APPLE_MUSIC_USER_TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"attributes\":{\"name\":\"${PLAYLIST_NAME}\"}}"
playlist_id="$(python3 - "$create_body" <<'PY'
import json, sys
with open(sys.argv[1], "r", encoding="utf-8") as f:
data = json.load(f)
print(data["data"][0]["id"])
PY
)"
curl -sS --compressed -o "$delete_body" -w "Delete status: %{http_code}\n" \
-X DELETE "${BASE_URL}/me/library/playlists/${playlist_id}" \
-H "Authorization: Bearer ${APPLE_MUSIC_DEV_TOKEN}" \
-H "Music-User-Token: ${APPLE_MUSIC_USER_TOKEN}" \
-H "Content-Type: application/json"
I capture the response bodies like this: cat "$create_body" cat "$delete_body"
Result:
- Create: 201
- Delete: 401
I also checked the latest macOS SDK’s MusicKit interfaces and MusicLibrary.createPlaylist/edit/add(to:) are marked @available(macOS, unavailable), so I can’t create/ delete via MusicKit on macOS either.
Question: How can I implement a playlist editor on macOS (create/delete/modify) if:
- MusicKit write APIs are unavailable on macOS, and
- The HTTP API can create but DELETE returns 401?
Any guidance or official workaround would be hugely appreciated.