Skip to content

Instantly share code, notes, and snippets.

@abubelinha
Forked from alanorth/dspace6-post-item-rest.md
Created November 27, 2023 13:15
Show Gist options
  • Save abubelinha/b2af262359c5b09b53900347c86239e4 to your computer and use it in GitHub Desktop.
Save abubelinha/b2af262359c5b09b53900347c86239e4 to your computer and use it in GitHub Desktop.
POSTing items to the DSpace 6 REST API

POSTing an item to /collections

First log in to get the JSESSIONID cookie and then post the item (I'm using httpie instead of curl):

$ http -f POST https://dspacetest.cgiar.org/rest/login [email protected] password=fuuuu
$ http https://dspacetest.cgiar.org/rest/status Cookie:JSESSIONID=EABAC9EFF942028AA52DFDA16DBCAFDE
$ http POST https://dspacetest.cgiar.org/rest/collections/f10ad667-2746-4705-8b16-4439abe61d22/items Cookie:JSESSIONID=EABAC9EFF942028AA52DFDA16DBCAFDE < item-object.json
HTTP/1.1 200 OK
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Wed, 07 Oct 2020 10:50:58 GMT
Server: nginx
Transfer-Encoding: chunked
Vary: Accept-Encoding
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-Robots-Tag: none
X-XSS-Protection: 1; mode=block

{
    "archived": "false",
    "bitstreams": null,
    "expand": [
        "metadata",
        "parentCollection",
        "parentCollectionList",
        "parentCommunityList",
        "bitstreams",
        "all"
    ],
    "handle": null,
    "lastModified": "Wed Oct 07 12:50:58 CEST 2020",
    "link": "/rest/items/335530b9-ed0e-4616-b81b-25cd3f14f9e9",
    "metadata": null,
    "name": "Testing REST API post",
    "parentCollection": null,
    "parentCollectionList": null,
    "parentCommunityList": null,
    "type": "item",
    "uuid": "335530b9-ed0e-4616-b81b-25cd3f14f9e9",
    "withdrawn": "false"
}

The response indicates that a new item has been created, and you get the internal UUID, but no Handle, because it hasn't been "archived" into the repository yet. If you post to a collection without a workflow then it will be archived automatically and you will get a Handle.

The item-object.json file looks like this:

{ "metadata": [
    {
      "key": "dc.title",
      "value": "Testing REST API post",
      "language": "en_US"
    },
    {
      "key": "dc.contributor.author",
      "value": "Orth, Alan",
      "language": "en_US"
    },
    {
      "key": "dc.date.issued",
      "value": "2020-09-01",
      "language": "en_US"
    }
  ],
  "archived":"false",
  "withdrawn":"false"
}

The archived and withdrawn keys seem to only be used for GETing items, not POSTing.

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