How to overwrite file when updating topic file

Our course team has a custom app that generates pages from template files and then creates corresponding modules and topics within a course in D2L. This is great for new courses we launch as course designers can play around with the structure of the course in the place we track video and other page information.

A new feature I am looking to build is the ability to update pages. This would be beneficial for future iterations of an existing course as videos, resources, or other page content may change moving forward. The PUT /topic/(topicId)/file API looks promising for this use case. Using it, I am able to update the topic contents as intended.

However, on the backend in the “Manage Files” section of the course, if the file is named the same, it will create a copy each time this API is called (e.g. Page, Page - Copy, Page - Copy (1), Page - Copy (2), etc.). This is explained in the API documentation with the note that “the existing content topic file will not be removed by this action”. 

Is there a parameter, or different API route, I can use to overwrite the existing file in place? When creating the topic with POST /modules/(moduleId)/structure/, the default behavior appears to be to overwrite an existing file with the same name (with a parameter renameFileIfExists that can be set to true to not overwrite the file; much like the PUT method). Is this feature available for the PUT method (e.g. renameFileIfExists=false)?


Best Answer

  • Matt.W.287
    Matt.W.287 Posts: 48
    Answer ✓

    Hi Matthew

    This functionality doesn't appear to be available at present. I see that PIE #10606 is under review so it's being considered. Hopefully that's something that can be added to update the existing API calls. No promises can be made at this point though, sorry to say.

    Certainly an "overwrite" popup comes up in the UI when uploading a file to Manage Files which does exactly what you're after but not via API.

    I hope that's helpful information.



  • Hi Matthew,

    As in 20.23.7 release( ,

    API routes now exist for the Create/Delete Folder and Create/Delete/Overwrite Files in Manage Files. Previously, these API routes were not possible, and users created files via Content API workflows. Users can now easily update and manage files used by Content. For more information on these API routes,

    Should you have any questions or concerns please do not hesitate to contact me directly.

    Thank you,
    Production Support Specialist

  • Matthew.T.222
    Matthew.T.222 Posts: 19 🌱

    Hi Sreelakshmi,

    Thank you for your reply! I have been experimenting with the new Course Files APIs, so I'm still getting up-to-speed a little bit.

    While it can help manage files, these endpoints don't actually address the problem that I've outlined here, and from what I can tell is not currently possible with existing API endpoints.

    To reiterate the goal, I want to be able to update a topic file and have those updates overwrite the existing file, not create a new file.

    From what I've found, I can:

    • update a topic file, but this creates a copy (e.g. File.txt → File.txt - Copy (1))
    • manage course files, specifically delete a file (e.g. delete File.txt and/or File.txt - Copy (1)).

    But I can't use these in combination to functionally perform an overwrite. If I:

    • Start by deleting File.txt, the Topic turns into a 404. I cannot use the update endpoint to then put new content in a file also called File.txt (as it does not exist)
    • If I start by updating the Topic file, it keeps the old File.txt, but the Topic now points to the new File.txt - Copy (1) file. I can use the new APIs to delete File.txt, but I want the file to retain the same name, not with Copy (1) appended to the name.

    I've also filed a PIE item (#10606) that explains this further. The ideal use case here is copying the functionality that already exists for the "create Topic" endpoint that gives you the flexibility to create a copy (renameFileIfExists = true) or to overwrite the file (the default for "create Topic").

    If there are any endpoints or parameters I'm missing to get this behavior, please let me know! I'm also happy to clarify the problem further if my use case is unclear.