PHP code example of calliostro / php-discogs-api

1. Go to this page and download the library: Download calliostro/php-discogs-api library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

calliostro / php-discogs-api example snippets




alliostro\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";



// 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'
]);



// 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']);



use Calliostro\Discogs\ClientFactory;

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



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);



alliostro\Discogs\ClientFactory;

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

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



// 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();
bash
composer 
bash
composer analyse