Get started with Storage API

Introduction

This quick start is going to help you work with using Storage API. Tutorial describes main operations required to create files with folders, retrieving and managing them.

Info

Skill level:

Basic

Duration:

45 minutes

Prerequisites

This tutorial assumes that you already have:

  • A tool such as Postman that can be used to execute http calls. These calls can also be made using the TryIt button in the API documentation except from requests for file uploads.
  • Project created and configured. Try Projects API.

1. Preparing to use Storage API

There are some actions, which should be completed before starting using Storage API.

You will need to register an application to use the iTwin Platform APIs. You can use the Register button to automatically create your first single page application (SPA). This will allow you to configure Authorization Code Flow for your SPA application and get the correct access token.

Once generated, you will be shown a few lines of code under the button.

  • IMJS_AUTH_CLIENT_CLIENT_ID - this is the unique identifier for your application. Displayed on application details page as Client ID.
  • IMJS_AUTH_CLIENT_REDIRECT_URI - specifies where users are redirected after they have chosen whether or not to authenticate your app. Displayed on application details page as one of Redirect URIs.
  • IMJS_AUTH_CLIENT_LOGOUT_URI - specifies where users can be returned to after logging out. Displayed on application details page as one of Post logout redirect URIs.
  • IMJS_AUTH_CLIENT_SCOPES - list of accesses granted to the application. Displayed on application details page as Scopes.

Or optionally: Register and configure your application manually following instructions in Register and modify an Application tutorial. Make sure that your application is associated with Storage API and has storage:modify storage:read scopes enabled.

Requires you to sign in. Will automatically generate a Single page application (SPA) that is required to complete this tutorial. You will be able to manage your SPA from your My apps page.

To make request to API user token is needed. There are several ways to get it.

Follow this article to implement Authorization code workflow in your application.

Here you can use Client ID generated from previous registration step.
  1. Go to Get top level folders and files by project - Storage
  2. Click “Try it” button.
  3. On Authorization section select “AuthorizationCode”.
  4. After popup closes Authorization header with your user token value should be visible.
  5. Save user token value for this tutorial.
Use user token to replace JWT_TOKEN dynamic parameter in the next steps.

Files and folders created via Storage API are associated with project. If project is already existing then root folder, which is parent folder to first level files and folders could be retrieved by getting project operation.

Another way of getting link to the storage is by executing HTTP GET https://api.bentley.com/storage?projectId=PROJECT_ID request.

You can execute the request in Get top level folders and files by project documentation page, “Try it” section.

Top level folders with files should be returned if there are any. Response will contain link to the storage, to the root folder.

HTTP request


HTTP
GET https://api.bentley.com/storage?projectId=PROJECT_ID HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Response Body


JSON
{
  "items": [],
  "_links": {
    "self": {
        "href": "https://api.bentley.com/storage?projectId=PROJECT_ID&$skip=0&$top=100"
    },
    "prev": {
        "href": "https://api.bentley.com/storage?projectId=PROJECT_ID&$skip=0&$top=100"
    },
    "next": {
        "href": "https://api.bentley.com/storage?projectId=PROJECT_ID&$skip=100&$top=100"
    },
    "folder": {
        "href": "https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
    }
  }
}

2. Get folder

To retrieve root folder, HTTP GET https://api.bentley.com/storage/folders/FOLDER_ID request should be executed by using link from previous section or by existing another root folder ID.

You can execute the request in Get folder documentation page, “Try it” section.

HTTP request


HTTP
GET https://api.bentley.com/storage/folders/FOLDER_ID HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Response Body


JSON
{
  "folder": {
    "id": "FOLDER_ID",
    "displayName": "test",
    "description": "test folder",
    "path": "folderName/test",
    "lastModifiedByDisplayName": "Bob User",
    "createdDateTime": "2020-05-03T11:05:11.0133549Z",
    "lastModifiedDateTime": "2020-05-03T11:05:11.0133549Z",
    "parentFolderId": "TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
    "_links": {
      "createdBy": {
          "href": "https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "lastModifiedBy": {
          "href": "https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "parentFolder": {
          "href": "https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
      }
    }
  }
}

3. Create folder

Organize files in the better way by storing them in folders. To create folder request, payload should be send to HTTP POST https://api.bentley.com/storage/folders/FOLDER_ID/folders. It is necessary displayName to bet set while description is optional in the payload.

You can execute the request in Create folder documentation page, “Try it” section.

Folder should be created and ready to be used.

HTTP request


HTTP
POST https://api.bentley.com/storage/folders/FOLDER_ID/folders HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Request Body


JSON
{
  "displayName": "test",
  "description": "test folder"
}

Response Body


JSON
{
  "folder": {
    "id": "TYJsPN0xtkWId0yUrXkS5pN5AQzuullIkxz5aDnDJSI",
    "displayName": "test",
    "description": "test folder",
    "path": "test",
    "lastModifiedByDisplayName": "Bob User",
    "createdDateTime": "2020-05-03T11:05:11.0133549Z",
    "lastModifiedDateTime": "2020-05-03T11:05:11.0133549Z",
    "parentFolderId": "TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
    "_links": {
      "createdBy": {
          "href": "https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "lastModifiedBy": {
          "href": "https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "parentFolder": {
          "href": "https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
      }
    }
  }
}

Response headers


HTTP
Location: https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5pN5AQzuullIkxz5aDnDJSI

4. Create file

Create file is three steps operation. Metadata needs to be created first then actual file should be uploaded and finally confirmation request needs to be sent. Created files can be synchronized with iModels. Try Synchronization API.

Use roof folder ID from previous step to crate file in the same directory as previously created folder and execute HTTP POST https://api.bentley.com/storage/folders/FOLDER_ID/files request. It is necessary displayName to bet set while description is optional in the payload.

You can execute the request in Create file documentation page, “Try it” section.

File’s metadata should be created and links from the response will be used in the further steps to create file.

HTTP request


HTTP
POST https://api.bentley.com/storage/folders/FOLDER_ID/files HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Request Body


JSON
{
  "displayName": "test.txt",
  "description": "test file"
}

Response Body


JSON
{
  "_links": {
    "completeUrl": {
        "href": "https://api.bentley.com/storage/files/TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc/complete"
    },
    "uploadUrl": {
        "href": "https://projectshareprodeussa01.blob.core.windows.net/azuresqldbecpluginstorage/ProjectShare/File/b6145b7f-fee9-4a13-b1e4-5d061970373e?sv=2017-04-17&sr=b&sig=4NfdEriAONQhbHGkrTAL4bNMzjW8Qm5l%2FoEPiSQl%2BPo%3D&se=2020-10-19T15:12:51Z&sp=rw&rscd=attachment%3B%20filename%3D%22test.txt%22&userid=b905387c-a685-4d27-aab7-468c9ff0c9a6"
    }
  }
}

This request is used to upload actual file. A tool such as Postman should be used to make http request. Url should be picked from previous request’s response where uploadUrl is specified. The maximum size of the file is 256 MiB. If bigger file needs to be uploaded there are possibility to use Azure libraries to upload file via given Azure SAS url or by uploading file with multiple requests.

Note: Authorization header is not required for this request.

HTTP request


HTTP
PUT https://projectshareprodeussa01.blob.core.windows.net/azuresqldbecpluginstorage/ProjectShare/File/b6145b7f-fee9-4a13-b1e4-5d061970373e?sv=2017-04-17&sr=b&sig=4NfdEriAONQhbHGkrTAL4bNMzjW8Qm5l%2FoEPiSQl%2BPo%3D&se=2020-10-19T15:12:51Z&sp=rw&rscd=attachment%3B%20filename%3D%22test.txt%22&userid=b905387c-a685-4d27-aab7-468c9ff0c9a6 HTTP/1.1
x-ms-blob-type: BlockBlob

Request Body


JSON
test

After uploading actual file confirmation is needed. That will make file visible and it could be used further. Url should be picked from the first step of file’s metadata creation where completeUrl is specified.

You can execute the request in Complete file upload page, “Try it” section.

Your file should be placed in the storage and be ready to be used.

HTTP request


HTTP
POST https://api.bentley.com/storage/files/TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc/complete HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Response Body


JSON
{
  "file":{
    "id":"TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc",
    "displayName":"test.txt",
    "description":"test file",
    "path":"folderName/test.txt",
    "size":8,
    "lastModifiedByDisplayName":"Bob User",
    "createdDateTime":"2020-05-03T11:05:11.0133549Z",
    "lastModifiedDateTime":"2020-05-03T11:05:11.0133549Z",
    "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
    "_links":{
      "createdBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "lastModifiedBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "parentFolder":{
        "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
      }
    }
  }
}

5. Download file

Created files can be downloaded by executing HTTP GET https://api.bentley.com/storage/files/FILE_ID/download request.

You can execute the request in Complete file upload page, “Try it” section.

Your file should be downloaded with the content specified in the previous request.

This query returns `302` redirect response and follow up request should be executed by using link from `Location` header.

HTTP request


HTTP
GET https://api.bentley.com/storage/files/FILE_ID/download HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+octet-stream
Authorization: Bearer JWT_TOKEN

Response Headers


HTTP
Location: https://projectshareprodeussa01.blob.core.windows.net/azuresqldbecpluginstorage/ProjectShare/File/b6145b7f-fee9-4a13-b1e4-5d061970373e?sv=2017-04-17&sr=b&sig=4NfdEriAONQhbHGkrTAL4bNMzjW8Qm5l%2FoEPiSQl%2BPo%3D&se=2020-10-19T15:12:51Z&sp=rw&rscd=attachment%3B%20filename%3D%22test.txt%22&userid=b905387c-a685-4d27-aab7-468c9ff0c9a6

6. Get folders and files in the folder

Usually for navigating through folders and files request for getting the is send. HTTP GET https://api.bentley.com/storage/folders/FOLDER_ID/list with root folder id as folder id should be used to retrieve the items of root folder. It is possible to set page size by specifying $skip and $top query parameters. $top default is set to 100 if it is not changed.

You can execute the request in Get folders and files in folder documentation page, “Try it” section.

Your created folder and file should retrieved.

HTTP request


HTTP
GET https://api.bentley.com/storage/folders/FOLDER_ID/list HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Response Body


JSON
{
  "items":[
    {
      "type":"folder",
      "id":"TYJsPN0xtkWId0yUrXkS5pN5AQzuullIkxz5aDnDJSI",
      "displayName":"test",
      "description":"test folder",
      "path":"test",
      "lastModifiedByDisplayName":"Bob User",
      "createdDateTime":"2020-05-03T11:05:11.0133549Z",
      "lastModifiedDateTime":"2020-05-03T11:05:11.0133549Z",
      "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
      "_links":{
        "createdBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "lastModifiedBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "parentFolder":{
          "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
        }
      }
    },
    {
      "type":"file",
      "id":"TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc",
      "displayName":"test.txt",
      "description":"test file",
      "path":"folderName/test.txt",
      "size":8,
      "lastModifiedByDisplayName":"Bob User",
      "createdDateTime":"2020-05-03T11:05:11.0133549Z",
      "lastModifiedDateTime":"2020-05-03T11:05:11.0133549Z",
      "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
      "_links":{
        "createdBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "lastModifiedBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "parentFolder":{
          "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
        }
      }
    }
  ],
  "_links":{
    "self":{
      "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s/list?$skip=0&$top=100"
    },
    "prev":{
      "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s/list?$skip=0&$top=100"
    },
    "next":{
      "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s/list?$skip=100&$top=100"
    }
  }
}

7. Update folder

To update folder’s metadata request with payload should be send to HTTP PATCH https://api.bentley.com/storage/files/FOLDER_ID. displayName and description properties can be updated by sending this request.

You can execute the request in Update folder documentation page, “Try it” section.

Folder’s properties should be updated.

HTTP request


HTTP
PATCH https://api.bentley.com/storage/folders/FOLDER_ID HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Request Body


JSON
{
  "displayName":"test update",
  "description":"test folder update"
}

Response Body


JSON
{
  "folder":{
    "id":"TYJsPN0xtkWId0yUrXkS5pN5AQzuullIkxz5aDnDJSI",
    "displayName":"test",
    "description":"test folder",
    "path":"test",
    "lastModifiedByDisplayName":"Bob User",
    "createdDateTime":"2020-05-03T11:05:11.0133549Z",
    "lastModifiedDateTime":"2020-05-03T11:09:02.0954397Z",
    "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
    "_links":{
      "createdBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "lastModifiedBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "parentFolder":{
        "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
      }
    }
  }
}

8. Update file

To update file’s metadata request with payload should be send to HTTP PATCH https://api.bentley.com/storage/files/FILE_ID. displayName and description properties can be updated by sending this request same as with folder update.

You can execute the request in Update file documentation page, “Try it” section.

Files properties should be updated.

HTTP request


HTTP
PATCH https://api.bentley.com/storage/files/FILE_ID HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Request Body


JSON
{
  "displayName":"test update.txt",
  "description":"test file update"
}

Response Body


JSON
{
  "folder":{
    "id":"TYJsPN0xtkWId0yUrXkS5pN5AQzuullIkxz5aDnDJSI",
    "displayName":"test",
    "description":"test folder",
    "path":"test",
    "lastModifiedByDisplayName":"Bob User",
    "createdDateTime":"2020-05-03T11:05:11.0133549Z",
    "lastModifiedDateTime":"2020-05-03T11:15:02.0954397Z",
    "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
    "_links":{
      "createdBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "lastModifiedBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "parentFolder":{
        "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
      }
    }
  }
}

9. Update file’s content

Update file’s content is three steps operation. Request for initiating update need to be made first then actual file should be uploaded and finally confirmation request needs to be sent.

Use file ID from previous step and execute HTTP POST https://api.bentley.com/storage/files/FILE_ID/updateContent request.

You can execute the request in Update file’s content documentation page, “Try it” section.

Hyperlinks will be created, which should be used be used in the further steps to update file’s content.

HTTP request


HTTP
POST https://api.bentley.com/storage/files/FILE_ID/updateContent HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Response Body


JSON
{
  "_links":{
    "completeUrl":{
      "href":"https://api.bentley.com/storage/files/TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc/complete"
    },
    "uploadUrl":{
      "href":"https://projectshareprodeussa01.blob.core.windows.net/azuresqldbecpluginstorage/ProjectShare/File/b6145b7f-fee9-4a13-b1e4-5d061970373e?sv=2017-04-17&sr=b&sig=4NfdEriAONQhbHGkrTAL4bNMzjW8Qm5l%2FoEPiSQl%2BPo%3D&se=2020-10-19T15:12:51Z&sp=rw&rscd=attachment%3B%20filename%3D%22test.txt%22&userid=b905387c-a685-4d27-aab7-468c9ff0c9a6"
    }
  }
}

This request is used to upload actual file. A tool such as Postman should be used to make http request. Url should be picked from previous request’s response where uploadUrl is specified. The maximum size of the file is 256 MiB. If bigger file needs to be uploaded there are possibility to use Azure libraries to upload file via given Azure SAS url or by uploading file with multiple requests.

Note: Authorization headers is not required for this request.

HTTP request


HTTP
PUT https://projectshareprodeussa01.blob.core.windows.net/azuresqldbecpluginstorage/ProjectShare/File/b6145b7f-fee9-4a13-b1e4-5d061970373e?sv=2017-04-17&sr=b&sig=4NfdEriAONQhbHGkrTAL4bNMzjW8Qm5l%2FoEPiSQl%2BPo%3D&se=2020-10-19T15:12:51Z&sp=rw&rscd=attachment%3B%20filename%3D%22test.txt%22&userid=b905387c-a685-4d27-aab7-468c9ff0c9a6 HTTP/1.1
x-ms-blob-type: BlockBlob

Request Body


JSON
test update

After uploading actual file confirmation is needed. Url should be picked from the first step where completeUrl is specified.

You can execute the request in Complete file upload page, “Try it” section.

File’s content should be updated.

HTTP request


HTTP
POST https://api.bentley.com/storage/files/TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc/complete HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Response Body


JSON
{
  "file":{
    "id":"TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc",
    "displayName":"test.txt",
    "description":"test file",
    "path":"folderName/test.txt",
    "size":8,
    "lastModifiedByDisplayName":"Bob User",
    "createdDateTime":"2020-05-03T11:05:11.0133549Z",
    "lastModifiedDateTime":"2020-05-03T11:25:46.8659753Z",
    "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
    "_links":{
      "createdBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "lastModifiedBy":{
        "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
      },
      "parentFolder":{
        "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
      }
    }
  }
}

10. Recycle bin operations

Files and folders can be deleted and restored. Deleted items can be queried as well because they will be only soft deleted and kept in the recycle bin. Items from recycle bin can be deleted manually if there is no reason to keep them longer otherwise they will be removed automatically after 30 days.

Let’s delete created folder. Execute HTTP DELETE https://api.bentley.com/storage/folders/FOLDER_ID request.

You can execute the request in Delete folder page, “Try it” section.

Folder should be soft deleted.

HTTP request


HTTP
DELETE https://api.bentley.com/storage/folders/FOLDER_ID HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Let’s delete created file as well. Execute HTTP DELETE https://api.bentley.com/storage/files/FILE_ID request.

You can execute the request in Delete file page, “Try it” section.

File should be soft deleted.

HTTP request


HTTP
DELETE https://api.bentley.com/storage/files/FILE_ID HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Soft deleted files and folders can be retrieve. Send HTTP GET https://api.bentley.com/recycleBin?projectId=PROJECT_ID. It is possible to set page size by specifying $skip and $top query parameters. $top default is set to 100 if it is not changed.

You can execute the request in Get folders and files in recycle bin documentation page, “Try it” section.

File and folder, which were deleted previously should be showed.

HTTP request


HTTP
GET https://api.bentley.com/storage/recycleBin?projectId=PROJECT_ID HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Response Body


JSON
{
  "items":[
    {
      "type":"folder",
      "id":"TYJsPN0xtkWId0yUrXkS5pN5AQzuullIkxz5aDnDJSI",
      "displayName":"test",
      "description":"test folder",
      "path":"test",
      "lastModifiedByDisplayName":"Bob User",
      "createdDateTime":"2020-05-03T11:05:11.0133549Z",
      "lastModifiedDateTime":"2020-05-03T11:05:11.0133549Z",
      "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
      "_links":{
        "createdBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "lastModifiedBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "parentFolder":{
          "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
        }
      }
    },
    {
      "type":"file",
      "id":"TYJsPN0xtkWId0yUrXkS5s4FlCroosBMlyDhZZmlzoc",
      "displayName":"test.txt",
      "description":"test file",
      "path":"folderName/test.txt",
      "size":8,
      "lastModifiedByDisplayName":"Bob User",
      "createdDateTime":"2020-05-03T11:05:11.0133549Z",
      "lastModifiedDateTime":"2020-05-03T11:25:46.8659753Z",
      "parentFolderId":"TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s",
      "_links":{
        "createdBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "lastModifiedBy":{
          "href":"https://api.bentley.com/projects/6959daff-27f5-4b87-96ea-9917daa3a8ff/members/1140f95b-1ba0-49d9-bbf4-b53e54d80387"
        },
        "parentFolder":{
          "href":"https://api.bentley.com/storage/folders/TYJsPN0xtkWId0yUrXkS5g0CIYaGZLxEozrWBCOcS_s"
        }
      }
    }
  ],
  "_links":{
    "self":{
      "href":"https://api.bentley.com/storage/recycleBin?projectId=PROJECT_ID&$skip=0&$top=100"
    },
    "prev":{
      "href":"https://api.bentley.com/storage/recycleBin?projectId=PROJECT_ID&$skip=0&$top=100"
    },
    "next":{
      "href":"https://api.bentley.com/storage/recycleBin?projectId=PROJECT_ID&$skip=100&$top=100"
    }
  }
}

It is time to restore deleted folder. Execute HTTP POST https://api.bentley.com/storage/recycleBin/folders/FOLDER_ID/restore request.

You can execute the request in Restore folder page, “Try it” section.

Folder should be successfully restored.

HTTP request


HTTP
POST https://api.bentley.com/storage/recycleBin/folders/FOLDER_ID/restore HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Finally file can be restored as well. Execute HTTP POST https://api.bentley.com/storage/recycleBin/files/FILE_ID/restore request.

You can execute the request in Restore file page, “Try it” section.

File should be successfully restored.

HTTP request


HTTP
POST https://api.bentley.com/storage/recycleBin/files/FILE_ID/restore HTTP/1.1
Accept: application/vnd.bentley.itwin-platform.v1+json
Authorization: Bearer JWT_TOKEN

Continue learning

Congratulation for completing Storage API tutorial! You should be able to manage your securely stored files, which can be integrated to other service.

More resources that you may like

There are more capabilities, which could be used for retrieving files, folders and more.
Project is necessary for using Storage API. You can check its possibilities.
Files can be synchronized to iModel via Synchronization API.
Issues can be exported as PDF files to Storage.
Forms can be exported as PDF files to Storage.