Search by

calliostro / php-discogs-api

calliostro

Lightweight Discogs API client for PHP 8.1+ with built-in resilience and minimal dependencies.

Package info

github.com/calliostro/php-discogs-api

pkg:composer/calliostro/php-discogs-api

Statistics

Installs: 8 638

Dependents: 1

Suggesters: 0

Stars: 9

Open Issues: 0

v4.1.0 2026-09-18 19:01 UTC

README

Package Version Total Downloads License PHP Version Guzzle CI Code Coverage PHPStan Level Code Style

A lightweight, modern PHP client for the Discogs API, supporting database queries, marketplace, user collection, wantlist, and full OAuth flows for PHP 8.1+.

๐Ÿ“ฆ Installation

composer require calliostro/php-discogs-api

Do You Need to Register?

For basic database access (artists, releases, labels): No registration needed

  • Install and start using basic endpoints immediately

For search and user features: Registration required

Symfony Integration

Symfony Users: For easier integration, there's also a Symfony Bundle available.

๐Ÿš€ Quick Start

Public Data (No Registration Needed)

use Calliostro\Discogs\DiscogsClientFactory;

$discogs = DiscogsClientFactory::create();

$artist = $discogs->getArtist(5590213);     // Billie Eilish
$release = $discogs->getRelease(19929817);  // Olivia Rodrigo - Sour
$label = $discogs->getLabel(2311);          // Interscope Records

Search with Consumer Credentials

use Calliostro\Discogs\DiscogsClientFactory;

$discogs = DiscogsClientFactory::createWithConsumerCredentials('key', 'secret');

// Positional parameters (traditional)
$results = $discogs->search('Billie Eilish', 'artist');
$releases = $discogs->listArtistReleases(4470662, 'year', 'desc', 50);

// Named parameters (PHP 8.0+, recommended for clarity)
$results = $discogs->search(q: 'Taylor Swift', type: 'release');
$releases = $discogs->listArtistReleases(
    artistId: 4470662,
    sort: 'year', 
    sortOrder: 'desc',
    perPage: 25
);

Your Collections (Personal Token)

use Calliostro\Discogs\DiscogsClientFactory;

$discogs = DiscogsClientFactory::createWithPersonalAccessToken('key', 'secret', 'token');

$collection = $discogs->listCollectionFolders('your-username');
$wantlist = $discogs->getUserWantlist('your-username');

// Add to the collection with named parameters
$discogs->addToCollection(
    username: 'your-username',
    folderId: 1,
    releaseId: 30359313
);

Multi-User Apps (OAuth 1.0a)

use Calliostro\Discogs\DiscogsClientFactory;

$discogs = DiscogsClientFactory::createWithOAuth('key', 'secret', 'oauth_token', 'oauth_secret');

$identity = $discogs->getIdentity();

โœจ Key Features

  • Simple Setup โ€“ Works immediately with public data, easy authentication for advanced features.
  • Complete API Coverage โ€“ All 60 Discogs API endpoints supported.
  • Built-in Resilience โ€“ Automatic retries on 429 rate limits and 503 Service Unavailable with exponential backoff and Retry-After header support.
  • Clean Parameter API โ€“ Natural method calls: getArtist(123) with named parameter support.
  • Lightweight Focus โ€“ Minimal codebase with only essential dependencies (Guzzle 7 or 8).
  • Modern PHP Comfort โ€“ Full IDE support, type safety, PHPStan Level 8 without bloat.
  • Secure Authentication โ€“ Full OAuth 1.0a and Personal Access Token support.
  • Battle-Tested โ€“ 100% test coverage, PSR-12 compliant.
  • Future-Ready โ€“ PHP 8.1โ€“8.6 compatible (beta/dev testing).
  • Pure Guzzle โ€“ Modern HTTP client, no custom transport layers.

๐ŸŽต All Discogs API Methods as Direct Calls

  • Database Methods โ€“ search(), getArtist(), listArtistReleases(), getRelease(), updateUserReleaseRating(), deleteUserReleaseRating(), getUserReleaseRating(), getCommunityReleaseRating(), getReleaseStats(), getMaster(), listMasterVersions(), getLabel(), listLabelReleases()
  • Marketplace Methods โ€“ getUserInventory(), getMarketplaceListing(), createMarketplaceListing(), updateMarketplaceListing(), deleteMarketplaceListing(), getMarketplaceFee(), getMarketplaceFeeByCurrency(), getMarketplacePriceSuggestions(), getMarketplaceStats(), getMarketplaceOrder(), getMarketplaceOrders(), updateMarketplaceOrder(), getMarketplaceOrderMessages(), addMarketplaceOrderMessage()
  • Inventory Export Methods โ€“ createInventoryExport(), listInventoryExports(), getInventoryExport(), downloadInventoryExport()
  • Inventory Upload Methods โ€“ addInventoryUpload(), changeInventoryUpload(), deleteInventoryUpload(), listInventoryUploads(), getInventoryUpload()
  • User Identity Methods โ€“ getIdentity(), getUser(), updateUser(), listUserSubmissions(), listUserContributions()
  • User Collection Methods โ€“ listCollectionFolders(), getCollectionFolder(), createCollectionFolder(), updateCollectionFolder(), deleteCollectionFolder(), listCollectionItems(), getCollectionItemsByRelease(), addToCollection(), updateCollectionItem(), removeFromCollection(), getCustomFields(), setCustomFields(), getCollectionValue()
  • User Wantlist Methods โ€“ getUserWantlist(), addToWantlist(), updateWantlistItem(), removeFromWantlist()
  • User Lists Methods โ€“ getUserLists(), getUserList()

All Discogs API endpoints are supported with clean documentation โ€” see Discogs API Documentation for complete method reference.

Note

Some endpoints require special permissions (seller accounts, data ownership).

๐Ÿ“‹ Requirements

  • PHP ^8.1
  • guzzlehttp/guzzle ^7.0 || ^8.0

โš™๏ธ Configuration

Rate Limiting & Retries

Discogs enforces rate limits (25 requests/min for unauthenticated requests, 60 requests/min for authenticated requests) and returns 429 Too Many Requests (or 503 Service Unavailable) when busy. By default (auto_retry => true, max_retries => 3), the client automatically retries 429 and 503 responses with intelligent exponential backoff and respects the Retry-After header.

You can customize or disable retries:

use Calliostro\Discogs\DiscogsClientFactory;

// Custom retry count
$discogs = DiscogsClientFactory::create([
    'auto_retry' => true,   // Automatically wait and retry on 429/503 (default: true)
    'max_retries' => 5,     // Maximum number of retry attempts (default: 3)
]);

// Disable automatic retries (e.g. in tests or to handle exceptions immediately)
$discogs = DiscogsClientFactory::create([
    'auto_retry' => false,
]);

Advanced (Custom Guzzle handler, timeouts, headers)

use Calliostro\Discogs\DiscogsClientFactory;

$discogs = DiscogsClientFactory::create([
    'timeout' => 30,
    'headers' => [
        'User-Agent' => 'MyApp/1.0 (+https://myapp.com)',
    ],
    'auto_retry' => true,
    'max_retries' => 3,
]);

Note

By default, the client uses DiscogsClient/4.1.0 +https://github.com/calliostro/php-discogs-api as User-Agent. You can override this by setting custom headers as shown above.

๐Ÿ” Authentication

Get credentials at Discogs Developer Settings.

Quick Reference

What you want to do Method What you need
Get artist/release info create() Nothing
Search the database createWithConsumerCredentials() Register app
Access your collection createWithPersonalAccessToken() Personal token
Multi-user app createWithOAuth() Full OAuth setup

Complete OAuth Flow Example

Step 1: authorize.php โ€“ Redirect user to Discogs

<?php
// authorize.php

use Calliostro\Discogs\OAuthHelper;

$consumerKey = 'your-consumer-key';
$consumerSecret = 'your-consumer-secret';
$callbackUrl = 'https://yourapp.com/callback.php';

$oauth = new OAuthHelper();
$requestToken = $oauth->getRequestToken($consumerKey, $consumerSecret, $callbackUrl);

$_SESSION['oauth_token'] = $requestToken['oauth_token'];
$_SESSION['oauth_token_secret'] = $requestToken['oauth_token_secret'];

$authUrl = $oauth->getAuthorizationUrl($requestToken['oauth_token']);
header("Location: {$authUrl}");
exit;

Step 2: callback.php โ€“ Handle Discogs callback

<?php
// callback.php

require __DIR__ . '/vendor/autoload.php';

use Calliostro\Discogs\{OAuthHelper, DiscogsClientFactory};

$consumerKey = 'your-consumer-key';
$consumerSecret = 'your-consumer-secret';
$verifier = $_GET['oauth_verifier'];

$oauth = new OAuthHelper();
$accessToken = $oauth->getAccessToken(
    $consumerKey,
    $consumerSecret,
    $_SESSION['oauth_token'],
    $_SESSION['oauth_token_secret'],
    $verifier
);

$oauthToken = $accessToken['oauth_token'];
$oauthSecret = $accessToken['oauth_token_secret'];

// Store tokens for future use
$_SESSION['oauth_token'] = $oauthToken;
$_SESSION['oauth_token_secret'] = $oauthSecret;

$discogs = DiscogsClientFactory::createWithOAuth($consumerKey, $consumerSecret, $oauthToken, $oauthSecret);
$identity = $discogs->getIdentity();
echo "Hello " . $identity['username'];

๐Ÿงช Development & Testing Guide

See DEVELOPMENT.md for detailed setup instructions, test suite commands, static analysis, and contribution guidelines.

๐Ÿค Contributing

Contributions are welcome! Please ensure all tests pass and coding standards are maintained:

composer cs-fix
composer analyse
composer test

๐Ÿ“„ License

MIT License โ€“ see the LICENSE file for details.

โš–๏ธ Disclaimer

Discogs is a registered trademark of Zink Media, LLC. This project is an independent, unofficial open-source library and is not affiliated with, endorsed by, or sponsored by Discogs or Zink Media, LLC.

๐Ÿ™ Acknowledgments