PHPackages                             gtgt/discogs-api-bundle - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. gtgt/discogs-api-bundle

ActiveSymfony-bundle[Authentication &amp; Authorization](/categories/authentication)

gtgt/discogs-api-bundle
=======================

Symfony Bundle providing a complete API client for Discogs.com v2.0 with OAuth 1.0a support

1.0.0(3w ago)00MITPHPPHP ^8.4

Since Jul 9Pushed 3w agoCompare

[ Source](https://github.com/gtgt/discogs-api-bundle)[ Packagist](https://packagist.org/packages/gtgt/discogs-api-bundle)[ RSS](/packages/gtgt-discogs-api-bundle/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (1)Dependencies (17)Versions (2)Used By (0)

Discogs API Bundle
==================

[](#discogs-api-bundle)

A Symfony Bundle providing a complete, type-safe API client for [Discogs.com v2.0 API](https://www.discogs.com/developers/) with OAuth 1.0a authentication support.

Features
--------

[](#features)

- ✅ Complete API coverage: Database (artists, releases, labels, masters), User Collections, Wantlists, Marketplace (listings, orders)
- ✅ Dual authentication: User-Token (simple) and OAuth 1.0a (full flow)
- ✅ Value-object models with proper types and immutability
- ✅ Pagination support with iterator interface
- ✅ Rate limit handling and automatic retry with exponential backoff
- ✅ Optional PSR-6 caching with per-endpoint TTL
- ✅ Event dispatching for extensibility (logging, monitoring)
- ✅ Symfony 8.0+ compatible, follows bundle best practices
- ✅ Comprehensive error handling with typed exceptions

Installation
------------

[](#installation)

```
composer require tamas-gere/discogs-api-bundle
```

### Register the bundle

[](#register-the-bundle)

For Symfony Flex projects (recommended): the bundle is auto-registered.

For manual registration, add to `config/bundles.php`:

```
return [
    // ...
    DiscogsApiBundle\DiscogsApiBundle::class => ['all' => true],
];
```

### Configure

[](#configure)

Copy configuration to your project:

```
cp vendor/tamas-gere/discogs-api-bundle/config/packages/discogs_api.yaml config/packages/discogs_api.yaml
```

Edit `config/packages/discogs_api.yaml`:

```
discogs_api:
    user_agent: 'MyApp/1.0'  # Required - unique identifier for your app

    # Option 1: Personal token (simplest)
    user_token:
        token: '%env(DISCOGS_USER_TOKEN)%'

    # Option 2: OAuth 1.0a (for multi-user apps)
    # oauth1:
    #     consumer_key: '%env(DISCOGS_CONSUMER_KEY)%'
    #     consumer_secret: '%env(DISCOGS_CONSUMER_SECRET)%'
```

Get your credentials from [Discogs Developer Settings](https://www.discogs.com/settings/developers).

Set environment variables in `.env`:

```
# Option 1 - Simple token
DISCOGS_USER_TOKEN=your_user_token_here

# Option 2 - OAuth app credentials
DISCOGS_CONSUMER_KEY=your_consumer_key
DISCOGS_CONSUMER_SECRET=your_consumer_secret
```

Usage
-----

[](#usage)

### Basic: Personal Token

[](#basic-personal-token)

```
// In controller or service
public function __construct(private DiscogsClient $discogsClient) {}

// Get a release
$release = $this->discogsClient->getRelease(12345);
echo $release->title;

// Search
$results = $this->discogsClient->search('Daft Punk', [
    'type' => 'artist',
    'per_page' => 10,
]);
foreach ($results as $result) {
    echo $result->title;
}

// Get your identity
$user = $this->discogsClient->getIdentity();

// Add to collection
$this->discogsClient->addToCollection('your_username', $releaseId, folderId: 0, rating: 5, notes: 'Want this');
```

### Advanced: OAuth 1.0a Flow

[](#advanced-oauth-10a-flow)

```
// Step 1: Redirect user to authorization
$authUrl = $this->generateUrl('discogs_api_oauth_request_token');
// Or call OAuthController::requestToken() directly
// User redirected to Discogs, authorizes app

// Step 2: Handle callback at route "discogs_api_oauth_callback"
// Controller receives token and verifier, exchanges for access token
// Store token credentials in database (user_id -> token, secret)

// Step 3: Configure with stored tokens
// In config/services.yaml:
discogs_api:
    oauth1:
        consumer_key: '%env(DISCOGS_CONSUMER_KEY)%'
        consumer_secret: '%env(DISCOGS_CONSUMER_SECRET)%'
        token: '%user.discogs_token%'  # stored per-user token
        token_secret: '%user.discogs_token_secret%'

// Now all API calls act on behalf of that user
$collection = $discogsClient->getCollection($username);
```

### OAuth Controller Routes (optional)

[](#oauth-controller-routes-optional)

Enable routes in `config/routes.yaml`:

```
discogs_api_oauth:
    resource: '@DiscogsApiBundle/Controller/OAuthController.php'
    type: annotation
```

Routes:

- `GET /oauth/request-token` - Get request token &amp; redirect to Discogs
- `GET /oauth/callback` - OAuth callback from Discogs
- `GET /oauth/token` - Inspect current session's token
- `POST /oauth/logout` - Clear OAuth session

### Services

[](#services)

Inject any service individually:

```
use DiscogsApiBundle\Service\ArtistService;

public function __construct(private ArtistService $artistService) {}

$artist = $this->artistService->getArtist(12345);
$releases = $this->artistService->getArtistReleases(12345, ['per_page' => 20]);
```

Available services:

- `ArtistService` - artists, artist releases, search (artists)
- `ReleaseService` - releases, ratings, stats
- `MasterService` - master releases, versions
- `LabelService` - labels, label releases
- `UserService` - user identity, user profiles
- `CollectionService` - folders, collection CRUD, ratings
- `WantlistService` - wantlist CRUD
- `MarketplaceService` - listings CRUD, orders, messages
- `InventoryService` - inventory listings CRUD
- `OrderService` - order management, messages
- `SearchService` - full-text search across all types

### Pagination

[](#pagination)

List methods return `PaginatedResponse`:

```
$paginated = $discogsClient->getCollection('username');
foreach ($paginated as $item) {
    // Iterate items
}
echo $paginated->count();       // items on current page
echo $paginated->getPage();     // current page
echo $paginated->getPages();    // total pages
if ($paginated->hasNextPage()) {
    $page = $paginated->getNextPage();
}
```

### Error Handling

[](#error-handling)

All API errors throw exceptions:

```
use DiscogsApiBundle\Exception\{
    DiscogsApiException,
    RateLimitException,
    AuthenticationException,
    NotFoundException,
    ValidationException
};

try {
    $release = $discogsClient->getRelease(999999999);
} catch (NotFoundException $e) {
    // 404 - resource not found
} catch (AuthenticationException $e) {
    // 401/403 - check your token/keys
} catch (RateLimitException $e) {
    // 429 - rate limit exceeded
    $retryAfter = $e->getRetryAfter();
} catch (DiscogsApiException $e) {
    // other API errors
}
```

### Caching (optional)

[](#caching-optional)

Enable caching in config:

```
discogs_api:
    cache:
        enabled: true
        pool: 'cache.app'  # any PSR-6 pool
        ttl:
            artists: 86400   # 24h
            releases: 43200  # 12h
```

Cache keys are auto-purged on write operations (add/remove collection, create/update listing).

### Events (optional)

[](#events-optional)

Subscribe to events for logging/metrics:

```
use DiscogsApiBundle\Event\{
    RequestBeforeEvent,
    ResponseEvent,
    ErrorEvent,
    RateLimitEvent
};
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class LoggingSubscriber implements EventSubscriberInterface
{
    public static function getSubscribedEvents(): array
    {
        return [
            'discogs_api.request.before' => 'onRequestBefore',
            'discogs_api.request.after' => 'onRequestAfter',
            'discogs_api.error' => 'onError',
            'discogs_api.rate_limit.exceeded' => 'onRateLimit',
        ];
    }

    public function onRequestBefore(RequestBeforeEvent $event): void
    {
        // Log outgoing request
    }

    public function onError(ErrorEvent $event): void
    {
        // Log errors
    }
}
```

Testing
-------

[](#testing)

### Unit Tests

[](#unit-tests)

```
vendor/bin/phpunit tests/Unit
```

### Integration Tests (live API)

[](#integration-tests-live-api)

By default, live tests are skipped. To run:

```
# Using env var
DISCOGS_TEST_LIVE=1 vendor/bin/phpunit tests/Integration

# Or with --live flag (if using custom test runner)
vendor/bin/phpunit --group live --live
```

Configuration for live tests in `phpunit.xml.dist`:

```

```

Rate Limits
-----------

[](#rate-limits)

Discogs enforces rate limits:

- Unauthenticated: 60 requests/minute
- Authenticated: 5000 requests/minute

The bundle automatically tracks `X-Ratelimit-Remaining` and can retry on 429 with `retry_on_rate_limit: true`. Configure `max_retries` for resilience.

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

[](#contributing)

Contributions welcome! Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) file.

Resources
---------

[](#resources)

- [Discogs API Docs](https://www.discogs.com/developers/)
- [Symfony Bundle Best Practices](https://symfony.com/doc/current/bundles.html)
- [OAuth 1.0 Client](https://github.com/thephpleague/oauth1-client)
- [Report Issues](https://github.com/your-username/discogs-api-bundle/issues)

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance95

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

21d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6842308?v=4)[GT](/maintainers/gt)[@gt](https://github.com/gt)

---

Top Contributors

[![gtgt](https://avatars.githubusercontent.com/u/788449?v=4)](https://github.com/gtgt "gtgt (1 commits)")

---

Tags

apiclientsymfonybundleoauthdiscogs

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/gtgt-discogs-api-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/gtgt-discogs-api-bundle/health.svg)](https://phpackages.com/packages/gtgt-discogs-api-bundle)
```

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.9M405](/packages/easycorp-easyadmin-bundle)[chameleon-system/chameleon-base

The Chameleon System core.

1028.7k5](/packages/chameleon-system-chameleon-base)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M608](/packages/shopware-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M215](/packages/sulu-sulu)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k64](/packages/open-dxp-opendxp)[simplesamlphp/simplesamlphp

A PHP implementation of a SAML 2.0 service provider and identity provider.

1.1k13.0M223](/packages/simplesamlphp-simplesamlphp)

PHPackages © 2026

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