Skip to content

Instantly share code, notes, and snippets.

@alanorth
Last active August 29, 2015 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alanorth/61ebdb93c6ee04e91f94 to your computer and use it in GitHub Desktop.
Save alanorth/61ebdb93c6ee04e91f94 to your computer and use it in GitHub Desktop.
Playing with the DSpace 4.x REST API.

DSpace 4.x REST API

Ok, so this is pretty cool. I played with it a bit more and found some useful tidbits. The documentation for the REST API lists the following endpoints:

  • /communities
  • /collections
  • /items
  • /bitstreams

But I found there is also /handle which is much easier to work with because you don't have to know the internal database ID of a given community / collection / item, etc... you can just work using the same IDs you're used to from the DSpace front end.

DSpace Test has the REST webapp running here: https://cgspace.cgiar.org/rest

Playing with the /handle endpoint

For example, given a collection 10568/3547 (CCAFS Journal Articles), we can get a list of its items using the /handle/ endpoint: /handle/10568/3547

<collection>
<expand>parentCommunityList</expand>
<expand>parentCommunity</expand>
<expand>license</expand>
<expand>logo</expand>
<expand>all</expand>
<handle>10568/3547</handle>
<ID>313</ID>
<name>CCAFS Journal Articles</name>
<type>collection</type>
<copyrightText/>
<introductoryText>
<strong><a href="https://cgspace.cgiar.org/handle/10568/3547/browse?type=dateissued&sort_by=2&order=DESC&rpp=30">View all journal articles</a></strong>
</introductoryText>
<items>
<expand>metadata</expand>
<expand>parentCollection</expand>
<expand>parentCollectionList</expand>
<expand>parentCommunityList</expand>
<expand>bitstreams</expand>
<expand>all</expand>
<handle>10568/33749</handle>
<ID>34886</ID>
<name>
Integrated management practices significantly affect N2O emissions and wheat–maize production at field scale in the North China Plain
</name>
<type>item</type>
<archived>true</archived>
<lastModified>2014-11-04 18:25:11.469</lastModified>
<withdrawn>false</withdrawn>
</items>

From there you can get the handles for the individual items, then drill down to get their metadata (still using the /handle endpoint): /handle/10568/33749

<item>
<expand>metadata</expand>
<expand>parentCollection</expand>
<expand>parentCollectionList</expand>
<expand>parentCommunityList</expand>
<expand>bitstreams</expand>
<expand>all</expand>
<handle>10568/33749</handle>
<ID>34886</ID>
<name>
Integrated management practices significantly affect N2O emissions and wheat–maize production at field scale in the North China Plain
</name>
<type>item</type>
<archived>true</archived>
<lastModified>2014-11-04 18:25:11.469</lastModified>
<withdrawn>false</withdrawn>
</item>

It gets interesting when you expand the result set. For example, you can expand the items to get their full metadata, ?expand=all, or perhaps the bitstreams, ?expand=bitstreams. From there, getting their thumbnails is super easy: /bitstreams/22635/retrieve

/bitstreams/22635/retrieve

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment