REST Endpoints
The REST API is modeled after the DSpace Objects of Communities, Collections, Items, and Bitstreams. The API is not a straight database schema dump of these entities, but provides some wrapping that makes it easy to follow relationships in the API output.
HTTP Header: Accept
Example usage from command line in XML format with pretty printing:
Example usage from command line in JSON format with pretty printing:
For this documentation, we will assume that the URL to the "REST" webapp will be http://localhost:8080/rest/ for production systems, this address will be slightly different, such as: https://demo.dspace.org/rest/. The path to an endpoint, will go after the /rest/, such as /rest/communities, all-together this is: http://localhost:8080/rest/communities
Another thing to note is that there are Query Parameters that you can tack on to the end of an endpoint to do extra things. The most commonly used one in this API is "?expand". Instead of every API call defaulting to giving you every possible piece of information about it, it only gives a most commonly used set by default and gives the more "expensive" information when you deliberately request it. Each endpoint will provide a list of available expands in the output, but for getting started, you can start with ?expand=all, to make the endpoint provide all of its information (parent objects, metadata, child objects). You can include multiple expands, such as: ?expand=collections,subCommunities.
PaginationDSpace 6.x supports pagination by allowing two query parameters: limit and offset. Note however that the aggregate results number is not supplied (see DS-3887). Endpoints which return arrays of objects, such as /communities, /collections or /items, are "paginated": the full list is broken into "pages" which start at offset from the beginning of the list and contain at most limit elements. By repeated queries you can retrieve any portion of the array or all of it. The default value of offset is 0 and the default value of limit is 100. So, as an example, to retrieve the sixth through tenth elements of the full list of Collections, you could do this:
REST API Authentication has changed in DSpace 6.x. It now uses a JSESSIONID cookie (see below). The previous (5.x) authentication scheme using a rest-dspace-token is no longer supported.
REST API static documentation page listing available endpoints and their function.
Example:
POST/loginLogin to the REST API using a DSpace EPerson (user). It returns a JSESSIONID cookie, that can be used for future authenticated requests.
Example Request:
Example Response:
Example of using JSESSIONID cookie for subsequent (authenticated) requests:
Invalid email/password combinations will receive an HTTP 401 Unauthorized response.
Please note, special characters need to be HTTP URL encoded.For example, an email address like dspacedemo+admin@gmail.com (notice the + special character) would need to be encoded as dspacedemo%2Badmin@gmail.com.
Login to the REST API using Shibboleth authentication. In order to work, this requires additional Apache configuration. To authenticate, execute the following steps:
1. Call the REST Shibboleth login point with a Cookie jar:
2. This should take you again to the IdP login page. You can submit this form using curl using the same cookie jar. However this is IdP dependant so we cannot provide an example here.
3. Once you submit the form using curl, you should be taken back to the /rest/shibboleth-login URL which will return you the JSESSIONID.
4. Using that JSESSIONID, check if you have authenticated successfully:
Logout from the REST API, by providing a JSESSIONID cookie. After being posted this cookie will no longer work.
Example Request:
After posting a logout request, cookie is invalidated and the "/status" path should show you as unauthenticated (even when passing that same cookie). For example:
Invalid token will result in HTTP 400 Invalid Request
Returns string "REST api is running", for testing that the API is up.
Example Request:
https://demo.dspace.org/rest/test
Example Response:
Receive information about the currently authenticated user token, or the API itself (e.g. version information).
Example Request (XML by default):
https://demo.dspace.org/rest/status
Example Request (JSON):
Example JSON Response:
Before Shibboleth authentication for the REST API will work, you need to secure the /rest/shibboleth-login endpoint. Add this configuration section to your Apache HTTPD Shibboleth configuration:
You can test your configuration in 3 different ways:
Using a web browser:Go to https://dspace.myu.edu/rest/shibboleth-login, this should redirect you to the login page of your IdP if you don't have a Shibboleth session yet.Enter your test credentials and this should take you back to the /rest/shibboleth-login URL. You should then see a blank page but in the response headers, the JSESSIONID cookie should be present.Then go to /rest/status and you should see information on the current authenticated ePerson.Using curl without a Shibboleth SessionCall the REST Shibboleth login point with a Cookie jar:Using that JSESSIONID, check if you have authenticated successfully:
Double check that the cookie you took is valid:
Use this cookie to obtain a Tomcat JSESSIONID:
Use the returned JSESSIONID to check if you have authenticated successfully:
Communities in DSpace are used for organization and hierarchy, and are containers that hold sub-Communities and Collections (ex: Department of Engineering).
For an alternative way to create a Community/Collection hierarchy to the REST API take a look at Importing Community and Collection Hierarchy.
Return an array of all the communities in the repository. The results are paginated.
Example:
https://demo.dspace.org/rest/communities
GET/communities/top-communitiesReturn an array of all top-level communities. The results are paginated.
Example:
https://demo.dspace.org/rest/communities/top-communities
GET/communities/{community id}Return the specified community.
Example:
https://demo.dspace.org/rest/communities/e97b847b-2fd5-4751-8d91-fcf0d8895b81
GET/communities/{community id}/collectionsReturn an array of collections of the specified community. The results are paginated.GET/communities/{community id}/communitiesReturn an array of sub-communities of the specified community. The results are paginated.POST/communitiesCreate a new community at top level. You must POST a community object data type.POST/communities/{community id}/collectionsCreate a new collections in the specified community. You must POST a collection object data type.POST/communities/{community id}/communitiesCreate a new sub-community in the specified community. You must POST a community object data type.PUT/communities/{community id}Update the specified community. You must PUT a community object data type.DELETE/communities/{community id}Delete the specified community.DELETE/communities/{community id}/collections/{collection id}Delete the specified collection in the specified community.DELETE/communities/{community id}/communities/{sub-community id}Delete the specified sub-community in the specified community.Collections in DSpace are containers of Items. (ex: Engineering Faculty Publications).
For an alternative way to create a Community/Collection hierarchy to the REST API take a look at Importing Community and Collection Hierarchy.
Items in DSpace represent a "work" and combine metadata and files, known as Bitstreams.
Return an array of all the items in the repository. The results are paginated.
Example:
https://demo.dspace.org/rest/items
GET/items/{item id}Return the specified item.GET/items/{item id}/metadataReturn metadata of the specified item.GET/items/{item id}/bitstreamsReturn an array of all the bitstreams of the specified item. The results are paginated.POST/items/find-by-metadata-fieldFind items by metadata entry. You must POST a metadataentry object data type.POST/items/{item id}/metadataAdd metadata to the specified item. You must POST an array of metadataentry object data type.POST/GET/items/{item id}/bitstreams?name={file name}Add bitstream to the specified item. You must POST the file data and include the name parameter with the value as {file name} in the URL posted to.
Optional query parameters:
description: A description of the bitstream.
groupId: Id of group to set item resource policy to.
year: Year to set embargo date to
month: Month to set embargo date to
day: Day of month to set embargo date to
Example:
/items/{item id}/bitstreams?name=The%20Children%27s%20Crusade%3A%20A%20Duty-Dance%20with%20Death.pdf&description=All%20this%20happened%2C%20more%20or%20less.&groupID=1969&year=2045&month=2&day=13
PUT/items/{item id}/metadataUpdate metadata in the specified item. You must PUT a metadataentry object data type.Each metadata entry that will replace all prior matching metadata entries, i.e. if you submit n 'dc.subject' entries all pre-existing 'dc.subject' entries in the item will be deleted and replaced with the n entriesDELETE/items/{item id}Delete the specified item.DELETE/items/{item id}/metadataClear the metadata of the specified item.DELETE/items/{item id}/bitstreams/{bitstream id}Delete the specified bitstream of the specified bitstream.Bitstreams are files. They have a filename, size (in bytes), and a file format. Typically in DSpace, the Bitstream will the "full text" article, or some other media. Some files are the actual file that was uploaded (tagged with bundleName:ORIGINAL), others are DSpace-generated files that are derivatives or renditions, such as text-extraction, or thumbnails. You can download files/bitstreams. DSpace doesn't really limit the type of files that it takes in, so this could be PDF, JPG, audio, video, zip, or other. Also, the logo for a Collection or a Community, is also a Bitstream.
Return an array of all the bitstreams in the repository. The results are paginated.
Example:
http://demo.dspace.org/rest/bitstreams
GET/bitstreams/{bitstream id}Return the specified bitstream.GET/bitstreams/{bitstream id}/policyReturn bitstream policies.GET/bitstreams/{bitstream id}/retrieveReturn data of bitstream.POST/bitstreams/{bitstream id}/policyAdd policy to item. You must POST a resourcepolicy object data type.PUT/bitstreams/{bitstream id}/dataUpdate the data/file of the specified bitstream. You must PUT the data.PUT/bitstreams/{bitstream id}Update metadata of the specified bitstream. You must PUT a bitstream, does not alter the file/data.DELETE/bitstreams/{bitstream id}Delete the specified bitstream.DELETE/bitstreams/{bitstream id}/policy/{policy id}Delete the specified resource policy of the specified bitstream.You can access the parent object of a Bitstream (normally an Item, but possibly a Collection or Community when it is its logo) through: /bitstreams/:bitstreamID?expand=parent
As the documentation may state "You must post a ResourcePolicy" or some other object type, this means that there is a structure of data types, that your XML or JSON must be of type, when it is posted in the body.
HandleIn DSpace, Communities, Collections, and Items typically get minted a Handle Identifier. You can reference these objects in the REST API by their handle, as opposed to having to use the internal item-ID.
Assembling a full representation of the community and collection hierarchy using the communities and collections endpoints can be inefficient. Retrieve a lightweight representation of the nested community and collection hierarchy. Each node of the hierarchy contains minimal information (id, handle, name).
Note: since the schema object contains no data fields, the following method has not been implemented: PUT /registries/schema/{schema id}
Report ToolsReporting Tools that allow a repository manager to audit a collection for metadata consistency and bitstream consistency. See REST Based Quality Control Reports for more information or test the Collection Report Tool or Metadata Query Tool on demo.dspace.org.