search_and_add
Search for a track and add the top result to a Spotify playlist in one step.
Instructions
Search for a track and add the top result to a playlist in one step.
Parameters
query : str
Free-text search query (e.g. "Shape of You Ed Sheeran").
playlist_id : str
Spotify playlist ID or full URI to add the track to.
Returns
dict
Keys: track_name, artists, track_uri, playlist_id.
Raises
ValueError
If query is blank or the search returns no results.
spotipy.SpotifyException
Propagated if the Spotify API returns a non-2xx response.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| playlist_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||