C#.NET API for Discogs.com

Overview

Discogs.com is a searchable community-built database of music information. Discogs offers an interface to access contents programmatically. For detailed information about the Discogs.API have a look at the documentation. Please respect Discogs' terms of use.

Discogs.API supports a RESTful interface, cause all API methods are read-only you can access the API with HTTP-GET requests and get XML documents back. The URL has the following format (exemplarily):

http://www.discogs.com/release/2145?f=xml&api_key=########

You'll need an API-key to access that API. If you use that service using existing libraries or tools you not necessarily need to become a member of that community, but if you build your own application or want to use that API directly its recommended to join, members will get an individual key (for free). Furthermore the usage is limited to 5.000 requests per IP within a 24-hour period.

Getting the XML-Response

All data provided by the Discogs.API is request driven and comes in XML-format, an appropriate XML-schema you might find here, examples or known issues could be found within the Discogs help forum.

The API-response is GZIP-encoded, so client must send the "Accept-Encoding: gzip" header and unpack the received data, in .NET that could be done this way:

[...]
using System.IO;
using System.IO.Compression;
using System.Net;
using System.Text;

[...]

public static string GetResponse(string url) {

   WebClient wc = new WebClient();
   wc.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip");
   wc.Proxy = null;

   using(GZipStream stream = new GZipStream(
      wc.OpenRead(url), CompressionMode.Decompress, false)) {
         using (StreamReader reader = new StreamReader(stream)) {
            reader.ReadToEnd();
         }
   }
}

[...]

Setting the WebClient.Proxy-property to NULL was necessary, cause some proxy or router configurations do not relay that 'Accept-Encoding'-Header, if you open the URL with your web browser you should receive the XML-document correctly, if not, do also check you firewall settings, even with special filter rules my firewall software could not get convinced of cooperating, so I have to disable each time I access the Discogs.API.

If you have no further idea what goes wrong, you should enable the .NET-logging mechanism as described here.

Implementation

Motivated by the possibility to obtain Discogs' data in a structured way and postprocess it using .NET-technology this library was born in March, 2008.

I will upload the full source and some detailed documentation within the next days, so please be patient...