Difference between revisions of "Sword API"
Line 77: | Line 77: | ||
<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||
− | <METS:mets EXT_VERSION="1.1" OBJID="islandora:72" LABEL="Cinderella" xmlns:METS="http://www.loc.gov/METS/" | + | <METS:mets EXT_VERSION="1.1" OBJID="islandora:72" LABEL="Cinderella" |
− | xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | + | xmlns:METS="http://www.loc.gov/METS/" |
+ | xmlns:xlink="http://www.w3.org/1999/xlink" | ||
+ | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.loc.gov/METS/ http://www.fedora.info/definitions/1/0/mets-fedora-ext1-1.xsd"> | xsi:schemaLocation="http://www.loc.gov/METS/ http://www.fedora.info/definitions/1/0/mets-fedora-ext1-1.xsd"> | ||
<METS:fileSec> | <METS:fileSec> |
Revision as of 14:41, 15 November 2013
Overview
One of the 1.1 release features is a sponsored project to integrate Archivematica with Islandora. This integration will be accomplished by creating a Sword 2.0 API. Islandora development work will add functionality to Islandora to use this API to deposit digital objects into Archviematica.
As described elsewhere on this wiki, "the primary function of Archivematica is to process digital transfers (accessioned digital objects), turn them into SIPs, apply format policies and create high-quality, repository-independent Archival Information Packages (AIP)".
The Archivematica Sword API allows 3rd party applications to automate the process of creating Transfers.
- Create Transfer - set the name and other metadata about a Transfer
- Populate Transfer - add/edit/update digital objects in a Transfer, and associated metadata
- Finalize Transfer - indicates that the Transfer is ready to start processing.
Transfers created through the Dashboard (the Archivematica web based user interface) can be manipulated through this api as well, allowing content from 3rd party applications to be combined with manually created Transfers.
Once a Transfer has been created, populated and finalized, Archivematica will begin processing that Transfer.
Endpoints
Service document
The SWORD service document provides information about the SWORD provider's capacities and lists SWORD collections. Archivematica currently includes one SWORD collection to which SWORD deposits can be made: transfers.
The SWORD service document endpoint is located at /api/v2/sword.
List existing transfers
- HTTP Get to the Collection IRI (defined by default as: /api/v2/transfer/sword)
- Transfers are listed as an Atom feed
- Each Atom feed entry contains an "atom:link" element whose href attribute contains the URL needed to get details about the transfer
- optional filters via get parameters (not yet implemented)
Create a new transfer
- used to start a new transfer in Archivematica
- HTTP POST of an Atom Entry Document to the Collection IRI (defined by default as: /api/v2/transfer/sword)
Possible HTTP Response Codes
- HTTP 200 OK - transfer already exists (not yet implemented)
- HTTP 201 Created - transfer has been accepted
- HTTP 412 Precondition Failed - required metadata missing or invalid
Valid requests will receive a Sword Deposit Receipt in the body of the response.
Required HTTP Headers The HTTP POST must include certain specific http headers.
Required by http 1.1 specification:
- Host: Must be set to archivematica host name.
- Content-Length: Must be set to the length of the atom entry document.
- Content-Type: Must be set to "application/atom+xml;type=entry".
Required by Archivematica.
- Authorization: Must include the api key and username assigned by Archivematica.
Required by SWORD 2.0 protocol:
- In-Progress: Must be set to "true"
Optional in SWORD 2.0 protocol:
- On-Behalf-Of: not implemented by Archivematica
- Slug: not implemented by Archivematica
Required in Body The Body of the request must be a valid Atom Entry Document. The required fields in an Atom Entry Document are:
- title: used as the transfer name
- id: used as an accession id
- author: used as the source of acquisition
- summary: not implemented yet. Could be used in the future as a description for the Transfer
- updated: should be set to the current timestamp.
Example Example HTTP POST request:
POST /api/v2/transfer/sword HTTP/1.1 Host: localhost Authorization: Archivematica-API api_key="XXXXXXXXXXXXXXXXXXXX", username="timh" Content-Length: 213 Content-Type: application/atom+xml;type=entry In-Progress: true <?xml version="1.0" encoding="UTF-8"?> <METS:mets EXT_VERSION="1.1" OBJID="islandora:72" LABEL="Cinderella" xmlns:METS="http://www.loc.gov/METS/" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.loc.gov/METS/ http://www.fedora.info/definitions/1/0/mets-fedora-ext1-1.xsd"> <METS:fileSec> <METS:fileGrp ID="DATASTREAMS"> <METS:fileGrp ID="OBJ" STATUS="A" VERSIONABLE="true"> <METS:file ID="OBJ.0"> <METS:FLocat xlink:title="Cinderella_(1865).pdf" LOCTYPE="URL" xlink:href="http://localhost:8080/fedora/get/islandora:72/OBJ/2013-08-12T14:46:43.454Z" /> </METS:file> </METS:fileGrp> </METS:fileGrp> </METS:fileSec> </METS:mets>
Example Response:
201 Created Location: http://localhost/api/v2/transfer/sword/1225c695-cfb8-4ebb-aaaa-80da344efa6a <entry xmlns="http://www.w3.org/2005/Atom" xmlns:sword="http://purl.org/net/sword/"> <title>Test Transfer</title> <id>2013-0001</id> <author> <updated>2008-08-18T14:27:08Z</updated> <summary type="text">A summary</summary> <!-- EM-IRI --> <link rel="edit-media" href="http://localhost/api/v2/transfer/sword/edit/1225c695-cfb8-4ebb-aaaa-80da344efa6a" /> <!-- Edit-IRI --> <link rel="edit" href="http://localhost/api/v2/transfer/sword/edit/1225c695-cfb8-4ebb-aaaa-80da344efa6a" /> <!-- SE-IRI --> <link rel="http://purl.org/net/sword/terms/add" href="http://localhost/api/v2/transfer/sword/add/1225c695-cfb8-4ebb-aaaa-80da344efa6a" /> <!-- State-IRI --> <link rel="http://purl.org/net/sword/terms/statement" type="application/atom+xml;type=feed" href="http://localhost/api/v2/transfer/sword/feed/1225c695-cfb8-4ebb-aaaa-80da344efa6a" /> <link rel="http://purl.org/net/sword/terms/statement" type="application/rdf+xml" href="http://localhost/api/v2/transfer/sword/rdf/1225c695-cfb8-4ebb-aaaa-80da344efa6a" /> </entry>
Add Files to a Transfer
- POST a METS file to the SE-IRI, listed below. (not yet implemented)
- HTTP headers are required similar to Create Transfer call (above).
- Body must include a valid Atom Entry document, that has METS embedded inside it.
- It is possible to also POST the actual file, (using Multipart in the Content-Type header).
- If only an Atom Entry Document is POST'ed, Archivematica will look for uri's in the file StructMap section of the METS file, and attempt to GET each file listed, to include in the Transfer.
Finalize a Transfer
- POST with no body to the SE-IRI
- set In-Progress HTTP header to : false
- This will tell Archivematica that no further content will be added or removed from the Transfer.
- Archivematica will finish fetching any files that were added previously, and once they have all been downloaded, the Transfer will start through the Archivematica pipeline.
Example
POST http://localhost/api/v2/transfer/sword/1225c695-cfb8-4ebb-aaaa-80da344efa6a HTTP/1.1 Host: localhost Authorization: Archivematica-API api_key="XXXXXXXXXXXXXXXXXXXX", username="timh" Content-Length: 0 Content-Type: application/atom+xml;type=entry In-Progress: false
The response will be HTTP 200/OK or 400/Error (400 if the Transfer was already finalized). If the transfer doesn't exist the response will be HTTP 404.
Get Status of Transfer
To check Status:
GET the State-IRI in this example:
GET http://localhost/api/v2/transfer/sword/1225c695-cfb8-4ebb-aaaa-80da344efa6a/state HTTP/1.1
response will include:
<atom:feed xmlns:sword="http://purl.org/net/sword/terms/" xmlns:atom="http://www.w3.org/2005/Atom"> <atom:category scheme="http://purl.org/net/sword/terms/state" term="failed" label="State"> Deposit initiation: Failed </atom:category> </atom:feed>
the list of possible descriptions is not finalized.
The state term value will either be "processing" (asynchronous deposit still working), "complete" (ready to be finalized), or "failed" (asynchronous deposit encountered an error).
Additional Details
Transfer Details
- redirect to Edit-IRI
- used to get basic info about a Transfer with HTTP GET
- can update basic info using HTTP PUT (not yet implemented)
- can allow deletion with HTTP DELETE
- follows the form: [archivematica hostname]/api/v2/transfer/[uuid of transfer]
- example: http://localhost/api/v2/transfer/1225c695-cfb8-4ebb-aaaa-80da344efa6a
EM-IRI
- Edit-Media IRI
- used to add new objects to an existing transfer
- follows the form: [archivematica hostname]/api/v2/transfer/[uuid of transfer]/media
- example: http://localhost/api/v2/transfer/1225c695-cfb8-4ebb-aaaa-80da344efa6a/media
An HTTP POST to the em-iri for a transfer should include a file as the body (may not be supported in v2, return "not supported" HTTP status)
An HTTP GET should return a list of files in the transfer
An HTTP DELETE to the em-iri will remove all digital objects from the Transfer. This is a valid operation only while the Transfer is being assembled. Once the Transfer has been finalized, attempting to DELETE will return an error.
Edit-IRI
The client can replace the metadata of a resource by performing an HTTP PUT of a new Atom Entry on the Edit-IRI.
This would be used to update metadata about a transfer, such as the transfer name.
SE-IRI
State-IRI
- used to retrieve status of transfer
- implemented as Atom document
- example: http://localhost/api/v2/transfer/1225c695-cfb8-4ebb-aaaa-80da344efa6a/state
- should be able to subscribe like RSS feed
Example session
Below is an example session using curl to manipulate the API. In the example a transfer is created, a file is added to it, and it is finalized.
NOTE: While this is in development, change the URL list "mock_object_content_urls" in src/dashboard/src/components/api/view.py to working URL(s).
# create new transfer curl -v -H "In-Progress: true" --data-binary @mets.xml --request POST http://localhost/api/v2/transfer/sword # response XML includes endpoint for adding addition files, etc. # add another file to the transfer curl -v -H "Content-Disposition: attachment; filename=horse.jpg" --request POST --data-binary "@horse.jpg" http://localhost/api/v2/transfer/sword/03ce11a5-32c1-445a-83ac-400008894f78/media # finalize transfer and approve processing curl -v -H "In-Progress: false" --request POST http://localhost/api/v2/transfer/sword/03ce11a5-32c1-445a-83ac-400008894f78
You might, at some point, want to list the transfers that have been started. The following curl command will do so.
# list transfers that have been created by the API curl -v http://localhost/api/v2/transfer/sword
If you're working on a transfer and want to list what files are included in it, the following curl command will list them.
# list files in transfer curl -v http://localhost/api/v2/transfer/sword/03ce11a5-32c1-445a-83ac-400008894f78/media
If you've started a transfer, but decide not to proceed, you can delete the transfer. The following curl command shows an example.
curl -v -XDELETE http://localhost/api/v2/transfer/sword/03ce11a5-32c1-445a-83ac-400008894f78