Submitting items using dspace 7 REST API

149 views
Skip to first unread message

Aroldo Rique Júnior

unread,
Jan 13, 2024, 2:29:12 PMJan 13
to DSpace Developers
Guys, is anyone using the Dspace 7.x REST API to submit items?

I can log in and check the status normally. I've already learned the /server/api/authn/login and /server/api/authn/status calls.

I haven't been able to submit an item yet. From what I understand, first I authenticate and then I look for an id passing the uuid of the collection as a parameter, through the REST call /server/api/submission/workspaceitems?owningCollection=c57788fc-ad35-4e86-9b3c-764bad9d8bca

And then, how do I submit my form fields? With which REST call? I created a test form with just one metadata: dc.title.

Checking how the submission process occurs in the Chrome inspector, I saw that the REST call /server/api/submission/workspaceitems/155687 is executed with PATCH. Wouldn't it be POST?

image.png

Does anyone have a complete example of item submission using the REST API?

Att,

Aroldo

Aroldo Rique Júnior

unread,
Jan 13, 2024, 11:42:22 PMJan 13
to DSpace Developers

Bollini, Andrea

unread,
Jan 14, 2024, 10:00:04 AMJan 14
to Aroldo Rique Júnior, DSpace Developers
Hi Aroldo,
I haven't checked if small changes are needed at this time (content is a couple of years old) but it should give you at least an idea of what is needed
The repository contains also a postman collection with examples for the submission.
Hope this help,
Andrea 

From: dspace...@googlegroups.com <dspace...@googlegroups.com> on behalf of Aroldo Rique Júnior <aro...@gmail.com>
Sent: Saturday, January 13, 2024 8:28:58 PM
To: DSpace Developers <dspace...@googlegroups.com>
Subject: [dspace-devel] Submitting items using dspace 7 REST API
 
--
All messages to this mailing list should adhere to the Code of Conduct: https://www.lyrasis.org/about/Pages/Code-of-Conduct.aspx
---
You received this message because you are subscribed to the Google Groups "DSpace Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dspace-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dspace-devel/CACKFi%2BfQ%2BRNtU%3DLKQC9HY-uqkAxWY8VRq42CY5yRTRrgFdnRBg%40mail.gmail.com.

Sweata Kiran

unread,
Jan 18, 2024, 5:41:20 PMJan 18
to DSpace Developers
Hi Aroldo,

I have seen your solution. I am trying to create an item via the RestAPI and I keep getting error 422. Can you share some additional details what you did to successfully submit the an item?
I did the following to create an item. The version of DSpace that I am using is 7.6.

   1. Perform an HTTP get to retrieve the xsrf-token and xsrf-cookie (server/api)
   2. Grab the xsrf-token and xsrf-cookie and use them in the POST request headers to login (server/api/authn/login)
   3. Grab the bearer token and updated xsrf-token from the response headers for subsequent calls. Use both tokens to verify if status for authenticate is TRUE. (server/api/authn/status). Until this point, I got the status 200 and authenticate TRUE.
   4. Use the bearer token and updated xsrf-token in the POST request headers including content-type: application/json to create an item. (server/api/core/items?owningCollection=<uuid>)

I get the following error at step 4.

{"timestamp":"2023-12-18T20:49:14.673+00:00","status":422,"error":"Unprocessable Entity","message":"Unprocessable or invalid entity","path":"/server/api/core/items"}

I am stuck on this error for days and would appreciate any help.

On another note, I was able to create an item via the dspace-rest-python library. However, I want to implement a solution in Power Automate/Nintex to automate the flow via POST request.

Thanks,
Sara

Aroldo Rique Júnior

unread,
Jan 18, 2024, 10:46:33 PMJan 18
to Sweata Kiran, DSpace Developers
Hello Sara. 

In step 4, the REST call is this (you need to obtain an id for the new item):

POST server/api/submission/workspaceitems?owningCollection={collectionId} 

And step 5 would be this: 
PATCH server/api/submission/workspaceitems/{itemId} with JSON of the item.

You are calling a wrong rest call in item 4.

Aroldo 

--
All messages to this mailing list should adhere to the Code of Conduct: https://www.lyrasis.org/about/Pages/Code-of-Conduct.aspx
---
You received this message because you are subscribed to the Google Groups "DSpace Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dspace-devel...@googlegroups.com.

Sweata Kiran

unread,
Mar 6, 2024, 4:35:13 PMMar 6
to DSpace Developers
Hi, 

I figured out my problem. The JSON file was of the wrong format. 
I successfully created an item and uploaded a file through the following steps. I would like to share in case anyone from the community is having the same issue.

  1. Get the XSRF Token from  https://<org>/server/api
  2. Login to https:// <org>/server/api/authn/login with username, password and XSRF token. Get the updated XSRF token and Authorization (JWT Token) from this response.
  3. Create an item in a collection with the updated XSRF token and Authorization (JWT Token) in the header and json data in the body.  https:// <org>  /server/api/core/items?owningCollection=<your collection id>. Example of json data that worked:   {
        "name": "Test Item",
        "metadata": {
            "dc.contributor.author": [
                {
                    "value": "Testing",
                    "language": "en",
                    "authority": null,
                    "confidence": -1
                }
            ],
            "dc.title": [
                {
                    "value": "Test Item",
                    "language": "en",
                    "authority": null,
                    "confidence": -1
                }
            ],
            "dc.type": [
                {
                    "value": "Journal Article",
                    "language": "en",
                    "authority": null,
                    "confidence": -1
                }
            ]
        },
        "inArchive": true,
        "discoverable": true,
        "withdrawn": false,
        "type": "item"
    }
  4. After the item is created, I get the bundle uuid from the response body. 
  5. I used the bundle uuid to upload a file to the item. The file is in the body of the post request. https://<org>/server/api/core/bundles/<bundle id>/bitstreams?name=test‍&description=test
 The DSpace Python REST Client Library was also useful in the implementation of the API: dspace-rest-python/README.md at main · the-library-code/dspace-rest-python · GitHub

Thanks, 
Sweata
Reply all
Reply to author
Forward
0 new messages