by ricbra

PHP 5.4 Implementation of the Discogs API

125 Stars 68 Forks Last release: about 6 years ago (v1.0.0) MIT License 101 Commits 14 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Discogs Api

Build Status Latest Stable Version Total Downloads License Quality

This library is a PHP 5.4 implementation of the Discogs API v2.0. The Discogs API is a REST-based interface. By using this library you don't have to worry about communicating with the API: all the hard work has already be done.

This API is build upon the shoulders of a giant: Guzzle 4.0. This is an absolutely awesome library.


This library is released under the MIT license. See the complete license in the LICENSE file.


Start by installing composer. Next do:

$ composer require ricbra/php-discogs-api


PHP >=5.4.0


Creating a new instance is as simple as:


Discogs requires that you supply a User-Agent. You can do this easily:

        'headers' => ['User-Agent' => 'your-app-name/0.1 +'],


Discogs doesn't like it when you hit their API at a too high connection rate. Use the ThrottleSubscriber to prevent getting errors or banned:

getHttpClient()->getEmitter()->attach(new Discogs\Subscriber\ThrottleSubscriber());


Discogs API allow to access protected endpoints with either a simple Discogs Auth Flow or a more advanced (and more complex) Oauth Flow

Discogs Auth

As stated in the Discogs Authentication documentation:

In order to access protected endpoints, you’ll need to register for either a consumer key and secret or user token, depending on your situation: - To easily access your own user account information, use a User token. - To get access to an endpoint that requires authentication and build 3rd party apps, use a Consumer Key and Secret.

With the Discogs Php API you can add your credentials to each request by adding a

key to your own defaults like this:
$client = ClientFactory::factory([
    'defaults' => [
        'query' => [
            'key' => 'my-key',
            'secret' => 'my-secret',


There are a lot of endpoints which require OAuth. Lucky for you using Guzzle this is peanuts. If you're having trouble obtaining the token and token_secret, please check out my example implementation.

 $consumerKey, // from Discogs developer page
    'consumer_secret' => $consumerSecret, // from Discogs developer page
    'token'           => $token['oauth_token'], // get this using a OAuth library
    'token_secret'    => $token['oauth_token_secret'] // get this using a OAuth library

$response = $client->search([ 'q' => 'searchstring' ]);


Another cool plugin is the History plugin:


$response = $client->search([ 'q' => 'searchstring' ]);

foreach ($history as $row) { print (string) $row['request']; print (string) $row['response']; }

More info and plugins

For more information about Guzzle and its plugins checkout the docs.

Perform a search:

Per august 2014 a signed OAuth request is required for this endpoint.

    'q' => 'Meagashira'
// Loop through results
foreach ($response['results'] as $result) {
// Pagination data

// Dump all data var_dump($response->toArray());

Get information about a label:

    'id' => 1

Get information about an artist:

    'id' => 1

Get information about a release:

    'id' => 1

echo $release['title']."\n";

Get information about a master release:

    'id' => 1

echo $master['title']."\n";

Get image

Discogs returns the full url to images so just use the internal client to get those:


$release = $client->getRelease([ 'id' => 1 ]); foreach ($release['images'] as $image) { $response = $client->getHttpClient()->get($image['uri']); // response code echo $response->getStatusCode(); // image blob itself echo $client->getHttpClient()->get($image['uri'])->getBody()->getContents(); }

User Collection

Authorization is required when

is not

Get collection folders

    'username' => 'example'

Get collection folder

    'username' => 'example',
    'folder_id' => 1

Get collection items by folder

    'username' => 'example',
    'folder_id' => 3


Further documentation can be found at the Discogs API v2.0 Documentation.


Implemented a missing call? PR's are welcome!

Bitdeli Badge

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.