16 Oct 2017

The way to delete file version through Forge-DM API

Default blog image

As most of Forge developers know, we have 2 different ways to upload a file with Forge-DM API:

  1. The 1st way is uploading a file to the bucket of your App using OSS(Object Storage Service), it's commonly used, and you can check Create an App-Managed Bucket and Upload a File if you are not familiar with this.
  2. The 2nd way is uploading a file to Autodesk SaaS applications including BIM 360 Team, Fusion Team, A360 Personal and even BIM360 Docs, if you are not familiar with this, check this tutorials. Also, my colleague Jaime Rosales has a clear tutorial blog about uploading file to BIM360 Docs, check it here if you are handling with BIM360 Docs.

But, how to delete them when they are uploaded? The answer is different to the above 2 ways:

  1. If you are using the 1st way to upload a file directly to OSS, Ok, it’s straightforward to delete the file, you can use the DELETE buckets/:bucketKey/objects/:objectName API.  
    curl -v "https://developer.api.autodesk.com/oss/v2/buckets/mybucketkey/objects/myobjectkey"
    -H "Authorization: Bearer mytoken"
  2. Now let's talk about the file which is uploaded by the 2nd way, the file actually is represented by Version(Hub->Project->Folder->Item->Version),check https://developer.autodesk.com/en/docs/data/v2/overview/basics/ for details and if you want to delete the version, you CAN NOT achieve this by using DELETE buckets/:bucketKey/objects/:objectName API to delete content direct from OSS as mentioned above. Because if you do this way, it would be modifying the internal immutable data model of Autodesk SaaS application. Instead, you need to post a new version with ‘versions:autodesk.core:Deleted’ type by POST projects/:project_id/versions API, here is the cURL call I used to "delete" the file version.
    -X POST
    -H "Authorization: Bearer mytoken"
    -H "Content-Type: application/vnd.api+json"
    -d '

    And when you get the successful response, the file will be hidden from the folder. Unfortunately, the way only apply for BIM360 Docs, for files in A360 Personal, BIM360 Team or Fusion Team, you can not delete the file version, this is a current limitation. 


Related Article

Posted By

Zhong Wu

Zhong Wu started his career in Autodesk since 2006 on AutoCAD Architecture as a software developer with more than 6 years working experience. After that, Zhong moved to Autodesk Development Network(now is renamed to Forge Partner Development) team as a Developer Advocate mainly focus on the API support/consultant for Maya/MotionBuilder, and started to contribute in Forge evangelism and support with the growing...