[GH-ISSUE #212] Search Syntax Question #146

Closed
opened 2026-02-27 19:26:18 +03:00 by kerem · 2 comments
Owner

Originally created by @ghost on GitHub (Dec 20, 2020).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/212

Hi - firstly, thank you for writing this excellent repository.

I am working on the search part of the API, and this is my sample code:

$api = new SpotifyWebAPI\SpotifyWebAPI();
$api->setAccessToken($accessToken);

$options = ['offset' => 0,'limit' => 5,'year' => 2016];
$search = $api->search($str,'album', $options);

If I search for something, e.g. trees, and I check the 'href' attribute value that's returned by the API, it is this:

https://api.spotify.com/v1/search?query=trees&type=album&offset=0&limit=5

It seems that the Year part of the option array is ignored.

Am I doing something wrong? I searched the Closed Issues before raising this new issue.

I also tried setting the Year as a String as follows but get the same result:

$options = ['offset' => 0,'limit' => 5,'year' => '2016'];

Thanks

Originally created by @ghost on GitHub (Dec 20, 2020). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/212 Hi - firstly, thank you for writing this excellent repository. I am working on the search part of the API, and this is my sample code: ``` $api = new SpotifyWebAPI\SpotifyWebAPI(); $api->setAccessToken($accessToken); $options = ['offset' => 0,'limit' => 5,'year' => 2016]; $search = $api->search($str,'album', $options); ``` If I search for something, e.g. trees, and I check the 'href' attribute value that's returned by the API, it is this: `https://api.spotify.com/v1/search?query=trees&type=album&offset=0&limit=5` It seems that the Year part of the option array is ignored. Am I doing something wrong? I searched the Closed Issues before raising this new issue. I also tried setting the Year as a String as follows but get the same result: `$options = ['offset' => 0,'limit' => 5,'year' => '2016'];` Thanks
kerem 2026-02-27 19:26:18 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@jwilsson commented on GitHub (Dec 21, 2020):

Hi!
The "year" filter is passed with the actual query string, for example:

$str = $str . ' year:2016';
$search = $api->search($str,'album', $options);

The Spotify docs has more in-depth info, but don't worry about encoding spaces. The library will handle it for you.

Hope this helps!

<!-- gh-comment-id:748765631 --> @jwilsson commented on GitHub (Dec 21, 2020): Hi! The "year" filter is passed with the actual query string, for example: ```php $str = $str . ' year:2016'; $search = $api->search($str,'album', $options); ``` The [Spotify docs](https://developer.spotify.com/documentation/web-api/reference/search/search/#writing-a-query---guidelines) has more in-depth info, but don't worry about encoding spaces. The library will handle it for you. Hope this helps!
Author
Owner

@ghost commented on GitHub (Dec 21, 2020):

Hi Jonathan - that's a big help, thank you very much for your helpful reply, it's much appreciated :-)

<!-- gh-comment-id:748794226 --> @ghost commented on GitHub (Dec 21, 2020): Hi Jonathan - that's a big help, thank you very much for your helpful reply, it's much appreciated :-)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotify-web-api-php#146
No description provided.