API

This page describes a JSON-based API for MediaGoblin. It is a WORK IN PROGRESS at the moment while it is being drafted before it gets implemented. Currently it only includes a submission API, based on a specific scenario which might not work in general for MediaGoblin but can be used as a springboard for further API improvements and specifications.

= Scenario. =

A MediaGoblin server (MGS) is used for media storage/repository on behalf of a few other servers, called user servers (US). A user of one US submits a multimedia file. The file is sent to the MGS and categorized on the US in some server specific way. All future use of the multimedia file on the US is processed by the MGS.

The collection of multimedia files from all of the US's is accessible through the MGS interface and through specific categorizations on each US via API or direct links to the content on the MGS.

Submission.
Since all files are processed automatically when they are uploaded there is no need for a specific submission api. Media files should therefore just be uploaded using a normal HTTP POST which is made available via the API using some sort of an authentication mechanism. An extra variable, containing a webhook/callback URL, can be sent alongside the file upload. The callback provides a URL to the file in the public store. The MGS allows the US to send metadata (for example license information) for the file.

The process is as follows:


 * 1) User fills in a form on a US. The form is in fact based up of two forms
 * 2) * One for categorization on the US
 * 3) * One is a file form for the MGS
 * 4) US saves a pending object with the categorization
 * 5) The MGS processes the file as usual
 * 6) When the MGS has finished processing it notifies the US through a special callback url provided that the processing is finished and the file is available in the public store through a specific url
 * 7) US moves the object from a pending state to a real object with direct links (or api specific information which might be designed later) to the MGS
 * 8) US sends metadata to attach to the file.

Callback/finished processing API.
The callback function of the US should read and accept MediaGoblin JSON objects according to the following proposed schema when sent to the callback url provided alongside the original upload:

The MediaGoblin expects status codes 204 (No content) on success (to imitate pubsubhubbub protocol) or normal error codes (4xx or 5xx) to indicate failures. It is possible to further define JSON objects in responses but probably unnecessary.

Metadata.
It should be possible to add metadata to a specific file at any time. This could be information such as license information, related files (e.g. derivative work), views on site or something. In this case we only start with a Creative Commons license.

Metadata API.
A proposed json-based api to attach metadata to a file uploaded to a MediaGoblin instance. Other metadata information can be added later. This is just something to start with. It is necessary to check if the calling application is the same as the uploading application (to restrict others from setting metadata to other people's files).

The following is the JSON Schema for metadata:

An example of a Claim in JSON would be (it remains to decide how to handle user uploads from sites where users aren't registerd on MediaGoblin):

Possible design problems.

 * MediaGoblin is user based but who is the user when files are sent in by users on a specific site ? Use OAuth/OpenID ? Perhaps tie closely with OStatus federation. Probably best to follow Twitter API where applications must be registered and get an API key for uploading.
 * Mediatype for callback needs a better definition in the API (what can be sent, e.g. .).