Skip to main content

Get OAuth URL

curl -X GET https://api.asta.app/api/spotify/connect \
  -H "Authorization: Bearer YOUR_API_TOKEN"
{
  "url": "https://accounts.spotify.com/authorize?client_id=..."
}
Redirects the user to Spotify’s authorization page. After authorization, Spotify will redirect back to /api/spotify/callback with an authorization code.
You must configure a Spotify app in the Spotify Developer Dashboard and add the redirect URI (http://127.0.0.1:8010/api/spotify/callback for local development) to your app settings.

OAuth Callback

# This endpoint is called by Spotify after user authorization
GET /api/spotify/callback?code=...&state=...
code
string
required
Authorization code from Spotify
state
string
required
User ID passed during authorization
error
string
Error message if authorization failed
Exchanges the authorization code for access and refresh tokens, stores them securely, and redirects the user to the frontend settings page.
This endpoint is typically not called directly by your application. It’s the redirect URI that Spotify calls after user authorization.

Get Devices

curl -X GET https://api.asta.app/api/spotify/devices \
  -H "Authorization: Bearer YOUR_API_TOKEN"
{
  "devices": [
    {
      "id": "abc123",
      "name": "MacBook Pro",
      "type": "Computer",
      "is_active": true,
      "is_private_session": false,
      "is_restricted": false,
      "volume_percent": 50
    },
    {
      "id": "def456",
      "name": "iPhone",
      "type": "Smartphone",
      "is_active": false,
      "is_private_session": false,
      "is_restricted": false,
      "volume_percent": 100
    }
  ],
  "connected": true
}
devices
array
List of available Spotify devices
connected
boolean
Whether any devices are available

Start Playback

curl -X POST https://api.asta.app/api/spotify/play \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "track_uri": "spotify:track:4cOdK2wGLETKBW3PvgPWqT",
    "device_id": "abc123"
  }'
track_uri
string
required
Spotify URI of the track to play (e.g., spotify:track:4cOdK2wGLETKBW3PvgPWqT)
device_id
string
Device ID to play on. If omitted, plays on the active device.
{
  "ok": true,
  "error": null
}
ok
boolean
Whether playback started successfully
error
string
Error message if playback failed
Playback requires an active Spotify Premium account and at least one device with Spotify open.

Get Connection Status

curl -X GET https://api.asta.app/api/spotify/status \
  -H "Authorization: Bearer YOUR_API_TOKEN"
{
  "connected": true
}
connected
boolean
Whether the user has authorized Spotify access

Disconnect Spotify

curl -X POST https://api.asta.app/api/spotify/disconnect \
  -H "Authorization: Bearer YOUR_API_TOKEN"
{
  "disconnected": true
}
Clears stored access and refresh tokens. The user will need to re-authorize to use Spotify features again.

Setup Instructions

curl -X GET https://api.asta.app/api/spotify/setup \
  -H "Authorization: Bearer YOUR_API_TOKEN"
{
  "dashboard_url": "https://developer.spotify.com/dashboard",
  "docs_url": "https://developer.spotify.com/documentation/web-api",
  "redirect_uri": "http://127.0.0.1:8010/api/spotify/callback",
  "connect_url": "http://127.0.0.1:8010/api/spotify/connect?user_id=default",
  "steps": [
    "Go to the Spotify Developer Dashboard (link below) and log in with your Spotify account.",
    "Click Create app. Fill in name and description (e.g. Asta), accept the terms, then Create.",
    "Open your app → Settings. Copy Client ID and Client secret and paste them below.",
    "For playback on your devices: in the app settings under Redirect URIs, add: http://127.0.0.1:8010/api/spotify/callback then Save."
  ]
}
Returns setup instructions and configuration URLs for the Spotify integration.
dashboard_url
string
URL to Spotify Developer Dashboard
redirect_uri
string
OAuth redirect URI to configure in Spotify app
connect_url
string
URL to start OAuth flow
steps
array
Step-by-step setup instructions

Build docs developers (and LLMs) love