Spotify.NET/SpotifyAPI.Docs/versioned_docs/version-5.1.1/web/playlists.md

267 lines
10 KiB
Markdown
Raw Normal View History

2020-05-13 17:25:42 +01:00
---
id: playlists
title: Playlists
sidebar_label: Playlists
---
2019-08-16 23:40:04 +01:00
## GetUserPlaylists
2016-08-20 11:49:09 +01:00
> Get a list of the playlists owned or followed by a Spotify user.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|[limit]| The maximum number of playlists to return. Default: 20. Minimum: 1. Maximum: 50. | `20`
|[offset]| The index of the first playlist to return. Default: 0 (the first object) | `0`
Returns a [SimplePlaylist](https://developer.spotify.com/web-api/object-model/#playlist-object-simplified) wrapped inside a [Paging Object](https://developer.spotify.com/web-api/object-model/#paging-object)
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
Paging<SimplePlaylist> userPlaylists = _spotify.GetUserPlaylists("1122095781");
userPlaylists.Items.ForEach(playlist => playlist.Owner.DisplayName) //Who is the owner of the playlist?
```
---
2019-08-16 23:40:04 +01:00
## GetPlaylist
2016-08-20 11:49:09 +01:00
> Get a playlist owned by a Spotify user.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|[fields]| Filters for the query: a comma-separated list of the fields to return. If omitted, all fields are returned. | `"description,uri"`
|[market]| An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. | "DE"
Returns a [FullTrack](https://developer.spotify.com/web-api/object-model/#track-object-full)
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
FullPlaylist playlist = _spotify.GetPlaylist("1122095781", "1TtEejT1y4D1WmcOnLfha2");
playlist.Tracks.Items.ForEach(track => Console.WriteLine(track.Track.Name));
```
---
2019-08-16 23:40:04 +01:00
## GetPlaylistTracks
2016-08-20 11:49:09 +01:00
> Get full details of the tracks of a playlist owned by a Spotify user.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|[fields]| Filters for the query: a comma-separated list of the fields to return. If omitted, all fields are returned. | `"description,uri"`
|[limit]| The maximum number of tracks to return. Default: 100. Minimum: 1. Maximum: 100. | `100`
|[offset]| The index of the first object to return. Default: 0 (i.e., the first object) | `0`
|[market]| An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. | `DE`
Returns a [PlaylistTrack](https://developer.spotify.com/web-api/object-model/#playlist-object-simplified) wrapped inside a [Paging Object](https://developer.spotify.com/web-api/object-model/#paging-object)
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
Paging<PlaylistTrack> playlist = _spotify.GetPlaylistTracks("1122095781", "1TtEejT1y4D1WmcOnLfha2");
playlist.Items.ForEach(track => Console.WriteLine(track.Track.Name));
```
---
2019-08-16 23:40:04 +01:00
## CreatePlaylist
2016-08-20 11:49:09 +01:00
> Create a playlist for a Spotify user. (The playlist will be empty until you add tracks.)
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistName| The name for the new playlist, for example "Your Coolest Playlist". This name does not need to be unique. | `"This is my new Playlist"`
|[isPublic]| default true. If true the playlist will be public, if false it will be private. To be able to create private playlists, the user must have granted the playlist-modify-private scope. | `true`
Returns a [FullPlaylist](https://developer.spotify.com/web-api/object-model/#playlist-object-full)
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
FullPlaylist playlist = _spotify.CreatePlaylist("1122095781", "This is my new Playlist");
if(!playlist.HasError())
Console.WriteLine("Playlist-URI: " + playlist.Uri);
```
---
2019-08-16 23:40:04 +01:00
## UpdatePlaylist
2016-08-20 11:49:09 +01:00
> Change a playlists name and public/private state. (The user must, of course, own the playlist.)
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|[newName]| The new name for the playlist, for example "My New Playlist Title". | `"New Playlistname"`
|[newPublic]| If true the playlist will be public, if false it will be private. | EXAMPLE
2019-08-16 23:40:04 +01:00
Returns a `ErrorResponse` which just contains a possible error. (`response.HasError()` and `response.Error`)
2016-08-20 11:49:09 +01:00
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
ErrorResponse response = _spotify.UpdatePlaylist("1122095781", "1TtEejT1y4D1WmcOnLfha2", "New Name", true);
if(!response.HasError())
Console.WriteLine("success");
```
---
2019-08-16 23:40:04 +01:00
## ReplacePlaylistTracks
2016-08-20 11:49:09 +01:00
> Replace all the tracks in a playlist, overwriting its existing tracks. This powerful request can be useful for replacing tracks, re-ordering existing tracks, or clearing the playlist.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|uris| A list of Spotify track URIs to set. A maximum of 100 tracks can be set in one request. | `new List<string> { "1ri6UZpjPLmTCswIXZ6Uq1" }`
2019-08-16 23:40:04 +01:00
Returns a `ErrorResponse` which just contains a possible error. (`response.HasError()` and `response.Error`)
2016-08-20 11:49:09 +01:00
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
ErrorResponse response = _spotify.ReplacePlaylistTracks("1122095781", "1TtEejT1y4D1WmcOnLfha2", new List<string> { "1ri6UZpjPLmTCswIXZ6Uq1" });
if(!response.HasError())
Console.WriteLine("success");
```
---
2019-08-16 23:40:04 +01:00
## RemovePlaylistTracks
2016-08-20 11:49:09 +01:00
> Remove one or more tracks from a users playlist.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|uris| array of objects containing Spotify URI strings (and their position in the playlist). A maximum of 100 objects can be sent at once. | `(example below)`
2019-08-16 23:40:04 +01:00
Returns a `ErrorResponse` which just contains a possible error. (`response.HasError()` and `response.Error`)
2016-08-20 11:49:09 +01:00
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
//Remove multiple tracks
ErrorResponse playlist = _spotify.RemovePlaylistTracks("1122095781", "1TtEejT1y4D1WmcOnLfha2", new List<DeleteTrackUri>()
{
new DeleteTrackUri("1ri6UZpjPLmTCswIXZ6Uq1"),
new DeleteTrackUri("47xtGU3vht7mXLHqnbaau5")
});
//Remove multiple tracks at their specified positions
ErrorResponse playlist = _spotify.RemovePlaylistTracks("1122095781", "1TtEejT1y4D1WmcOnLfha2", new List<DeleteTrackUri>()
{
new DeleteTrackUri("1ri6UZpjPLmTCswIXZ6Uq1", 2),
new DeleteTrackUri("47xtGU3vht7mXLHqnbaau5", 0, 50)
});
```
---
2019-08-16 23:40:04 +01:00
## RemovePlaylistTrack
2016-08-20 11:49:09 +01:00
> Remove one or more tracks from a users playlist.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|uri| Spotify URI | `new DeleteTrackUri("1ri6UZpjPLmTCswIXZ6Uq1")`
2019-08-16 23:40:04 +01:00
Returns a `ErrorResponse` which just contains a possible error. (`response.HasError()` and `response.Error`)
2016-08-20 11:49:09 +01:00
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
//Remove all tracks with the specified URI
ErrorResponse response = _spotify.RemovePlaylistTrack("1122095781", "1TtEejT1y4D1WmcOnLfha2", new DeleteTrackUri("1ri6UZpjPLmTCswIXZ6Uq1"));
//Remove all tracks with the specified URI and the specified positions
ErrorResponse response = _spotify.RemovePlaylistTrack("1122095781", "1TtEejT1y4D1WmcOnLfha2", new DeleteTrackUri("1ri6UZpjPLmTCswIXZ6Uq1", 0, 10, 20));
```
---
2019-08-16 23:40:04 +01:00
## AddPlaylistTracks
2016-08-20 11:49:09 +01:00
> Add one or more tracks to a users playlist.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|uris| A list of Spotify track URIs to add | `new List<string> { "1ri6UZpjPLmTCswIXZ6Uq1" }`
|[position]| The position to insert the tracks, a zero-based index | `10`
2019-08-16 23:40:04 +01:00
Returns a `ErrorResponse` which just contains a possible error. (`response.HasError()` and `response.Error`)
2016-08-20 11:49:09 +01:00
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
ErrorResponse response = _spotify.AddPlaylistTracks("1122095781", "1TtEejT1y4D1WmcOnLfha2", new List<string> { "1ri6UZpjPLmTCswIXZ6Uq1" });
if(!response.HasError())
Console.WriteLine("Success");
```
---
2019-08-16 23:40:04 +01:00
## AddPlaylistTrack
2016-08-20 11:49:09 +01:00
> Add one or more tracks to a users playlist.
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|uri| A Spotify Track URI | `"1ri6UZpjPLmTCswIXZ6Uq1"`
|position| The position to insert the tracks, a zero-based index | `10`
2019-08-16 23:40:04 +01:00
Returns a `ErrorResponse` which just contains a possible error. (`response.HasError()` and `response.Error`)
2016-08-20 11:49:09 +01:00
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
ErrorResponse response = _spotify.AddPlaylistTrack("1122095781", "1TtEejT1y4D1WmcOnLfha2", "1ri6UZpjPLmTCswIXZ6Uq1");
if(!response.HasError())
Console.WriteLine("Success");
```
---
2019-08-16 23:40:04 +01:00
## ReorderPlaylist
2016-08-20 11:49:09 +01:00
> Reorder a track or a group of tracks in a playlist.
> More Info: [Reorder-Playlist](https://developer.spotify.com/web-api/reorder-playlists-tracks/)
2019-08-16 23:40:04 +01:00
**Parameters**
2016-08-20 11:49:09 +01:00
|Name|Description|Example|
|--------------|-------------------------|-------------------------|
|userId| The user's Spotify user ID. | `"1122095781"`
|playlistId| The Spotify ID for the playlist. | `"1TtEejT1y4D1WmcOnLfha2"`
|rangeStart| The position of the first track to be reordered. | `2`
|insertBefore| The position where the tracks should be inserted. | `0`
|[rangeLength]| The amount of tracks to be reordered. Defaults to 1 if not set. | `2`
|[snapshotId]| The playlist's snapshot ID against which you want to make the changes. | ``
2019-08-16 23:40:04 +01:00
Returns a `Snapshot`-Object which contains the property `String SnapshotId`
2016-08-20 11:49:09 +01:00
2019-08-16 23:40:04 +01:00
**Usage**
```csharp
2016-08-20 11:49:09 +01:00
Snapshot snapshot = _spotify.ReorderPlaylist("1122095781", "1TtEejT1y4D1WmcOnLfha2", 2, 0, 2);
Console.WriteLine("New SnapshotId: " + snapshot.SnapshotId);
```
---