Ampache API
Ampache API
The Ampache API Provides methods for pulling out it's meta data in the form of simple XML (and JSON!) documents. This was originally created for use by 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 Access Control Lists. 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 Feature Request. All dates in the API calls should be passed as ISO 8601 dates.
News
Ampache8 ships a new API (API8) based on API6. Changes are kept to a minimum so API8 can be used as a drop in replacement for API6.
Ampache8 introduces a fully compatible RESTful API implementation supporting all formats and versions.
As of 7.7.1 (API 6.9.0) Ampache fully supports POST data requests for all API methods.
POST requests offer more privacy than a regular GET request because data is sent in the body, not the URL, avoiding exposure in browser history and logs.
Parameters for POST, PUT, PATCH and DELETE requests may be supplied in any of three ways, and may be mixed with query-string parameters (the body takes precedence on conflicts):
- a query string (as with
GET) - a form-encoded body (
Content-Type: application/x-www-form-urlencoded) - a JSON body (
Content-Type: application/json)
For example, these are equivalent:
curl "https://music.com.au/server/json.server.php?action=song&filter=54&auth=API_SESSION"
curl -X POST "https://music.com.au/server/json.server.php" -d "action=song&filter=54&auth=API_SESSION"
curl -X POST "https://music.com.au/server/json.server.php" -H "Content-Type: application/json" -d '{"action":"song","filter":"54","auth":"API_SESSION"}'
Archived Version Documentation
After each release, a documentation page will be created to allow pruning old features from the current version.
API8 is the current version and is documented in this repository (docs/openapi.json plus the API-JSON-methods.md / API-XML-methods.md references). The pages below document the last major release of the older versions:
Ampache serves API versions 3, 4, 5, 6 and 8 (version 7 was skipped). You can also check out the past releases page for some historical detail but DO NOT use these pages as a guide for API development.
API Changelog
Take a look at the API Changelog to keep an eye on changes between versions
Before you begin
Ampache 5.2.0+ supports multiple API versions. This means that you can send your handshake with a specific version (e.g. 390001, 440001, 5.2.0, 6.0.0 or 8.0.0) and you will be sent API3, API4, API5, API6 or API8 responses in return. Version 7 was skipped; the default version is 8.
To change from API3 to API5 you can send a ping with a new version parameter to update your session (or send goodbye to log off and start again.)
API3 is not recommended for use outside of running old applications and it is recommended that you turn off API versions you don't use.
Sending Handshake Request
Multiple authentication methods are available, described in the next sections.
NOTE if you use a Bearer Token you do not need to send a handshake request.
User / Password
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 passphrase, you can 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=8.0.0&user=USER
Api Key
The key that must be passed to Ampache is the API Key generated for a specific user (none by default, only the administrator can generate one). Then call the following URL (localhost/ampache is the location of your Ampache installation):
http://localhost/ampache/server/xml.server.php?action=handshake&auth=API_KEY&version=8.0.0
If you are using Ampache 4.0.0 and higher; the key can be passed to Ampache using SHA256(USER+KEY) where KEY is SHA256('APIKEY'). Below is a PHP example
$user = 'username';
$key = hash('sha256', 'myapikey');
$passphrase = hash('sha256', $user . $key);
HTTP Header Authentication
Ampache supports sending your auth parameter to the server using a Bearer Token.
The auth parameter does not need to be sent with your URL. We will check your header for a token first
GET https://demo.ampache.dev/server/json.server.php?action=handshake&version=8.0.0 HTTP/1.1
Authorization: Bearer 000111112233334444455556667777788888899aaaaabbbbcccccdddeeeeeeff