-
Notifications
You must be signed in to change notification settings - Fork 0
/
.fetch-samples
64 lines (53 loc) · 2.41 KB
/
.fetch-samples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
shreyas:
user_id = ttx1gpej20552zpv12kplq0ky
Oauth Token = oath_token
MIGRATING FROM SPOTIFY
GET all the playlists of the user with user_id
Endpoint: /v1/users/{user_id}/playlists
fetch("https://api.spotify.com/v1/users/ttx1gpej20552zpv12kplq0ky/playlists",{
"headers": {
"Authorization": "Bearer {oath_token}"
}}),
"method": "GET"
}).then((res) => res.json()).then(json => console.log(json))
GET all tracks of a particular playlist
Endpoint: /v1/playlists/{playlist_id}/tracks
eg playlist_id = 4rGoFjChJLDAVExn1aRjLS
-----------------------------------------------------------------------------------------------------
MIGRATING INTO SPOTIFY
POST Create a playlist
Endpoint: /v1/users/{user_id}/playlists
This reuturns a playlist id which is stored for later purposes.
fetch("https://api.spotify.com/v1/users/ttx1gpej20552zpv12kplq0ky/playlists", {
"headers": {
"authorization": "Bearer {oath_token}"
},
"body": JSON.stringify({
"name": "Dummy Playlist",
"description": "New playlist description",
"public": false
}),
"method": "POST"
}).then((res) => res.json()).then(json => console.log(json));
Response playlist id: "1tRbFs2jQp7DXy96G8Fjna"
GET search for spotify track URI based on search query (searching based on artist and track name for now, and limiting search results to 2 to avoid noise)
Endpoint: /v1/search?q=track:{track_name}+artist:{artist_name}&type=tracks&limit={limit_value}
fetch("https://api.spotify.com/v1/search?q=track:thunder+artist:Imagine+Dragons&type=track&limit=2", {
"headers": {
"authorization": "Bearer {oath_token}",
},
"method": "GET",
}).then((res) => res.json()).then(json => console.log(json));
Response track URI: "spotify:track:1zB4vmk8tFRmM9UULNzbLB"
Response track URI for Alone(by marshmello): "spotify:track:3MEYFivt6bilQ9q9mFWZ4g"
POST add items to spotify playlist based on track URIs (Max 100 tracks can be added)
Endpoint: /v1/playlists/{playlist_id}/tracks
fetch("https://api.spotify.com/v1/playlists/1tRbFs2jQp7DXy96G8Fjna/tracks", {
"headers": {
"authorization": "Bearer {oath_token}"
},
"body": JSON.stringify({
"uris": ["spotify:track:1zB4vmk8tFRmM9UULNzbLB","spotify:track:3MEYFivt6bilQ9q9mFWZ4g"]
}),
"method": "POST"
}).then((res) => res.json()).then(json => console.log(json));