Deleting a folder and its contents using the API

I have folders with XLSX files in them and want to delete them CLEANLY using the API

/var/www/onlyoffice/Data/Products/Files/00/00/01/folder_1000/file_824/v3/content.xlsx
/var/www/onlyoffice/Data/Products/Files/00/00/01/folder_1000/file_825/v2/content.xlsx

I’ve read through ONLYOFFICE Api Documentation - Delete files and folders

does anyone have a CURL example of how to call the API and delete these two folders and their contents (xlsx and diff.zip) from the current document server Version 12.0.0.1726

The doc server runs on Ubuntu 20.04.6 LTS
Thanks
Ivan

The account I wish to get a token for is ALSO MFA protected so how do I get a token?

curl --request POST --header Content-Type: application/json --data {“username":"user@hostxxx.com”,“password”:“mypass”} https://hostxxx.com:6443/api/2.0/authentication.json
{“count”:1,“status”:0,“statusCode”:201,“response”:{“token”:null,“tfa”:true}

I need a token 1st :slight_smile:

Hello @ivan

The account I wish to get a token for is ALSO MFA protected so how do I get a token?

You have to use this method, please check it out:ONLYOFFICE Api Documentation - Authenticate a user by code

does anyone have a CURL example of how to call the API and delete these two folders and their contents (xlsx and diff.zip) from the current document server Version 12.0.0.1726

You can use Postman app to create request and receive CURL sample via code snippet in the right top corner of the app.

By the way, please note that Community server v.12.0 is outdated. If it’s possible, please update you installation.

Thanks Alexandre, will do, I know postman :wink: … opening new bug around upgrade though…

1 Like

Hi I am back trying to make this work.

Using latest Sw stack

I can get the token issued but cannot format the JSON correctly for the file delete.

The fileID I am trying to delete is 968

#json=$(curl --request POST --header “Content-Type: application/json” --data “{“username":"onlyoffice@abc.com”,“password”:“xxxxxx”}” “https://abc.com:6443/api/2.0/authentication.json”)

#token=$(echo $json | sed “s/{.“token”:"([^"]).*}/\1/g”)

#echo $token

TOKEN IS GOOD

Then, HOW do I format the delete for file ID 968?
I’ve read ONLYOFFICE Api Documentation - Delete a file

curl --request DELETE --header “Content-Type: application/json” --data “{“deleteAfter”:“true”,“immediately”:“true”}” “https://abc.com:6443/api/2.0/files/file/968” -H “Authorization: Bearer $token”

I SEE…

{“count”:1,“status”:0,“statusCode”:200,“response”:[{“id”:“727764a4-e5e0-41d8-a5b9-432a2474e851”,“operation”:2,“progress”:0,“error”:null,“processed”:“0”,“finished”:false,“url”:null,“files”:null,“folders”:null}]

and file 968 is NOT deleted…

Any help appreciated

I see

Thanks
Ivan

curl -i --request DELETE --header Content-Type: application/json --header Accept: application/json --data {“deleteAfter”:“true”,“immediately”:“true”} -H Authorization: sEFL54b9GX0KrY= https://abc.com:6443/api/2.0/files/file/968
HTTP/2 200
server: nginx
date: Fri, 04 Aug 2023 21:35:01 GMT
content-type: application/json; charset=UTF-8
content-length: 210
x-aspnet-version: 4.0.30319
cache-control: private, max-age=0
etag: 5cba941c5448473d894eddd1db3b1c83
set-cookie: asc_auth_key=sEFL54b9GX0KrY; path=/; expires=Fri, 04 Aug 2023 22:35:01 GMT; secure; HttpOnly
strict-transport-security: max-age=63072000; includeSubDomains; preload
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
access-control-allow-origin: *

BUMP

Still no joy getting the file deleted… HELP :slight_smile: !
Please.

Hello @ivan
Have you tried to run the request via Postman? I have checked it out, all things are OK (file was deleted). I’ve checked Postman code snippet for curl, it appears as following:

curl --location --request DELETE 'https://my_server/api/2.0/files/file/43' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: ZQXPq_my_token_DXztXi4=' \
--header 'Cookie: asc_auth_key=ZQXPqt_my_token_XztXi4=' \
--data '{
  "deleteAfter": true,
  "immediately": true
}'

Thanks Alexandre, I thought I could figure it out manually :wink:
Where is the OO API collection page and I’ll import it.
Sorry I didnt try it 1st
Ivan

Hello @ivan

I’m not sure that I quite understand it. Do you mean the page with method description? ONLYOFFICE Api Documentation - Delete a file

Got this to work Alexandre. Please close the ticket
!! THANKS

1 Like