Updating metadata via the REST API

Do you want to create a native client or integrate with third party applications: webservices are the solution.

Moderators: car031, car031, car031

Locked
mark.grimes
Posts: 1
Joined: Thu Mar 09, 2017 6:44 pm

Updating metadata via the REST API

Post by mark.grimes » Thu Mar 09, 2017 9:17 pm

I am able to update most of my document's metadata through the REST API with two exceptions:

#1: Date Formats
I can't seem to update any of the attribute fields that are defined with the "Date" type. I've tried a bunch of different formats without luck, but each results in a 500 Intneral Server Error.

Code: Select all

curl -v -u admin:password -X PUT 
    -H "Content-Type: application/json" -H "Accept: application/json" \
    -d '{"id":5445646,"folderId":5539667,"title":"Termination2","templateId":5603328,"attributes":[{"name":"carNo","value":"CAR-newer"},{"name":"modDate","value":"1974-07-27 13:12:07 +0100"}] }' \
    "http://localhost:8080/services/rest/document/update"
Some date formats that I've tried:

Code: Select all

07/27/1974
07271974
19740727
1974/07/27
1974-07-27
1974-07-27 13:12:07 +0100
1974-07-27 13:12:07
1974-07-27T13:12:07 +0100
1974-07-27 13:12:07
1489088532
This command works fine if the modDate attribute is a String type. It only fails when it is a Date type.

#2: Updating standard properties
I am using the REST API (in part) to migrate documents from our old document management system. I'd like to preserve the created/published date and user. Is there any way to update those fields via the REST API? The following has no effect:

Code: Select all

    
curl -v -u admin:password -X PUT \
    -H "Content-Type: application/json" -H "Accept: application/json" \
    -d '{"id":5445646,"folderId":5539667,"title":"Termination2","create}' \
    "http://localhost:8080/services/rest/document/update"
I've also tried each of these. All appear to succeed, but nothing is updated:

Code: Select all

  "date": "2017-03-09 11:06:41 -0500"
  "creation": "2017-03-09 11:06:41 -0500"
  "lastModified": "2017-03-09 14:52:33 -0500"
  "publisher": "User"
  "publisherId": 5341184
  "creator": "User"
  "creatorId": 5341184
Thanks for the help.

agaspa
Posts: 494
Joined: Tue Apr 20, 2010 8:24 am

Re: Updating metadata via the REST API

Post by agaspa » Sat Mar 18, 2017 7:32 pm

Hi,
in order to update an attribute field of type date you should specify the type: 3 and dateValue property

Eg:

Code: Select all

curl -v -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X PUT \
    -d '{ "id": 47, "folderId": 4, "title":"Egzai_u001", "templateId":92241920, "attributes":[{"name":"ack","stringValue":"ack","type":0},{"name":"Tar","dateValue":"2017-03-18 19:10:00 +0100","type":3}] }' \ 
    http://localhost:8080/services/rest/document/update

Code: Select all

curl -v -u admin:admin -H "Content-Type: application/json" -H "Accept: application/json" -X PUT -d @testdata.json http://localhost:8080/services/rest/document/update
See also the link below to get an overview of values for type
http://docs.logicaldoc.com/resources/ws ... ml#method5
Attachments
testdata.zip
It contains the file testdata.json
(266 Bytes) Downloaded 6 times

agaspa
Posts: 494
Joined: Tue Apr 20, 2010 8:24 am

Re: Updating metadata via the REST API

Post by agaspa » Sat Mar 18, 2017 9:38 pm

I checked the code and I can confidently say that it is useless to try to change the document's dates, these changes currently are not covered.
In particular the changes to the fields creation, date and lastModified are not taken into account.
Note: I've tested the code against LD 7.6.3

You can only change the date fields startPublishing and stopPublishing

Code: Select all

curl -v -u admin:admin -X PUT \
    -H "Content-Type: application/json" -H "Accept:application/json" \
    -d '{"id":47,"folderId":4,"title":"Egzai_u002","startPublishing":"2017-03-17 19:28:46 +0100"}" http://localhost:8080/services/rest/document/update

Locked

Who is online

Users browsing this forum: No registered users and 1 guest