Delete Media Files via Media API

Learn how to delete media files via the Media API.

Employee App
Front Door Intranet

Media files are any files that are uploaded to the Staffbase platform. This can be user avatar images, header images, or any images in the My Files or My File Manager. In this article, you will learn how to delete a media file using the Media API.

There can be different use cases why you want to delete media files. For instance, your company’s logo may have changed, and you may want to delete the current images or delete images that were reported as offensive or not falling within your corporate communication guidelines.

  • You have already created an API token with administrative access via the Staffbase Studio. Learn more
  • You have the improved Secure Media feature activated for your platform if you want to get the mediumID using the URL.

To delete a media file, do the following:

It is also possible to obtain a list of media files and their respective mediumID by sending a GET request to /media endpoint. However, this approach has a limitation as the GET request will retrieve a list of all media files along with their mediumIDs, making it difficult to determine the specific mediumID of the file that needs to be deleted.

  1. In your App or Intranet, navigate to the image you want to delete.
  2. Right-click the image and open it in a new tab.
  3. From the URL in the address bar of your browser, copy the mediumID.
    For example, if the URL is https://example.staffbase.com/api/media/secure/external/v2/image/upload/w_554,h_641/c_limit,w_1000,h_1000/66295b72c06bb61d04780ba3.png, copy 66295b72c06bb61d04780ba3 at the end of the URL.

You have copied the mediumID.

Make a DELETE request to the endpoint /media/{mediumID} for each media file that you want to delete.

Terminal window
export mediumID="5db0221d0a09a219c4ce9218"
export AUTH="Basic TOKEN"
curl "https://exampleapp.staffbase.com/api/media/$mediumID" \
-X DELETE \
-H "Authorization: $AUTH" \
--compressed | json_pp

You get a 204 response that the media file is deleted.

Even after completing the request to delete the file successfully, it may take several minutes for the file to be removed from the cache. Therefore, if a user attempts to access the file immediately after deletion, it may still be available.

To bulk trigger the deletion of multiple media files, add a function to loop through multiple mediumIDs to perform your request.