Update File Metadata

55 views
Skip to first unread message

Christian Bischof

unread,
Oct 10, 2023, 6:15:49 AM10/10/23
to Dataverse Users Community

Hi

I tried to update the file metadata, but it did't work according to the instructions https://guides.dataverse.org/en/5.12.1/api/native-api.html#updating-file-metadata

I got the metadata with:

curl https://data.aussda.at/api/files/735/metadata

               output:

{"label":"20001_ta_de_v1_0.pdf","description":"GfK-1: Tabellenband","restricted":true,"categories":["Data","Research report"],"id":818}

But update with:

curl -H "X-Dataverse-key:xxx" -X POST \

  -F 'jsonData={"label":"20001_ta_de_v1_0.pdf","description":"GfK-1: Tabellenband new","restricted":true,"categories":["Data","Research report"],"id":818}' \

  "https://dv03.aussda.at/api/files/735/metadata"

Brings the error:

{"status":"ERROR","message":"Filename already exists at 20001_ta_de_v1_0.pdf"}

 

I followed the guide “so if you want to update a specific field first get the json with the above command and alter the fields you want.”, what could be the problem?

I tried it also at the demo server with the same error:

curl https://demo.dataverse.org/api/files/:persistentId/metadata?persistentId=doi:10.70122/FK2/EEKEZH/FEN1HL

curl -H "X-Dataverse-key:xxx" -X POST \

  -F 'jsonData={"label":"test.txt","description":"file_test_new","restricted":false,"id":1888197}' \

 https://demo.dataverse.org/api/files/2092597/metadata

On demo I used persistendId, the file Id didn’t work:

curl https://demo.dataverse.org/api/files/2092597/metadata

{"status":"ERROR","message":"Error attempting get the requested data file.}

 

Thank you,

best regards

Christian

Christian Bischof

unread,
Oct 10, 2023, 6:29:40 AM10/10/23
to Dataverse Users Community
the first curl was not correct, dv03 is the non public test server,  https://data.aussda.at is the production instance:
The error was on dv03.
Best

Christian Bischof

unread,
Oct 11, 2023, 5:48:13 AM10/11/23
to Dataverse Users Community
I found out now, if I update the label (=filename) it works:
curl -H "X-Dataverse-key:345bc83f-2e5d-4d80-861c-e96db61b9e0f" -X POST \
  -F 'jsonData={"label":"20001_ta_de_v1_0_new.pdf", "description":"file_test_new","restricted":false,"id":1888197}' \

But I don't want to change the filename! Without label:
curl -H "X-Dataverse-key:345bc83f-2e5d-4d80-861c-e96db61b9e0f" -X POST \
  -F 'jsonData={"description":"file_test_new","restricted":false,"id":1888197}' \
  "https://demo.dataverse.org/api/files/:persistentId/metadata?persistentId=doi:10.70122/FK2/EEKEZH/FEN1HL"
Come's the error again:
{"status":"ERROR","message":"Filename already exists at 20001_ta_de_v1_0.pdf"}

Best

Julian Gautier

unread,
Oct 11, 2023, 3:24:55 PM10/11/23
to Dataverse Users Community
Hi Christian,

When you run the curl command, does the dataset have a draft version or is its latest version published?

I ask because when I try to use the API endpoint, it seems to work only when the file's dataset has a draft version. Otherwise, I get the same error you've reported. This fact, that the file's dataset needs be have a draft version, has confused me and others in the past.

The dataset you're testing with on Demo Dataverse is at https://demo.dataverse.org/dataset.xhtml?persistentId=doi:10.70122/FK2/EEKEZH and has multiple version, so I can't tell if a draft version exists before you try those curl commands you've shared.

Julian Gautier (he/him)
Product Research Specialist, IQSS
Interested in helping test Dataverse? Sign up for usability testing

Christian Bischof

unread,
Oct 12, 2023, 3:56:39 AM10/12/23
to Dataverse Users Community

Hi Julian,


thank you! You’re right, file metadata update (without update of the label) is only possible when the dataset is in draft status. Is this behaviour intentional? If yes, the documentation should be adapted.


What about getting file metadata, with file Id it doesn’t work anymore:

curl https://demo.dataverse.org/api/files/2092597/metadata

With persistent Id everythin ok:

Curl https://demo.dataverse.org/api/files/:persistentId/metadata?persistentId=doi:10.70122/FK2/EEKEZH/FEN1HL

A bug in Version 6.0?

 

Best regards

Christian

Julian Gautier

unread,
Oct 12, 2023, 11:59:37 AM10/12/23
to Dataverse Users Community
I'm not sure if that behavior is intentional but I agree that it seems that at least the documentation could be improved. I found related conversations in the GitHub issues at https://github.com/IQSS/dataverse/issues/8542 and https://github.com/IQSS/dataverse/issues/9676. And the conversation in https://github.com/IQSS/dataverse/issues/9348 seems relevant, in that I think the API works for editing files should be as similar as possible to the way it works for editing datasets.

Some of the details in those GitHub issues aren't very clear to me and I think could use some disentangling.

About getting file metadata with file Id versus persistent Id:

It looks like the ID you used, 2092597, is the database ID of the file's dataset. But you need to use the database of the file. And this is why https://demo.dataverse.org/api/files/2092597/metadata doesn't work. Although maybe the error message, "Error attempting get the requested data file", could be clearer or more specific. Maybe it could let users know that the file doesn't exist, so we know that the call is supported but the user is using the wrong ID?

And 2092598 is the database ID of the file. So https://demo.dataverse.org/api/files/2092598/metadata works.

Another confusing thing is the ID that's in the json returned from this endpoint. For example, https://demo.dataverse.org/api/files/2092598/metadata shows "id": 1888337.

Screenshot 2023-10-12 at 11.51.25 AM.png

But I don't know what that ID is. It's not the file's database ID or the dataset's database ID.

Christian Bischof

unread,
Oct 13, 2023, 3:49:27 AM10/13/23
to Dataverse Users Community

https://github.com/IQSS/dataverse/issues/8542 and https://github.com/IQSS/dataverse/issues/9676 are about the same problem, updating file metadata is only possible when the dataset is in draft status.

Thanks for the clarification file Id vs database Id. The id 1888337 from the JSON return, there is this information in the documentation: “Note: The id returned in the json response is the id of the file metadata version.”

It’s all a little bit confusing…

 

Best regards & thank you again

Christian

Philip Durbin

unread,
Oct 13, 2023, 1:29:14 PM10/13/23
to dataverse...@googlegroups.com
The behavior is not intentional. It's a bug. Like Katie said at https://github.com/IQSS/dataverse/issues/8542 the UI allows this so the API should to.

Thanks for bringing this to our attention,

Phil


--
You received this message because you are subscribed to the Google Groups "Dataverse Users Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dataverse-commu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dataverse-community/d949eaf5-d4c1-4555-ae80-f8e1c640e098n%40googlegroups.com.


--
Reply all
Reply to author
Forward
0 new messages