Course Files API - Delete file

Options

When I use the Course Files API to view a file, it works as expected. For example, GET d2l/api/lp/1.44/xxxx/managefiles/file?path=/path/to/file.txt (org id and file name omitted) works completely fine and as expected.

Based on the documentation, it would appear that the only thing that should change is instead of using the GET verb, it should instead use DELETE. However, when trying to do this, it returns a 403 Forbidden error, despite using an administrator account and ensuring that the Role Permissions allowed for file creation and deletion.

Is there something I'm missing? I note that the documentation references JSON Parameters: DeleteFile -Delete file properties, although it doesn't actually provide any reference as to what this body should contain.

Thanks in advance!

Answers

  • Sreelakshmi.N.546
    Options

    Hi Connor,

    Thank you for reaching us through community.

    403 Forbidden error is thrown when you don't have enough permission to perform the required action.

    The API call for delete file is DELETE /d2l/api/lp/(version)/(orgUnitId)/managefiles/file?path

    https://docs.valence.desire2learn.com/res/course.html#delete--d2l-api-lp-(version)-(orgUnitId)-managefiles-file

    403 Forbidden – No permission to See the File Listing or Delete Files

    Can you please check if you have the permission See the File Listing & Delete Files at required levels

    https://community.d2l.com/brightspace/kb/articles/4491-manage-files-permissions

    Thanks,

    Sreelakshmi

  • Connor.D.131
    Connor.D.131 Posts: 8 🌱
    edited October 2023
    Options

    Hi @Sreelakshmi.N.546 , thanks for the quick response! I've confirmed that I have the appropriate permissions (in my Administrator role, all the checkboxes are selected for the "Manage Files" category (except Template, however toggling this didn't change anything).

    This is the Javascript call I've been using to try and perform the DELETE action from within my browser, as my currently signed-in user: await fetch('/d2l/api/lp/1.44/xxxx/managefiles/file?path=/path/to/file.txt', { method: 'DELETE' }).

    Thanks!

  • Connor.D.131
    Connor.D.131 Posts: 8 🌱
    Options

    Ah, I've figured it out! When using the GET method, it's required that it's relative to the base dir. ie. if it's stored in the "/content/folder/file" directory, the GET request must have the path ?path=/folder/file. However, when using the DELETE method, it is required to have the full path to the file; ie. ?path=/content/folder/file. I'd recommend updating the documentation to clarify the Course File API further. :)