Difference between revisions of "MusicBrainz API/XML"

From MusicBrainz Wiki
m (Areas don't have ratings)
(Redirected page to MusicBrainz API)
(Tag: New redirect)
(9 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<small>[[Products]] > XML Web Service Version 2</small>
#REDIRECT [[MusicBrainz API]]
The web service discussed in this document is an interface to the [[MusicBrainz Database]]. It is aimed at developers of media players, CD rippers, taggers, and other applications requiring music metadata. The service's architecture follows the REST design principles. Interaction with the web service is done using HTTP and all content is served in a simple but flexible '''XML''' format.
The same web service is also available in [[Development/JSON_Web_Service|JSON format]].
==Before getting started==
The web service root URL is <code><nowiki>https://musicbrainz.org/ws/2/</nowiki></code>.
We have 12 resources on our web service which represent core [[Entity|entities]] in our database:
  area, artist, event, instrument, label, place, recording, release, release-group, series, work, url
We also provide a web service interface for the following non-core resources:
  rating, tag, collection
And we allow you to perform lookups based on other unique identifiers with these resources:
  discid, isrc, iswc
On each entity resource, you can perform three different GET requests:
  lookup:  /<ENTITY>/<MBID>?inc=<INC>
  browse:  /<ENTITY>?<ENTITY>=<MBID>&limit=<LIMIT>&offset=<OFFSET>&inc=<INC>
  search:  /<ENTITY>?query=<QUERY>&limit=<LIMIT>&offset=<OFFSET>
... except that search is not implemented for URL entities at this time.
Of these:
* Lookups, Non-MBID lookups and Browse requests are documented in following sections.
Searches are documented at [[/Search|Web Service Search]].
==Relax NG Schema==
The file [https://github.com/metabrainz/mmd-schema/blob/master/schema/musicbrainz_mmd-2.0.rng musicbrainz_mmd-2.0.rng] is a Relax NG Schema for this web service. It can also be used to validate [[#Submitting data|submissions]] you're trying to make through it.
You can perform a lookup of an entity when you have the MBID for that entity:
  lookup:  /<ENTITY>/<MBID>?inc=<INC>
Note that unless you have provided an MBID in exactly the format listed, you are not performing a lookup request. If your URL includes something like artist=<MBID>, then please see the [[#Browse|Browse]] section. If it includes query=<QUERY>, please see the [[/Search|Web Service Search]] page.
The inc= is parameter allows you to request more information to be included about
the entity.  Any of the entities directly linked to the entity can be included.
  /ws/2/artist            recordings, releases, release-groups, works
  /ws/2/collection        user-collections (includes private collections, requires authentication)
  /ws/2/label            releases
  /ws/2/recording        artists, releases, isrcs, url-rels
  /ws/2/release          artists, collections, labels, recordings, release-groups
  /ws/2/release-group    artists, releases
In addition, [[#Relationships|Relationships]] are available for all entity types via inc parameters.
To include more than one subquery in a single request, separate the arguments to <code>inc=</code> with a + (plus sign), like <code>inc=recordings+labels</code>.
All lookups which include release-groups allow a type= argument to narrow down the release-groups.
All lookups which include releases also allow the type= argument, and a status= argument is allowed.
Note that the number of linked entities returned is always limited to 25,
if you need the remaining results, you will have to perform a browse request.
Linked entities are always ordered alphabetically by gid.
=== inc= arguments which affect subqueries ===
Some additional inc= parameters are supported to specify how much of the data about
the linked entities should be included:
  - discids          include discids for all media in the releases
  - media            include media for all releases, this includes the # of tracks on each medium and its format.
  - isrcs            include isrcs for all recordings
  - artist-credits    include artists credits for all releases and recordings
  - various-artists  include only those releases where the artist appears on one of the tracks,
                      but not in the artist credit for the release itself (this is only valid on a
                      /ws/2/artist?inc=releases request).
=== Misc inc= arguments ===
  - aliases                  include artist, label, area or work aliases; treat these as a set, as they are not deliberately ordered
  - annotation                include annotation
  - tags, ratings            include tags and/or ratings for the entity
  - user-tags, user-ratings  same as above, but only return the tags and/or ratings submitted by the specified user
  - genres, user-genres      include genres (tags in [https://musicbrainz.org/genres the genres list]): either all or the ones submitted by the user, respectively
Requests with user-tags, user-genres and user-ratings require authentication.  You can authenticate using HTTP Digest, use the same username and password used to access the main https://musicbrainz.org website.
=== Relationships ===
  - area-rels
  - artist-rels
  - event-rels
  - instrument-rels
  - label-rels
  - place-rels
  - recording-rels
  - release-rels
  - release-group-rels
  - series-rels
  - url-rels
  - work-rels
By default, these 'inc=' arguments will only load relationship for the requested entity. When you are loading a release, you might want to load relationships for all its recordings and also works linked to the recordings. This is useful to get full release credits. There are additional arguments that can be used only on release requests and allow you to specify for which entities to load relationships:
  - recording-level-rels
  - work-level-rels
With relationships included, entities will have <code><relation-list></code> nodes for each target entity type. As an example, requesting <code>inc=series-rels</code> for a work might produce the following relation-list as a child of the work:
<relation-list target-type="series">
    <relation type="part of" type-id="b0d44366-cdf0-3acb-bee6-0f65a77a6ef0">
            <attribute type-id="a59c5830-5ec7-38fe-9a21-c7ea54f6650a" value="op. 26">number</attribute>
        <series id="59c5f4e8-1308-4eff-8845-aa90b92ddc86" type="Catalogue" type-id="49482ff0-fc9e-3b8c-a2d0-30e84d9df002">
            <name>Works of Jean Sibelius by opus number</name>
The <code><attribute-list></code> nodes will contain any [https://musicbrainz.org/relationship-attributes attributes] specified on a relationship. (Here, there's an attribute for the number of the work in a series.) Note that an <code><attribute></code> node's text value is the name of the attribute type (here "number"), and the 'type-id' XML attribute (conflicting terminology!) is the UUID of the relationship attribute type ("number"). Relationship attributes always have a type, and some may have an associated value ("op. 26" here). They may also have a 'credited-as' XML attribute indicating a user-entered name. As an example, the attribute below specifies that the piano being played was a Steinway.
    <attribute credited-as="Steinway piano" type-id="b3eac5f9-7859-4416-ac39-7154e2e8d348">piano</attribute>
==Non-MBID Lookups==
Instead of MBIDs, you can also perform lookups using several other unique identifiers. However, because clashes sometimes occur, each of these lookups return a list of entities (there is no limit, all linked entities will be returned, paging is not supported).
=== discid ===
  lookup: /discid/<discid>?inc=<INC>&toc=<TOC>
A discid lookup returns a list of associated releases, the 'inc=' arguments supported are identical to a lookup request for a release.
If there are no matching releases in MusicBrainz, but a matching [[CD Stub|CDStub]] exists, it will be returned. This is the default behaviour. If you do ''not'' want to see CD stubs, pass 'cdstubs=no.' CD stubs are contained within a <cdstub> element, and otherwise have the same form as a release. Note that CD stubs do not have artist credits, just artists.
If you provide the "toc" query parameter, and if the provided discid is not known by MusicBrainz, a fuzzy lookup will done to find matching MusicBrainz releases. Note that if CD stubs are found this will not happen. If you do want TOC fuzzy lookup, but not cdstub searching, specify "cdstubs=no". For example:
Will look for the disc id first, and if it fails, will try to find tracklists that are within a similar distance to the one provided.
It's also possible to perform a fuzzy toc search without a discid. Passing "-" (or any invalid placeholder) as the discid will cause it to be ignored if a valid toc is present:
By default, fuzzy toc searches only return mediums whose format is set to "CD." If you want to search all mediums regardless of format, add 'media-format=all' to the query:
The toc consists of the following:
* First track (always 1)
* total number of tracks
* sector offset of the leadout (end of the disc
* a list of sector offsets for each track, beginning with track 1 (generally 150 sectors)
=== isrc ===
  lookup: /isrc/<isrc>?inc=<INC>
isrc lookups return a list of recordings, the 'inc=' arguments supported are identical to a lookup request for a recording.
=== iswc ===
  lookup: /iswc/<iswc>?inc=<INC>
An iswc lookup returns a list of works, the 'inc=' arguments supported are identical to a lookup request for a work.
Browse requests are a direct lookup of all the entities directly linked to another entity. (with directly linked I am referring to any relationship inherent in the database, so no ARs). For example, you may want to see all releases on netlabel ubiktune:
Note that browse requests are not searches, in order to browse all the releases on the ubiktune label you will need to know the MBID of ubiktune.
Browsed entities are always ordered alphabetically by gid. If you need to sort the entities, you will have to fetch all entities (see "Paging" below) and sort them yourself.
===Linked entities===
The following list shows which linked entities you can use in a browse request:
  /ws/2/area              collection
  /ws/2/artist            area, collection, recording, release, release-group, work
  /ws/2/collection        area, artist, editor, event, label, place, recording, release, release-group, work
  /ws/2/event            area, artist, collection, place
  /ws/2/instrument        collection
  /ws/2/label            area, collection, release
  /ws/2/place            area, collection
  /ws/2/recording        artist, collection, release, work
  /ws/2/release          area, artist, collection, label, track, track_artist, recording, release-group
  /ws/2/release-group    artist, collection, release
  /ws/2/series            collection
  /ws/2/work              artist, collection
  /ws/2/url              resource
As a special case, release also allows track_artist, which is intended to allow you to browse various artist appearances for an artist.  It will return any release where the artist appears in the artist_credit for a track, but NOT in the artist_credit for the entire release (as those would already have been returned in a request with artist=<MBID>).
The URL endpoint's 'resource' entity is for providing a URL directly, rather than a URL MBID, for example https://musicbrainz.org/ws/2/url?resource=http://www.madonna.com/ versus https://musicbrainz.org/ws/2/url/b663423b-9b54-4067-9674-fffaecf68851. This URL will need to be appropriately URL-escaped for inclusion as a query parameter; this means that URLs that include url-escaped parameters, or query parameters of their own, will need to be escaped a second time.
Release-groups can be filtered on type, and releases can be filtered on type and/or status.  For example, if you want all the Live Bootleg releases by Metallica:
Or all albums and EPs by Autechre:
Browse requests are the only requests which support paging, any browse request supports an 'offset=' argument to get more results.  Browse requests also support 'limit=', the default limit is 25, and you can increase that up to 100.
=== inc= ===
Just like with normal lookup requests, the server can be instructed to include more data about the entity using an 'inc=' argument.  Supported values for inc= are:
  /ws/2/area              aliases
  /ws/2/artist            aliases
  /ws/2/event            aliases
  /ws/2/instrument        aliases
  /ws/2/label            aliases
  /ws/2/place            aliases
  /ws/2/recording        artist-credits, isrcs
  /ws/2/release          artist-credits, labels, recordings, release-groups, media, discids, isrcs (with recordings)
  /ws/2/release-group    artist-credits
  /ws/2/series            aliases
  /ws/2/work              aliases
  /ws/2/area              aliases
  /ws/2/url              (only relation includes)
In addition to the inc= values listed above, all entities support:
All entities except release support:
  tags, user-tags, genres, user-genres
All entities except area, place, release, and series support:
  ratings, user-ratings
In addition, [[#Relationships|Relationships]] are available for all entity types via inc parameters, as with lookup requests.
== Release Type and Status ==
Any query which includes release-groups in the results can be filtered to only include release groups of a certain type.  Any query which includes releases in the results can be filtered to only include releases of a certain type and/or status.  Valid values are:
  status    official, promotion, bootleg, pseudo-release
  type      nat, album, single, ep, compilation, soundtrack, spokenword, interview, audiobook, live, remix, other
== Submitting data ==
You can use the web service to submit certain kinds of data.  Currently tags (including genres), ratings and ISRCs can be entered through the web service.
=== Authentication ===
All POST requests require authentication.  You should authenticate using HTTP Digest, use the same username and password you use to access the main https://musicbrainz.org website.  The realm is "musicbrainz.org".
POST requests should always include a 'client' parameter in the URL (not the body). The value of 'client' should be the ID of the client software submitting data.  This has to be the application's name and version number, not that of a client library (client libraries should use HTTP's User-Agent header). The recommended format is "application-version", where version does not contain a - character.
=== User Data ===
You can submit tags (including genres) and ratings through the web service using POST requests.  As described above, client software needs to identify itself using the 'client=' parameter.  In the following examples I will use 'example.app-0.4.7' as the client identifier, this is obviously a fictitious client.
==== tags ====
To submit tags (including genres), perform a POST request to the /ws/2/tag url, like this:
The body of your request should be an XML formatted list of entities with <user-tag> elements.
An example request is reproduced below:
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
        <artist id="a16d1433-ba89-4f72-a47b-a370add0bb56">
        <recording id="047ea202-b98d-46ae-97f7-0180a20ee5cf">
Because you're sending XML in the body of your POST request, make sure to also set the Content-Type to "application/xml; charset=utf-8".
Our tag functionality includes the ability to upvote and downvote tags (including genres). This terminology can be confusing. Whenever you tag something, you are in fact "upvoting" it (which will add 1 to the vote count for the tag). Downvoting is the inverse operation, and will subtract 1 from the tag's vote count. Tags that you downvote will be hidden from the UI for you (and if their total vote count drops to 0 or below, they'll be hidden for everyone). The "user-tag" elements can include a "vote" attribute that specifies what action you want to take:
<user-tag vote="upvote"><name>noise</name></user-tag>
<user-tag vote="downvote"><name>pop</name></user-tag>
<user-tag vote="withdraw"><name>rock</name></user-tag>
The "withdraw" vote will remove any upvote or downvote that you previously added (as if you had never voted).
If you do not supply any "vote" attributes in your request (as in the example above), then the list of tags you submit will be treated as upvotes and will completely replace all existing upvoted tags you have on that entity. (So, tags that are not included in the request will be withdrawn, if they were previously upvoted. Downvoted tags are left in place.) This is a legacy behavior that we maintain from before we had tag voting. Including any "vote" attribute in the request will cause it to only apply those votes that you specified.
==== ratings ====
To submit ratings, perform a POST request to the /ws/2/rating url, like this:
The body of your request should be an XML formatted list of entities with <user-rating> elements.
An example request is reproduced below:
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
        <artist id="455641ea-fff4-49f6-8fb4-49f961d8f1ad">
        <recording id="c410a773-c6eb-4bc0-9df8-042fe6645c63">
==== collections ====
To add or remove releases (for example) from your collection, perform a PUT or DELETE request to /ws/2/collection/<gid>/releases, respectively:
    PUT /ws/2/collection/f4784850-3844-11e0-9e42-0800200c9a66/releases/455641ea-fff4-49f6-8fb4-49f961d8f1ad;c410a773-c6eb-4bc0-9df8-042fe6645c63?client=example.app-0.4.7
    DELETE /ws/2/collection/f4784850-3844-11e0-9e42-0800200c9a66/releases/455641ea-fff4-49f6-8fb4-49f961d8f1ad;?client=example.app-0.4.7
Other types of entities supported by collections can be submitted, too; just substitute "releases" in the URI with one of: areas, artists, events, labels, places, recordings, release-groups, or works, depending on the type of collection.
You may submit up to ~400 entities in a single request, separated by a semicolon (;), as the PUT example above shows. You are restricted to a maximum URI length of 16kb at the moment (which roughly equates to 400 gids).
To get the description of a collection, perform a lookup request with the collection MBID:
    GET /ws/2/collection/4a0a2cd0-3b20-4093-bd99-92788045845e
To get the description and the summarized contents of a collection, perform a lookup request with the collection MBID and the appropriate entity subquery:
    GET /ws/2/collection/4a0a2cd0-3b20-4093-bd99-92788045845e/areas
    GET /ws/2/collection/f4784850-3844-11e0-9e42-0800200c9a66/releases
To get the contents of a collection, perform a browse request on the appropriate entity endpoint, using the collection MBID as a parameter:
    GET /ws/2/area?collection=4a0a2cd0-3b20-4093-bd99-92788045845e
    GET /ws/2/release?collection=f4784850-3844-11e0-9e42-0800200c9a66
To get a list of collections for a given user (including the number of entities in each collection), you can browse the collection endpoint by editor name:
    GET /ws/2/collection?editor=rob
This will only return collections that rob has made public. If you wish to see private collections as an authenticated user, do:
    GET /ws/2/collection?editor=rob&inc=user-collections
=== Barcode submission ===
Barcodes may be associated with releases by issuing an XML POST request to:
The body of the request must be an XML document with a list of <releases>s in a <release-list>, and a single barcode in a <barcode> element for each release. For example:
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
        <release id="047ea202-b98d-46ae-97f7-0180a20ee5cf">
Upon issuing this request MusicBrainz will create a single edit in the edit queue for applying these changes. These changes will ''not'' be automatically applied, though they will be applied if either no one votes against your changes, or once your changes expire.
=== ISRC submission ===
ISRCs may be associated with recordings by issuing an XML POST request to:
The body of the request must be an XML document with a list of <recording>s in a <recording-list>, and a list of <ISRC>s in a <isrc-list> to be associated with the recordings. For example:
<metadata xmlns="http://musicbrainz.org/ns/mmd-2.0#">
    <recording id="b9991644-7275-44db-bc43-fff6c6b4ce69">
      <isrc-list count="1">
        <isrc id="JPB600601201" />
    <recording id="75c961c9-6e00-4861-9c9d-e6ca90d57342">
      <isrc-list count="1">
        <isrc id="JPB600523201" />
Example code which illustrates this process can be found in our subversion repository: [http://svn.musicbrainz.org/miscellaneous/trunk/isrcsubmit-python/ isrcsubmit-python].
==Limiting Connections to the MusicBrainz Web Service==
All users of the XML web service must ensure that each of their client applications never make more than ONE web service call per second. Making more than one call per second drives up the load on the servers and prevents others from using MusicBrainz. If you impact the server by making more than one call per second, your IP address may be blocked preventing all further access to MusicBrainz. For more details on this, please see our [[XML_Web_Service/Rate_Limiting|rate limiting page]].
==Identifying your application to the MusicBrainz Web Service==
It is important that your application set a proper User-Agent string in its HTTP request headers. Please read our [[XML_Web_Service/Rate_Limiting|rate limiting]] documentation for more details.
==Libraries to use the Web Service==
The Web Service can be accessed with [[libmusicbrainz]].
===3rd party libraries===
* Python: [http://python-musicbrainzngs.readthedocs.org/ python-musicbrainzngs] Python2/3 bindings
* Java: [http://code.google.com/p/musicbrainzws2-java/ musicbrainzws2-java]
* JavaScript: [https://github.com/Borewit/musicbrainz-api musicbrainz-api]
* Ruby:
** [https://github.com/dwo/musicbrainz-ruby musicbrainz-ruby]
** [https://github.com/magnolia-fan/musicbrainz magnolia-fan/musicbrainz] ruby 1.9+
* PHP: [https://github.com/mikealmond/MusicBrainz mikealmond/MusicBrainz], a fork of [[phpbrainz]]
* C#: [https://github.com/avatar29A/MusicBrainz avatar29A/MusicBrainz]
* Objective-C: [https://github.com/demosdemon/libmusicbrainz-objc libmusicbrainz-objc]
* Haskell:
** [http://hackage.haskell.org/package/MusicBrainz Clint Adams' bindings (hackage)]
** [https://github.com/ocharles/haskell-musicbrainz-ws2 haskell-musicbrainz-ws2 (ocharles)]
* common lisp: [https://github.com/0/cl-musicbrainz cl-musicbrainz]
* Perl: [https://metacpan.org/pod/WebService::MusicBrainz WebService::MusicBrainz]
[[Category:Development]] [[Category:Products]] [[Category:WikiDocs Page]]

Latest revision as of 20:10, 10 July 2020

Redirect to: