calliostro/php-discogs-api

Ultra-lightweight Discogs API client for PHP 8.1+ with modern Guzzle-based implementation โ€” Only two classes, service descriptions, zero bloat

v4.0.0-beta.1 2025-09-10 22:53 UTC

README

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

๐Ÿš€ ONLY 2 CLASSES! The most lightweight Discogs API client for PHP. Zero bloat, maximum performance.

An ultra-minimalist Discogs API client that proves you don't need 20+ classes to build a great API client. Built with modern PHP 8.1+ features, service descriptions, and powered by Guzzle.

๐Ÿ“ฆ Installation

composer require calliostro/php-discogs-api

Important: You need to register your application at Discogs to get your credentials. For read-only access to public data, no authentication is required.

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

๐Ÿš€ Quick Start

Basic Usage

<?php

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

use Calliostro\Discogs\ClientFactory;

// Basic client for public data
$discogs = ClientFactory::create();

// Fetch artist information
$artist = $discogs->artistGet([
    'id' => '45031' // Pink Floyd
]);

$release = $discogs->releaseGet([
    'id' => '249504' // Nirvana - Nevermind
]);

echo "Artist: " . $artist['name'] . "\n";
echo "Release: " . $release['title'] . "\n";

Collection and Marketplace

<?php

// Authenticated client for protected operations
$discogs = ClientFactory::createWithToken('your-personal-access-token', 'MyApp/1.0');

// Collection management
$folders = $discogs->collectionFolders(['username' => 'your-username']);
$folder = $discogs->collectionFolderGet(['username' => 'your-username', 'folder_id' => '1']);
$items = $discogs->collectionItems(['username' => 'your-username', 'folder_id' => '0']);

// Add release to a collection
$addResult = $discogs->collectionAddRelease([
    'username' => 'your-username',
    'folder_id' => '1', 
    'release_id' => '249504'
]);

// Wantlist management
$wantlist = $discogs->wantlistGet(['username' => 'your-username']);
$addToWantlist = $discogs->wantlistAdd([
    'username' => 'your-username',
    'release_id' => '249504',
    'notes' => 'Looking for mint condition'
]);

// Marketplace operations
$inventory = $discogs->inventoryGet(['username' => 'your-username']);
$orders = $discogs->ordersGet(['status' => 'Shipped']);

// Create a marketplace listing
$listing = $discogs->listingCreate([
    'release_id' => '249504',
    'condition' => 'Near Mint (NM or M-)',
    'sleeve_condition' => 'Very Good Plus (VG+)',
    'price' => '25.00',
    'status' => 'For Sale'
]);

Database Search and Discovery

<?php

// Search the Discogs database
$results = $discogs->search(['q' => 'Pink Floyd', 'type' => 'artist']);
$releases = $discogs->artistReleases(['id' => '45031', 'sort' => 'year']);

// Master release versions
$master = $discogs->masterGet(['id' => '18512']);
$versions = $discogs->masterVersions(['id' => '18512']);

// Label information
$label = $discogs->labelGet(['id' => '1']); // Warp Records
$labelReleases = $discogs->labelReleases(['id' => '1']);

โœจ Key Features

  • Ultra-Lightweight โ€“ Only 2 classes, ~234 lines of logic + service descriptions
  • Complete API Coverage โ€“ All 60+ Discogs API endpoints supported
  • Direct API Calls โ€“ $client->artistGet() maps to /artists/{id}, no abstractions
  • Type Safe + IDE Support โ€“ Full PHP 8.1+ types, PHPStan Level 8, method autocomplete
  • Future-Ready โ€“ PHP 8.5 compatible (beta/dev testing)
  • Pure Guzzle โ€“ Modern HTTP client, no custom transport layers
  • Well Tested โ€“ 100% test coverage, PSR-12 compliant
  • Secure Authentication โ€“ Full OAuth and Personal Access Token support

๐ŸŽต All Discogs API Methods as Direct Calls

  • Database Methods โ€“ search(), artistGet(), artistReleases(), releaseGet(), releaseRatingGet(), releaseRatingPut(), releaseRatingDelete(), releaseRatingCommunity(), releaseStats(), masterGet(), masterVersions(), labelGet(), labelReleases()
  • User Identity Methods โ€“ identityGet(), userGet(), userEdit(), userSubmissions(), userContributions(), userLists()
  • Collection Methods โ€“ collectionFolders(), collectionFolderGet(), collectionFolderCreate(), collectionFolderEdit(), collectionFolderDelete(), collectionItems(), collectionItemsByRelease(), collectionAddRelease(), collectionEditRelease(), collectionRemoveRelease(), collectionCustomFields(), collectionEditField(), collectionValue()
  • Wantlist Methods โ€“ wantlistGet(), wantlistAdd(), wantlistEdit(), wantlistRemove()
  • Marketplace Methods โ€“ inventoryGet(), listingGet(), listingCreate(), listingUpdate(), listingDelete(), marketplaceFee(), marketplaceFeeCurrency(), marketplacePriceSuggestions(), marketplaceStats()
  • Order Methods โ€“ orderGet(), ordersGet(), orderUpdate(), orderMessages(), orderMessageAdd()
  • Inventory Export Methods โ€“ inventoryExportCreate(), inventoryExportList(), inventoryExportGet(), inventoryExportDownload()
  • Inventory Upload Methods โ€“ inventoryUploadAdd(), inventoryUploadChange(), inventoryUploadDelete(), inventoryUploadList(), inventoryUploadGet()
  • List Methods โ€“ listGet()

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

๐Ÿ“‹ Requirements

  • php ^8.1
  • guzzlehttp/guzzle ^6.5 || ^7.0

๐Ÿ”ง Advanced Configuration

Option 1: Simple Configuration (Recommended)

For basic customizations like timeout or User-Agent, use the ClientFactory:

<?php

use Calliostro\Discogs\ClientFactory;

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

Option 2: Advanced Guzzle Configuration

For advanced HTTP client features (middleware, interceptors, etc.), create your own Guzzle client:

<?php

use GuzzleHttp\Client;
use Calliostro\Discogs\DiscogsApiClient;

$httpClient = new Client([
    'timeout' => 30,
    'connect_timeout' => 10,
    'headers' => [
        'User-Agent' => 'MyApp/1.0 (+https://myapp.com)',
    ]
]);

// Direct usage
$discogs = new DiscogsApiClient($httpClient);

// Or via ClientFactory
$discogs = ClientFactory::create('MyApp/1.0', $httpClient);

๐Ÿ’ก Note: By default, the client uses DiscogsClient/3.0 (+https://github.com/calliostro/php-discogs-api) as User-Agent. You can override this by setting custom headers as shown above.

๐Ÿ” Authentication

Discogs supports different authentication flows:

Personal Access Token (Recommended)

For accessing your own account data, use a Personal Access Token from Discogs Developer Settings:

<?php

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

use Calliostro\Discogs\ClientFactory;

$discogs = ClientFactory::createWithToken('your-personal-access-token');

// Access protected endpoints
$identity = $discogs->identityGet();
$collection = $discogs->collectionFolders(['username' => 'your-username']);

OAuth 1.0a Authentication

For building applications that access user data on their behalf:

<?php

// You need to implement the OAuth flow to get these tokens
$discogs = ClientFactory::createWithOAuth('oauth-token', 'oauth-token-secret');

$identity = $discogs->identityGet();
$orders = $discogs->ordersGet();

๐Ÿ’ก Note: Implementing the complete OAuth flow is complex and beyond the scope of this README. For detailed examples, see the Discogs OAuth Documentation.

๐Ÿงช Testing

Run the test suite:

composer test

Run static analysis:

composer analyse

Check code style:

composer cs

๐Ÿ“š API Documentation Reference

For complete API documentation including all available parameters, visit the Discogs API Documentation.

Popular Methods

Database Methods

  • search($params) โ€“ Search the Discogs database
  • artistGet($params) โ€“ Get artist information
  • artistReleases($params) โ€“ Get artist's releases
  • releaseGet($params) โ€“ Get release information
  • masterGet($params) โ€“ Get master release information
  • masterVersions($params) โ€“ Get master release versions

Collection Methods

  • collectionFolders($params) โ€“ Get user's collection folders
  • collectionItems($params) โ€“ Get collection items by folder
  • collectionFolderGet($params) โ€“ Get specific collection folder

User Methods

  • identityGet($params) โ€“ Get authenticated user's identity (auth required)
  • userGet($params) โ€“ Get user profile information
  • wantlistGet($params) โ€“ Get user's wantlist

๐Ÿค Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please ensure your code follows PSR-12 standards and includes tests.

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

๐Ÿ™ Acknowledgments

โญ Star this repo if you find it useful! It helps others discover this lightweight solution.