A full featured Discogs API v2.0 client library
function(err, data, rateLimit)format for the callback
The global structure of
disconnect looks as follows:
require('disconnect') -> new Client() -> oauth()-> database()-> marketplace()-> user() -> collection()-> wantlist()-> util
Here are some basic usage examples that connect with the public API. Error handling has been left out for demonstrational purposes.
var Discogs = require'disconnect'Client;
Get the release data for a release with the id 176126.
var db = database;dbrelease176126console.logdata;;
Set your own custom User-Agent. This is optional as when omitted
disconnect will set a default one with the value
x.x.x is the installed version of
var dis = 'MyUserAgent/1.0';
Get page 2 of USER_NAME's public collection showing 75 releases. The second param is the collection folder ID where 0 is always the "All" folder.
var col = usercollection;colreleases'USER_NAME' 0 page: 2 per_page: 75console.logdata;;
User, artist and label profiles can be formatted in different ways:
disconnect defaults to
discogs, but the output format can be set for each client instance.
// Set the output format to HTMLvar dis = setConfigoutputFormat: 'html';
Just provide the client constructor with your preferred way of authentication.
// Authenticate by user tokenvar dis = userToken: 'YOUR_USER_TOKEN';// Authenticate by consumer key and secretvar dis =consumerKey: 'YOUR_CONSUMER_KEY'consumerSecret: 'YOUR_CONSUMER_SECRET';
The User-Agent can still be passed for authenticated calls.
var dis = 'MyUserAgent/1.0' userToken: 'YOUR_USER_TOKEN';
Below are the steps that involve getting a valid OAuth access token from Discogs. Note that in the following examples the
app variable is an Express instance to handle incoming HTTP requests.
appget'/authorize'var oAuth = oauth;oAuthgetRequestToken'YOUR_CONSUMER_KEY''YOUR_CONSUMER_SECRET'''// Persist "requestData" here so that the callback handler can// access it later after returning from the authorize urlresredirectrequestDataauthorizeUrl;;;
After redirection to the Discogs authorize URL in step 1, authorize the application.
appget'/callback'var oAuth = requestDataoauth;oAuthgetAccessTokenreqqueryoauth_verifier // Verification code sent back by Discogs// Persist "accessData" here for following OAuth callsressend'Received access token!';;;
Simply provide the constructor with the
accessData object persisted in step 3.
appget'/identity'var dis = accessData;disidentityressenddata;;;
Image requests themselves don't require authentication, but obtaining the image URLs through, for example, release data does.
var db = accessDatadatabase;dbrelease176126var url = dataimages0resource_url;dbimageurl// Data contains the raw binary image datarequire'fs'writeFilefile data 'binary'console.log'Image saved!';;;;