Skip to content

Commit 07a1de0

Browse files
committed
Correct SpotifyWebAPI::addMy* request bodies
1 parent 482508d commit 07a1de0

File tree

2 files changed

+31
-15
lines changed

2 files changed

+31
-15
lines changed

src/SpotifyWebAPI.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ protected function uriToId(string|array $uriIds, string $type): string|array
187187
public function addMyAlbums(string|array $albums): bool
188188
{
189189
$albums = $this->uriToId($albums, 'album');
190-
$albums = json_encode((array) $albums);
190+
$albums = json_encode([
191+
'ids' => (array) $albums,
192+
]);
191193

192194
$headers = [
193195
'Content-Type' => 'application/json',
@@ -211,7 +213,9 @@ public function addMyAlbums(string|array $albums): bool
211213
public function addMyEpisodes(string|array $episodes): bool
212214
{
213215
$episodes = $this->uriToId($episodes, 'episode');
214-
$episodes = json_encode((array) $episodes);
216+
$episodes = json_encode([
217+
'ids' => (array) $episodes,
218+
]);
215219

216220
$headers = [
217221
'Content-Type' => 'application/json',
@@ -235,7 +239,9 @@ public function addMyEpisodes(string|array $episodes): bool
235239
public function addMyShows(string|array $shows): bool
236240
{
237241
$shows = $this->uriToId($shows, 'show');
238-
$shows = json_encode((array) $shows);
242+
$shows = json_encode([
243+
'ids' => (array) $shows,
244+
]);
239245

240246
$headers = [
241247
'Content-Type' => 'application/json',
@@ -259,7 +265,9 @@ public function addMyShows(string|array $shows): bool
259265
public function addMyTracks(string|array $tracks): bool
260266
{
261267
$tracks = $this->uriToId($tracks, 'track');
262-
$tracks = json_encode((array) $tracks);
268+
$tracks = json_encode([
269+
'ids' => (array) $tracks,
270+
]);
263271

264272
$headers = [
265273
'Content-Type' => 'application/json',

tests/SpotifyWebAPITest.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ public function testAddMyAlbums()
140140
];
141141

142142
$expected = json_encode([
143-
'1oR3KrPIp4CbagPa3PhtPp',
144-
'6lPb7Eoon6QPbscWbMsk6a',
145-
'1oR3KrPIp4CbagPa3PhtPp',
143+
'ids' => [
144+
'1oR3KrPIp4CbagPa3PhtPp',
145+
'6lPb7Eoon6QPbscWbMsk6a',
146+
'1oR3KrPIp4CbagPa3PhtPp',
147+
],
146148
]);
147149

148150
$headers = ['Content-Type' => 'application/json'];
@@ -169,9 +171,11 @@ public function testAddMyEpisodes()
169171
];
170172

171173
$expected = json_encode([
172-
'0zov0kd6MA3BqT1FKpOeYO',
173-
'3pLx6LaVQbWl5IfW8nxq56',
174-
'6kSGLgKWhBg8AoCzylVfc2',
174+
'ids' => [
175+
'0zov0kd6MA3BqT1FKpOeYO',
176+
'3pLx6LaVQbWl5IfW8nxq56',
177+
'6kSGLgKWhBg8AoCzylVfc2',
178+
],
175179
]);
176180

177181
$headers = ['Content-Type' => 'application/json'];
@@ -197,8 +201,10 @@ public function testAddMyShows()
197201
];
198202

199203
$expected = json_encode([
200-
'2C6ups0LMt1G8n81XLlkbsPo',
201-
'5AvwZVawapvyhJUIx71pdJ',
204+
'ids' => [
205+
'2C6ups0LMt1G8n81XLlkbsPo',
206+
'5AvwZVawapvyhJUIx71pdJ',
207+
],
202208
]);
203209

204210
$headers = ['Content-Type' => 'application/json'];
@@ -225,9 +231,11 @@ public function testAddMyTracks()
225231
];
226232

227233
$expected = json_encode([
228-
'1id6H6vcwSB9GGv9NXh5cl',
229-
'3mqRLlD9j92BBv1ueFhJ1l',
230-
'1id6H6vcwSB9GGv9NXh5cl',
234+
'ids' => [
235+
'1id6H6vcwSB9GGv9NXh5cl',
236+
'3mqRLlD9j92BBv1ueFhJ1l',
237+
'1id6H6vcwSB9GGv9NXh5cl',
238+
],
231239
]);
232240

233241
$headers = ['Content-Type' => 'application/json'];

0 commit comments

Comments
 (0)