[GH-ISSUE #285] Unable to add parameters & headers to force results in English #213

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

Originally created by @darius00klokj on GitHub (Oct 2, 2025).
Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/285

Depending on the market one fetches from, you can get different artist names. So we need a way to specify the language in the getArtist function. Example: Artist "Noriko Kose" with ID: 13gezgXsLR3QZbKvi7Fc2K will return its Japanese name by default.

  ["name"]=>
  string(12) "巨勢典子"
  ["popularity"]=>
  int(18)
  ["type"]=>
  string(6) "artist"
  ["uri"]=>
  string(37) "spotify:artist:13gezgXsLR3QZbKvi7Fc2K"

I would like to be able to specify that the name should be in English Alphabet. Suggested changes:

from

public function getArtist($artistId)
{
        $artistId = $this->uriToId($artistId, 'artist');
        $uri = '/v1/artists/' . $artistId;

        $this->lastResponse = $this->sendRequest('GET', $uri);

        return $this->lastResponse['body'];
}

to

public function getArtist($artistId, $parameters = [], $headers = [])
{
        $artistId = $this->uriToId($artistId, 'artist');
        $uri = '/v1/artists/' . $artistId;

        $this->lastResponse = $this->sendRequest('GET', $uri, $parameters, $headers);

        return $this->lastResponse['body'];
}

This way I can add

$parameters = ['query' => ['market' => 'US']]; 
$headers = ['Accept-Language' => 'en-US'];

Output after test:


  ["name"]=>
  string(11) "Noriko Kose"
  ["popularity"]=>
  int(18)
  ["type"]=>
  string(6) "artist"
  ["uri"]=>
  string(37) "spotify:artist:13gezgXsLR3QZbKvi7Fc2K"
Originally created by @darius00klokj on GitHub (Oct 2, 2025). Original GitHub issue: https://github.com/jwilsson/spotify-web-api-php/issues/285 Depending on the market one fetches from, you can get different artist names. So we need a way to specify the language in the getArtist function. Example: Artist "Noriko Kose" with ID: 13gezgXsLR3QZbKvi7Fc2K will return its Japanese name by default. ``` ["name"]=> string(12) "巨勢典子" ["popularity"]=> int(18) ["type"]=> string(6) "artist" ["uri"]=> string(37) "spotify:artist:13gezgXsLR3QZbKvi7Fc2K" ``` I would like to be able to specify that the name should be in English Alphabet. Suggested changes: from ``` public function getArtist($artistId) { $artistId = $this->uriToId($artistId, 'artist'); $uri = '/v1/artists/' . $artistId; $this->lastResponse = $this->sendRequest('GET', $uri); return $this->lastResponse['body']; } ``` to ``` public function getArtist($artistId, $parameters = [], $headers = []) { $artistId = $this->uriToId($artistId, 'artist'); $uri = '/v1/artists/' . $artistId; $this->lastResponse = $this->sendRequest('GET', $uri, $parameters, $headers); return $this->lastResponse['body']; } ``` This way I can add ``` $parameters = ['query' => ['market' => 'US']]; $headers = ['Accept-Language' => 'en-US']; ``` Output after test: ``` ["name"]=> string(11) "Noriko Kose" ["popularity"]=> int(18) ["type"]=> string(6) "artist" ["uri"]=> string(37) "spotify:artist:13gezgXsLR3QZbKvi7Fc2K" ```
kerem 2026-02-27 19:26:37 +03:00
Author
Owner

@jwilsson commented on GitHub (Oct 6, 2025):

Hello!
I didn't know about passing Accept-Language to get results in other alphabets but I do think something like a default_headers option would be a better fit. Something like

$api = new SpotifyWebAPI\SpotifyWebAPI([
    'default_headers' => ['Accept-Language' => 'en-US'],
]);

$api->getArtist('spotify:artist:13gezgXsLR3QZbKvi7Fc2K');

That way you wouldn't have to extend every method with it. And it seems passing Accept-Language is enough, when I tested just passing that I get the expected English alphabet back. It doesn't look like the market option is supported when fetching artists.

<!-- gh-comment-id:3373231857 --> @jwilsson commented on GitHub (Oct 6, 2025): Hello! I didn't know about passing `Accept-Language` to get results in other alphabets but I do think something like a `default_headers` option would be a better fit. Something like ```php $api = new SpotifyWebAPI\SpotifyWebAPI([ 'default_headers' => ['Accept-Language' => 'en-US'], ]); $api->getArtist('spotify:artist:13gezgXsLR3QZbKvi7Fc2K'); ``` That way you wouldn't have to extend every method with it. And it seems passing `Accept-Language` is enough, when I tested just passing that I get the expected English alphabet back. [It doesn't look like](https://developer.spotify.com/documentation/web-api/reference/get-an-artist) the `market` option is supported when fetching artists.
Author
Owner

@jwilsson commented on GitHub (Oct 12, 2025):

Added a default_headers option in 6.3.0. Please let me know if it doesn't work!

<!-- gh-comment-id:3394005110 --> @jwilsson commented on GitHub (Oct 12, 2025): Added a `default_headers` option in `6.3.0`. Please let me know if it doesn't work!
Author
Owner

@darius00klokj commented on GitHub (Oct 23, 2025):

Thanks @jwilsson it works!

Sorry for the late reply.

<!-- gh-comment-id:3435933283 --> @darius00klokj commented on GitHub (Oct 23, 2025): Thanks @jwilsson it works! Sorry for the late reply.
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#213
No description provided.