PHPackages                             ngiraud/spotify-sdk-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ngiraud/spotify-sdk-php

ActiveLibrary[API Development](/categories/api)

ngiraud/spotify-sdk-php
=======================

SDK for using Spotify in PHP

1.0.4(2y ago)2112[2 PRs](https://github.com/ngiraud/spotify-sdk-php/pulls)MITPHPPHP ^8.1

Since Jun 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ngiraud/spotify-sdk-php)[ Packagist](https://packagist.org/packages/ngiraud/spotify-sdk-php)[ Docs](https://github.com/ngiraud/spotify-sdk-php)[ GitHub Sponsors](https://github.com/ngiraud)[ RSS](/packages/ngiraud-spotify-sdk-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (8)Used By (0)

SDK for using Spotify in PHP
============================

[](#sdk-for-using-spotify-in-php)

[![Latest Version on Packagist](https://camo.githubusercontent.com/22b4db63d36b204183e01f421b3c78f8a36aa03ee6f8b3ca300670676e56783d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6769726175642f73706f746966792d73646b2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ngiraud/spotify-sdk-php)[![Tests](https://camo.githubusercontent.com/326e6eb9f1bb4be804ce97651c05d2e7339ca76d0fffd34346c18eb591b4b67d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6e6769726175642f73706f746966792d73646b2d7068702f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/ngiraud/spotify-sdk-php/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/b0f9de0316956b0ff384a3b73e8ad5fa56d0dcb850e3041ae8203fadad842f30/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6769726175642f73706f746966792d73646b2d7068702e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ngiraud/spotify-sdk-php)

This package contains the PHP SDK to work with the [Spotify Web API](https://developer.spotify.com/documentation/web-api).

Table of Contents
-----------------

[](#table-of-contents)

- [Get Started](#get-started)
- [Usage](#usage)
    - [Handling Pagination](#handling-pagination)
    - [Albums Resource](#albums-resource)
    - [Artists Resource](#artists-resource)
    - [Audiobooks Resource](#audiobooks-resource)
    - [Categories Resource](#categories-resource)
    - [Chapters Resource](#chapters-resource)
    - [Episodes Resource](#episodes-resource)
    - [Genres Resource](#genres-resource)
    - [Markets Resource](#markets-resource)
    - [Player Resource](#player-resource)
    - [Playlists Resource](#playlists-resource)
    - [Search Resource](#search-resource)
    - [Shows Resource](#shows-resource)
    - [Tracks Resource](#tracks-resource)
    - [Users Resource](#users-resource)
- [Testing](#testing)
- [Linting](#linting)
- [Changelog](#changelog)
- [Contributing](#contributing)
- [Security Vulnerabilities](#security-vulnerabilities)
- [Credits](#credits)
- [License](#license)

Get Started
-----------

[](#get-started)

> **Requires [PHP 8.1+](https://php.net/releases/)**

First, install the client via the [Composer](https://getcomposer.org/) package manager:

```
composer require ngiraud/spotify-sdk-php
```

You must also install Guzzle if your project does not already have a it integrated:

```
composer require guzzlehttp/guzzle
```

In order to use the SDK, you need to request an access\_token. You can get an example from the [Spotify Web API docs](https://developer.spotify.com/documentation/web-api/tutorials/code-flow).

If you use Laravel, you can use [Socialite](https://laravel.com/docs/10.x/socialite) and the adapter provided by the community on [their website](https://socialiteproviders.com/Spotify/).

Below is an example on how to authenticate with Laravel Socialite.

```
Route::get('/spotify/redirect', function () {
    return Socialite::driver('spotify')
                    ->scopes([
                    // the list of scopes you want to allow
                    ])
                    ->redirect();
});

Route::get('/spotify/callback', function () {
    $user = Socialite::driver('spotify')->user();

    return $user->token;
});
```

You can now interact with Spotify's API:

```
use Spotify\Spotify;

$client = Spotify::client('');

$album = $client->albums()->find('', ['market' => 'FR']);
```

You can also use the [Client Credentials flow](https://developer.spotify.com/documentation/web-api/tutorials/client-credentials-flow) to authenticate:

```
use Spotify\Spotify;

$client = Spotify::basic('', '');

$seeds = $client->genres()->seeds();
```

Please keep in mind that only endpoints that do not access user information can be accessed using this particular authentication flow.

Usage
-----

[](#usage)

### Handling Pagination

[](#handling-pagination)

On some resources, some methods such as `findMultiple` will return an instance of `Spotify\Support\PaginatedResults`. This instance returns a list of records, and can handle other things like fetch the next or previous page of results.

#### Available methods

[](#available-methods)

- `results()`
- `links()`
- `previousUrl()`
- `nextUrl()`
- `previous()`
- `next()`
- `meta()`
- `total()`

### `Albums` Resource

[](#albums-resource)

You can access the Albums resource via the `albums` method from the client.

#### Available methods:

[](#available-methods-1)

- `find()`
- `findMultiple()`
- `tracks()`
- `findSaved()`
- `save()`
- `deleteSaved()`
- `checkSaved()`
- `newReleases()`

#### Example

[](#example)

```
// Returns an instance of Spotify\SingleObjects\Album
$album = $client->albums()->find('');
echo $album->name;

// Returns an instance of Spotify\Support\PaginatedResults
$tracks = $client->albums()->tracks('', ['market' => 'FR', 'limit' => 5]);
echo $tracks->results();
```

### `Artists` Resource

[](#artists-resource)

You can access the Artists resource via the `artists` method from the client.

#### Available methods:

[](#available-methods-2)

- `find()`
- `findMultiple()`
- `albums()`
- `topTracks()`
- `relatedArtists()`

#### Example

[](#example-1)

```
// Returns an instance of Spotify\SingleObjects\Artist
$artist = $client->artists()->find('');
echo $artist->name;

// Returns an instance of Spotify\Support\PaginatedResults
$albums = $client->artists()->albums('', ['market' => 'FR', 'limit' => 5]);
echo $albums->results();
```

### `Audiobooks` Resource

[](#audiobooks-resource)

> **Note: Audiobooks are only available for the US, UK, Ireland, New Zealand and Australia markets.**

You can access the Audiobooks resource via the `audiobooks` method from the client.

#### Available methods:

[](#available-methods-3)

- `find()`
- `findMultiple()`
- `chapters()`
- `findSaved()`
- `save()`
- `deleteSaved()`
- `checkSaved()`

#### Example

[](#example-2)

```
// Returns an instance of Spotify\SingleObjects\Audiobook
$audiobook = $client->audiobooks()->find('');
echo $audiobook->name;

// Returns an instance of Spotify\Support\PaginatedResults
$chapters = $client->audiobooks()->chapters('', ['limit' => 5]);
echo $chapters->results();
```

### `Categories` Resource

[](#categories-resource)

You can access the Categories resource via the `categories` method from the client.

#### Available methods:

[](#available-methods-4)

- `find()`
- `browse()`

#### Example

[](#example-3)

```
// Returns an instance of Spotify\SingleObjects\Category
$category = $client->categories()->find('');
echo $category->name;

// Returns an instance of Spotify\Support\PaginatedResults
$categories = $client->categories()->browse();
echo $categories->results();
```

### `Chapters` Resource

[](#chapters-resource)

You can access the Chapters resource via the `chapters` method from the client.

#### Available methods:

[](#available-methods-5)

- `find()`
- `findMultiple()`

#### Example

[](#example-4)

```
// Returns an instance of Spotify\SingleObjects\Category
$chapter = $client->chapters()->find('');
echo $chapter->name;

// Returns an instance of Spotify\Support\PaginatedResults
$chapters = $client->chapters()->browse();
echo $chapters->results();
```

### `Episodes` Resource

[](#episodes-resource)

You can access the Episodes resource via the `episodes` method from the client.

#### Available methods:

[](#available-methods-6)

- `find()`
- `findMultiple()`
- `findSaved()`
- `save()`
- `deleteSaved()`
- `checkSaved()`

#### Example

[](#example-5)

```
// Returns an instance of Spotify\SingleObjects\Episode
$episode = $client->episodes()->find('');
echo $episode->name;

// Returns an array with the status for each episode
$episodes = $client->episodes()->checkSaved(['', '']);
echo $episodes;
```

### `Genres` Resource

[](#genres-resource)

You can access the Genres resource via the `genres` method from the client.

#### Available methods:

[](#available-methods-7)

- `seeds()`

#### Example

[](#example-6)

```
// Returns an array of genres
$seeds = $client->genres()->seeds();
echo $seeds;
```

### `Markets` Resource

[](#markets-resource)

You can access the Markets resource via the `markets` method from the client.

#### Available methods:

[](#available-methods-8)

- `all()`

#### Example

[](#example-7)

```
// Returns an array of markets
$markets = $client->markets()->all();
echo $markets;
```

### `Player` Resource

[](#player-resource)

You can access the Player resource via the `player` method from the client.

#### Available methods:

[](#available-methods-9)

- `state()`
- `transfer()`
- `availableDevices()`
- `currentlyPlayingTrack()`
- `start()`
- `pause()`
- `next()`
- `previous()`
- `seek()`
- `repeat()`
- `volume()`
- `shuffle()`
- `recentlyPlayedTracks()`
- `queue()`
- `addToQueue()`

#### Example

[](#example-8)

```
// Returns an instance of Spotify\SingleObjects\Player
$player = $client->player()->state();
echo $player->is_playing;
```

### `Playlists` Resource

[](#playlists-resource)

You can access the Playlists resource via the `playlists` method from the client.

#### Available methods:

[](#available-methods-10)

- `find()`
- `forCurrentUser()`
- `forUser()`
- `create()`
- `update()`
- `tracks()`
- `reorderTracks()`
- `replaceTracks()`
- `addTracks()`
- `deleteTracks()`
- `featured()`
- `forCategory()`
- `coverImage()`
- `addCoverImage()`

#### Example

[](#example-9)

```
// Returns an instance of Spotify\SingleObjects\Playlist
$playlist = $client->playlists()->find('');
echo $playlist->name;

// Returns an instance of Spotify\Support\PaginatedResults
$playlists = $client->playlists()->forCategory('');
echo $playlists->results();
```

### `Search` Resource

[](#search-resource)

You can access the Search resource via the `search` method from the client. The search method will return an instance of `Spotify\SingleObjects\Search`, and every type of results is accessible via its own method. This end method will return an instance of `Spotify\Support\PaginatedResults`.

#### Available methods after the search

[](#available-methods-after-the-search)

- `audiobooks()`
- `albums()`
- `artists()`
- `episodes()`
- `playlists()`
- `shows()`
- `tracks()`

#### Example

[](#example-10)

```
// Returns an instance of Spotify\SingleObjects\Search
$results = $client->search('alice cooper', 'artist');

// $results->artists() is an instance of Spotify\Support\PaginatedResults
// $artist is an instance of Spotify\SingleObjects\Artist
foreach ($results->artists() as $artist) {
    echo $artist->name;
}
```

### `Shows` Resource

[](#shows-resource)

You can access the Shows resource via the `shows` method from the client.

#### Available methods:

[](#available-methods-11)

- `find()`
- `findMultiple()`
- `episodes()`
- `findSaved()`
- `save()`
- `deleteSaved()`
- `checkSaved()`

#### Example

[](#example-11)

```
// Returns an instance of Spotify\SingleObjects\Show
$show = $client->shows()->find('');
echo $show->name;

// Returns an instance of Spotify\Support\PaginatedResults
$episodes = $client->shows()->episodes('');
echo $episodes->results();
```

### `Tracks` Resource

[](#tracks-resource)

You can access the Tracks resource via the `tracks` method from the client.

#### Available methods:

[](#available-methods-12)

- `find()`
- `findMultiple()`
- `findSaved()`
- `save()`
- `deleteSaved()`
- `checkSaved()`
- `audioFeatures()`
- `audioAnalysis()`
- `recommendations()`

#### Example

[](#example-12)

```
// Returns an instance of Spotify\SingleObjects\Track
$track = $client->tracks()->find('');
echo $track->name;

// Returns an instance of Spotify\Support\PaginatedResults
$recommendedTracks = $client->tracks()->recommendations();
echo $recommendedTracks->results();
```

### `Users` Resource

[](#users-resource)

You can access the Users resource via the `users` method from the client.

#### Available methods:

[](#available-methods-13)

- `me()`
- `profile()`
- `topArtists()`
- `topTracks()`
- `topItems()`
- `followPlaylist()`
- `unfollowPlaylist()`
- `followingPlaylist()`
- `followedArtists()`
- `followArtists()`
- `followUsers()`
- `followArtistsOrUsers()`
- `unfollowArtists()`
- `unfollowUsers()`
- `unfollowArtistsOrUsers()`
- `followingArtists()`
- `followingUsers()`
- `followingArtistsOrUsers()`

#### Example

[](#example-13)

```
// Returns an instance of Spotify\SingleObjects\User
$me = $client->users()->me();
echo $me->display_name;
```

Testing
-------

[](#testing)

```
composer test
composer phpstan
```

Linting
-------

[](#linting)

```
composer pint
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

This package is inspired by the [OpenAI PHP](https://github.com/openai-php/client) client package made by Nuno Maduro and Sandro Gehri and the [Mailcoach API SDK](https://github.com/spatie/mailcoach-sdk-php) from Spatie.

- [Nicolas Giraud](https://github.com/ngiraud)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance27

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~7 days

Total

5

Last Release

1023d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5f1390490804d12c3c901ecee03043b1627cb837f3af1fcd1e2e9c89ac576d5?d=identicon)[ngiraud](/maintainers/ngiraud)

---

Top Contributors

[![ngiraud](https://avatars.githubusercontent.com/u/12152071?v=4)](https://github.com/ngiraud "ngiraud (41 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")

---

Tags

phpapiclientsdkspotifymusic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ngiraud-spotify-sdk-php/health.svg)

```
[![Health](https://phpackages.com/badges/ngiraud-spotify-sdk-php/health.svg)](https://phpackages.com/packages/ngiraud-spotify-sdk-php)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[kunalvarma05/dropbox-php-sdk

Dropbox PHP API V2 SDK (Unofficial)

3633.0M18](/packages/kunalvarma05-dropbox-php-sdk)[resend/resend-php

Resend PHP library.

564.7M21](/packages/resend-resend-php)[mozex/anthropic-laravel

Anthropic PHP for Laravel is a supercharged PHP API client that allows you to interact with the Anthropic API

71226.4k1](/packages/mozex-anthropic-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
