====== Ampache's XML API DEVELOPMENT VERSION ====== **API Versions:** {[[dev:XmlApi|Current Stable (3.5.x)]]} {[[dev:xmlapi:development|Development (3.6.x)]]} **Compatible Versions:** //>= 360000// Ampache Provides an API for pulling out it's meta data in the form of simple XML documents. This was originally created for use by [[http://amarok.kde.org/|Amarok]], but there is no reason it couldn't be used to create other front-ends to the Ampache data. Access to the API is controlled by the Internal [[Config:Acl|Access Control Lists]]. The KEY defined in the ACL is the passphrase that must be used to establish an API session. Currently all requests are limited to a maximum of 5000 results for performance reasons. To get additional results pass offset as an additional parameter. If you have any questions or requests for this API please submit a [[http://ampache.org/bugs/new|Feature Request]]. All dates in the API calls should be passed as [[http://en.wikipedia.org/wiki/ISO_8601|ISO 8601]] dates. ===== Sending Handshake Request ===== The handshake is a combination of the following three things * Encoded Passphrase * Timestamp * Username The key that must be passed to Ampache is SHA256(TIME+KEY) where KEY is SHA256('PASSWORD'). Below is a PHP example $time = time(); $key = hash('sha256','mypassword'); $passphrase = hash('sha256',$time . $key); Once you've generated the encoded call the following URL //localhost/ampache is the location of your Ampache installation// http://localhost/ampache/server/xml.server.php?action=handshake&auth=$passphrase×tamp=$time&version=350001&user=vollmerk If your Password, IP and Username match a row in the Access List the following will be returned. AUTHENTICATION TOKEN APIVERSION Last Update ISO 8601 Date Last Add ISO 8601 Date Last Clean ISO 8601 Date Total # of Songs Total # of Artists Total # of Albums Total # of Tags Total # of Videos All future interactions with the Ampache API must include the TOKEN as a get variable named 'AUTH'. ===== Errors ===== All errors will be returned as an XML document as specified in the [[dev:XmlApi:Error|XMLAPI Error Document]]. When possible the text part of the message will be translated into the users configured language. ===== Methods ===== All methods must be passed as action=METHODNAME. All methods except the handshake can take an optional offset=XXX and limit=XXX. The limit determines the maximum number of results returned. The offset will tell Ampache where to start in the result set. For Example if there are 100 total results and you set the Offset to 50, and the limit to 50 Ampache will return results 50 - 100. The default limit is 5000. The default offset is 0 === Non-Data Methods === * handshake * timestamp (Timestamp used in seed of password hash) * auth (Timestamp . Password SHA hash) * version (API Version that the application understands) * username * ping * auth (Session ID is optional) returns version information and extends the session if passed * url_to_song * url (Full Ampache URL from server, translates back into a song XML) === Data Methods === * artists * filter (Value is Alpha Match for returned results, may be more then one letter/number) * exact (Boolean, if true filter is exact rather then fuzzy) * add (ISO 8601 Date Format assumed filter method is newer then specified date, however [START]/[END] can be specified to receive only results added between two dates) * update (ISO 8601 Date Format assumed filter method is newer then specified date, however [START]/[END] can be specified to receive only results updated between two dates) * artist_songs * filter (UID of Artist, returns song XML) * artist_albums * filter (UID of Artist, returns Album XML) * albums * filter (Value is Alpha Match for returned results, may be more then one letter/number) * exact (Boolean, if true filter is exact rather then fuzzy) * add (ISO 8601 Date Format assumed filter method is newer then specified date, however [START]/[END] can be specified to receive only results added between two dates) * update (ISO 8601 Date Format assumed filter method is newer then specified date, however [START]/[END] can be specified to receive only results updated between two dates) * album_songs * filter (UID of Album, returns song XML) * tags * filter (Value is Alpha Match for returned results, may be more then one letter/number) * exact (Boolean, if true filter is exact rather then fuzzy) * tag * filter (UID of tag, returns tag XML) * tag_artists * filter (UID of tag, returns artist XML) * tag_albums * filter (UID of tag, returns album XML) * tag_songs * filter (UID of tag, returns song XML) * songs * filter (Value is Alpha Match for returned results, may be more then one letter/number) * add (ISO 8601 Date Format assumed filter method is newer then specified date, however [START]/[END] can be specified to receive only results added between two dates) * update (ISO 8601 Date Format assumed filter method is newer then specified date, however [START]/[END] can be specified to receive only results updated between two dates) * exact (Boolean, if true filter is exact rather then fuzzy) * song * filter (UID of Song, returns song XML) * playlists * filter (Value is Alpha Match for returned results, may be more then one letter/number) * exact (Boolean, if true filter is exact rather then fuzzy) * playlist * filter (UID of playlist, returns playlist XML) * playlist_songs * filter (UID of Playlist, returns song XML) * search_songs * filter (Value is Alpha Match for Song Title, Artist Name, Album Name, Genre Name returns song XML) * videos * filter (Value is Alpha Match for returned results, may be more then one letter/number) * exact (Boolean, if true filter is exact rather then fuzzy) * video * filter (UID of video, returns video XML) === Control Methods === * preference * set * //Preference Name// * value (New Value for specified preference) * get * //Preference Name// (returns Current value for specified preference) * all (Returns all preferences and their values) * localplay * method //The keyword 'command' is deprecated but still will work// * next (Advance to Next Localplay Item) * prev (Return to Previous Localplay Item) * stop (Stop Localplay Instance) * play (Play Localplay Instance) * playlist (Return Localplay Playlist as song XML) * volume (Set Volume to Int value between 0-100) * value (Int 0-100, if outside range it is ignored) * instances (Returns a list of instances for current the Localplay method, indicates current active one) * activate * instance (UID of instance to activate, also switches play method to Localplay) * democratic * method * vote * oid (Unique ID of the element you want to vote on) * type (Type of object, only song is currently accepted so this is optional) * devote * oid (Unique ID of the element you want to vote on) * type (Type of object, only song is currently accepted so this is optional) * playlist (Returns an array of song items with an additional [VOTE COUNT] element) * play (Returns the URL for playing democratic play) ===== Request URL Examples ===== For the purpose of this example the Ampache host is 'localhost' and the path to Ampache is /ampache **Requesting all genres who's name starts with Rock** http://localhost/ampache/server/xml.server.php?action=genres&auth=1234567890123456789012345678901&filter=Rock **Requesting all song titles, with an offset of 5000** localhost/ampache/server/xml.server.php?action=songs&auth=12345678901234567890123456789012&offset=5000 ===== XML Document Examples ===== All XML Documents that have a element may have 0 or more tag elements associated with them. Each tag element has an attribute ''count'' that indicates the number of people who have specified this tag. Artists XML Document. ID's are Ampache's unique Identifier for the artist. Metallica # of Albums # of Songs Rock & Roll Rock Roll 3 2.9 AC/DC # of Albums # of Songs Rock & Roll Rock Roll 3 2.9 Album XML Document. ID's are Ampache's unique identifier for the album and artist associated. Back in Black AC/DC 1984 12 1 Rock & Roll Rock Roll http://localhost/image.php?id=129348 3 2.9 Single Song XML document, includes references to its parent objects. Hells Bells AC/DC Back in Black Rock & Roll Rock Roll 4 http://localhost/play/index.php?oid=123908... Song Filesize in Bytes http://localhost/image.php?id=129348 3 2.9 Tag XML Document, includes counts for it's child objects Rock & Roll 84 29 239 2 6 Playlist XML Document, includes counts for it's child objects The Good Stuff Karl Vollmer 50 Rock & Roll Rock Roll Public Video XML Document -- Attention UIDs for video elements are non-unique against song.id