spotify_cli/endpoints/playlists/
update_playlist_items.rs

1use crate::http::api::SpotifyApi;
2use crate::http::client::HttpError;
3use crate::http::endpoints::Endpoint;
4use serde_json::Value;
5
6/// Reorder items in a playlist
7/// range_start: position of first item to move
8/// insert_before: position where items should be inserted
9/// range_length: number of items to move (default 1)
10pub async fn reorder_playlist_items(
11    client: &SpotifyApi,
12    playlist_id: &str,
13    range_start: u32,
14    insert_before: u32,
15    range_length: Option<u32>,
16) -> Result<Option<Value>, HttpError> {
17    let mut body = serde_json::json!({
18        "range_start": range_start,
19        "insert_before": insert_before,
20    });
21
22    if let Some(len) = range_length {
23        body["range_length"] = serde_json::Value::Number(len.into());
24    }
25
26    client
27        .put_json(&Endpoint::PlaylistTracks { id: playlist_id }.path(), &body)
28        .await
29}