CosmosAsync "request failed with error code -1 (Resolver not found!)"
π Have you checked Spicetify.app page for your issue?
- [X] I have checked the FAQ
π Is there already an issue for your problem?
- [X] I have checked older issues, open and closed
βΉ Environment / Computer Info
- Spotify version: 1.2.31.1205.g4d59ad7c
- Spicetify version: 1.0.17
- platform: "Win32_x86_64"
π Description
Essentially, not allowing me to add a track to a playlist at all. I've checked that the track URI and playlist ID both work on the spotify developer platform (here: https://developer.spotify.com/documentation/web-api/reference/add-tracks-to-playlist).
Error: POST request to https://api.spotify.com/v1/playlists/4Xy4g6S1EY3GiOcIjdkFj7/tracks?uris=spotify%3Atrack%3Gq3uFAdJltar4ddwboPby request failed with error code -1 (Resolver not found!)
when:
export async function addTrackToPlaylist(playlistUri: string, trackUri: string) {
try {
const playlistId = playlistUriToPlaylistId(playlistUri);
console.log(`@${playlistId}@`, `@${trackUri}@`);
// Make POST request to add track to playlist
await Spicetify.CosmosAsync.post(`https://api.spotify.com/v1/playlists/${playlistId}/tracks`, {
uris: [trackUri],
});
console.log("Added track to playlist");
} catch (error) {
console.error("Error adding track to playlist:", error);
}
}
πΈ Screenshots
No response
I have a feeling I'm being rate limited so I'll check in tomorrow and see what's up...
use platform methods
Are there platform methods for adding tracks to playlists? I can't find that in the docs
Spicetify.Platform.PlaylistAPI.add(
"spotify:playlist:6LFlf3kk62MioxGw7Dy0ZC",
["spotify:track:0OG11VjhfTx04bHarpaTaN"],
{},
);
Thanks so much for the quick reply - trying this rn
Ok cool. Thanks so much for the help this works and actually looks quite nice as well! Feel free to close this issue
- would be nice to have this added to the docs though (and maybe you could direct me to where I could find types for the platform methods?)
- would be nice to have this added to the docs though (and maybe you could direct me to where I could find types for the platform methods?)
platform methods are managed by spotify, we just allow developers to access them, and as such making docs would be painstakingly difficult as every spotify update changes many of them without our knowledge.
Your best bet for finding them is just looking through the Spicetify.Platform object yourself and looking at how the functions themselves work in xpui to figure out the props to pass
Ok yeah good idea. I wouldn't mind adding a few things to the platform section on the docs if you don't mind.
Ok yeah good idea. I wouldn't mind adding a few things to the platform section on the docs if you don't mind.
i am not a maintainer but i dont think they would want that in the docs as again its not something we cant control consistently, @rxri would need to talk to you about this
Platform API will be documented in types and everything in v3 so thatβs something we already work on and have on eye. Also duplicate of https://github.com/spicetify/spicetify-cli/issues/2837
Just for anyone else having the same problem here is my solution:
async function addTrackToPlaylist(playlistUri: string, trackUri: string) {
await Spicetify.Platform.PlaylistAPI.add(playlistUri, [trackUri], {after: 1, before: 0});
}
async function removeTrackFromPlaylist(playlistUri: string, trackUri: string) {
await Spicetify.Platform.PlaylistAPI.remove(playlistUri, [{uri: trackUri, uid: ""}]);
}