cli icon indicating copy to clipboard operation
cli copied to clipboard

CosmosAsync "request failed with error code -1 (Resolver not found!)"

Open brimell opened this issue 2 years ago β€’ 12 comments

πŸ” 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

brimell avatar Feb 16 '24 00:02 brimell

I have a feeling I'm being rate limited so I'll check in tomorrow and see what's up...

brimell avatar Feb 16 '24 01:02 brimell

use platform methods

ohitstom avatar Feb 16 '24 01:02 ohitstom

Are there platform methods for adding tracks to playlists? I can't find that in the docs

brimell avatar Feb 16 '24 02:02 brimell

Spicetify.Platform.PlaylistAPI.add(
  "spotify:playlist:6LFlf3kk62MioxGw7Dy0ZC",
  ["spotify:track:0OG11VjhfTx04bHarpaTaN"],
  {},
);

ohitstom avatar Feb 16 '24 02:02 ohitstom

Thanks so much for the quick reply - trying this rn

brimell avatar Feb 16 '24 02:02 brimell

Ok cool. Thanks so much for the help this works and actually looks quite nice as well! Feel free to close this issue

brimell avatar Feb 16 '24 02:02 brimell

  • 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?)

brimell avatar Feb 16 '24 02:02 brimell

  • 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

ohitstom avatar Feb 16 '24 02:02 ohitstom

Ok yeah good idea. I wouldn't mind adding a few things to the platform section on the docs if you don't mind.

brimell avatar Feb 16 '24 02:02 brimell

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

ohitstom avatar Feb 16 '24 02:02 ohitstom

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

rxri avatar Feb 16 '24 05:02 rxri

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: ""}]);
}

brimell avatar Feb 16 '24 13:02 brimell