- How do I install and use calliostro/php-discogs-api in a Laravel app?
- Install it with composer require calliostro/php-discogs-api. For public artist, release, and label data you can call DiscogsClientFactory::create() immediately without any credentials. In Laravel, bind the client as a singleton in a service provider so it can be resolved and injected anywhere. Configuration values such as consumer keys and tokens should live in config/services.php and .env.
- Do I need Discogs API credentials to use this package?
- No registration is required for basic database access such as artists, releases, and labels, so you can start querying public endpoints right after installing. Search, collections, wantlists, and marketplace features do require an application registered at Discogs. Those features need a consumer key and secret, plus OAuth 1.0a tokens for user-specific actions.
- Which PHP and Laravel versions does this Discogs API client support?
- The package requires PHP 8.1 or newer and is fully type-safe across PHP 8.1 to 8.5. It is built on Guzzle 6.5 or 7.0 and has been tested with Laravel 10 and above. Older Laravel versions are not part of the supported matrix, so upgrade before adopting it in legacy projects.
- How do I authenticate with Discogs using OAuth 1.0a in Laravel?
- Create the client through DiscogsClientFactory using an array of consumer_key, consumer_secret, token, and token_secret values. Keep those secrets in your .env file or a secure vault rather than committing them to source control. The package is OAuth 1.0a compliant, which is required for user-specific operations like collections and marketplace listings. You can wrap the factory call in a dedicated DiscogsAuthService if you need finer control over token handling.
- Is there a Laravel service provider or bundle for this package?
- There is no official Laravel service provider, but the client is simple enough to register manually in your AppServiceProvider using the service container. A Symfony bundle is available separately at calliostro/discogs-bundle for Symfony projects. In Laravel, a singleton binding that reads config('services.discogs') is the recommended pattern.
- How do I mock the Discogs client in Laravel PHPUnit tests?
- Because DiscogsClient is a concrete, type-hinted class, you can mock it with PHPUnit's createMock(DiscogsClient::class) and bind the mock into Laravel's container for feature tests. For lower-level HTTP assertions, pass a Guzzle HandlerStack with a MockHandler to simulate Discogs responses. This lets you test rate-limit errors, expired tokens, and malformed payloads without hitting the live API.
- Can I manage Discogs collections, wantlists, and marketplace listings with this client?
- Yes, but those endpoints require consumer credentials and OAuth 1.0a tokens because they act on behalf of a user. The client exposes verb-first methods such as createMarketplaceListing and collection-related calls that map directly to the Discogs API. Public data such as artist and release lookups works without any authentication.
- How should I handle Discogs rate limits and API errors in production?
- The client is Guzzle-based and includes built-in resilience, so you can configure retry and timeout behaviour through the underlying HTTP handler. Wrap calls in try/catch blocks and push bulk or slow operations into Laravel queue jobs so a failed request does not block a user request. Log failures with context and consider a fallback response or cached data when Discogs is unavailable.
- What are the alternatives to this Discogs API client for PHP?
- Most alternatives are heavier wrappers that add abstraction layers or bundle framework-specific code. This package deliberately stays minimal at roughly 750 lines across two core classes, mapping directly to Discogs endpoints with full PHPStan level 8 type safety. Choose it when you want IDE autocomplete, low maintenance overhead, and no bloat in a Laravel or microservice codebase.
- What breaking changes are in v4.0.0 and how do I migrate?
- Version 4.0.0 is a full overhaul with verb-first method names, so calls such as findArtistReleases become listArtistReleases across more than 60 endpoints. An UPGRADE.md guide is included to help you run regex or IDE-based search-and-replace refactors. Plan to update your composer constraint, refactor method calls, migrate authentication to OAuth 1.0a, and validate all critical paths with your test suite.