REST API metadata editing (DSpace 6)

258 views
Skip to first unread message

Ari

unread,
Aug 16, 2016, 8:09:38 AM8/16/16
to DSpace Technical Support

I'm trying to edit metadata via REST API but I can't get it to work.
Documentation says that entrypoint looks like this: PUT /items/{item id}/metadata - Update metadata in item. You must put a MetadataEntry

When I try with CURL:
curl -X PUT -H "Content-Type: application/json" -d '{"key":"dc.description.abstract", "value":"hello", "language":"no"}' "http://dummy_dspace_address.com:8080/rest/items/0000c4c0-7e11-4a18-bf94-8192275e50e4/metadata"

result is this:
Can not deserialize instance of org.dspace.rest.common.MetadataEntry[] out of START_OBJECT token at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@7780731e; line: 1, column: 1]


If I try like this:
curl -X PUT -H "Content-Type: application/json" -d "key=dc.description.abstract&value=hello&language=no" "http://dummy_dspace_address.com:8080/rest/items/0000c4c0-7e11-4a18-bf94-8192275e50e4/metadata"

I get this:
Unrecognized token 'key': was expecting ('true', 'false' or 'null') at [Source: org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream@5c8c7a38; line: 1, column: 5]

REST API is working otherwise, I can log in etc. I also tried with cookies enabled (i.e as an authenticated user) but there was no difference.

What am I doing wrong?





Javier Távara

unread,
Aug 16, 2016, 2:57:24 PM8/16/16
to DSpace Technical Support
Try sending "Accept: application/json" header.

Javier Távara

unread,
Aug 16, 2016, 3:02:21 PM8/16/16
to DSpace Technical Support
My mistake. I got confused with the Content-Type header, which you are already sending.

Ari

unread,
Aug 17, 2016, 1:45:35 AM8/17/16
to DSpace Technical Support

Thanks for suggestion, Javier.

However, I managed to find the problem. I had to add square brackets around JSON object:
curl -X PUT -H "Content-Type: application/json" -d '[{"key":"dc.description.abstract", "value":"hello", "language":"no"}]' "http://dummy_dspace_address.com:8080/rest/items/0000c4c0-7e11-4a18-bf94-8192275e50e4/metadata" -b  cookies.txt


Here is a full procedure using CURL, if someone is interested (current documentation is misleading)

1. First, authenticate your self:
curl --data "email=your.email&password=your_pass" http://your_dspace.com:8080/rest/login -c cookies.txt


2. Test that authentication was successful:
curl  -H "Accept: application/json"  http://your_dspace.com:8080/rest/status -b cookies.txt


- this should return something like this:
{"okay":true,"authenticated":true,"email":"your.email","fullname":"ari ","sourceVersion":null,"apiVersion":null}


3. And finally, make an edit:
curl -X PUT -H "Content-Type: application/json" -d '[{"key":"dc.description.abstract", "value":"hello", "language":"no"}]' "http://dummy_dspace_address.com:8080/rest/items/0000c4c0-7e11-4a18-bf94-8192275e50e4/metadata" -b  cookies.txt



Javier Távara

unread,
Aug 24, 2016, 1:06:26 PM8/24/16
to Ari, DSpace Technical Support
Good you got it fixed Ari.
Next time you can try Postman for testing your APIs. Postman can generate also the cUrl code and make tests.

Javier T.

--
You received this message because you are subscribed to a topic in the Google Groups "DSpace Technical Support" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dspace-tech/49KBEXeavyM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dspace-tech+unsubscribe@googlegroups.com.
To post to this group, send email to dspac...@googlegroups.com.
Visit this group at https://groups.google.com/group/dspace-tech.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages