/data.management-csharp-webhook

Webhooks for Data Management API:Use a database to store refresh token and access files (on BIM 360) later

Primary LanguageC#MIT LicenseMIT

data.management-csharp-webhook

Platforms .NET License

oAuth2 Data-Management Webhook

Advanced

Description

Show BIM 360 Hubs, Projects and Files, based on this tutorial. When select a folder on the tree view, the option to "Start watching folder" allow to create a dm.version.added webhook for that folder. When a new file is uploaded (e.g. via BIM 360 Docs UI) the webhook notifies the app, which queues the job to, later when ready, access the metadata of the file.

Thumbnail

thumbnail

Demonstration

There a few moving parts on this sample, this video demonstrates the sample.

Setup

Prerequisites

  1. Forge Account: Learn how to create a Forge Account, activate subscription and create an app at this tutorial.
  2. Visual Studio: Either Community (Windows) or Code (Windows, MacOS).
  3. .NET Core basic knowledge with C#
  4. ngrok: Routing tool, download here
  5. MongoDB: noSQL database, learn more. Or use a online version via mLab (this is used on this sample)

Running locally

Clone this project or download it. It's recommended to install GitHub desktop. To clone it via command line, use the following (Terminal on MacOSX/Linux, Git Shell on Windows):

git clone https://github.com/autodesk-forge/data.management-csharp-webhook

Visual Studio (Windows):

Right-click on the project, then go to Debug. Adjust the settings as shown below.

Visual Sutdio Code (Windows, MacOS):

Open the folder, at the bottom-right, select Yes and Restore. This restores the packages (e.g. Autodesk.Forge) and creates the launch.json file. See Tips & Tricks for .NET Core on MacOS.

MongoDB

MongoDB is a no-SQL database based on "documents", which stores JSON-like data. For testing purpouses, you can either use local or live. One easy way is using mLab.

  1. Create a account
  2. Create a new database (e.g. named webhooks)
  3. Under Collections, add a new users collection
  4. Under Users, add a new database user, e.g. appuser

At this point the connection string should be in the form of mongodb://<dbuser>:<dbpassword>@ds<number>.mlab.com:<port>/webhook.

There are several tools to view your database, Robo 3T (formerly Robomongo) is a free lightweight GUI that can be used. When it opens, click on Create, then at Connection specify a name, enter your ds<number>.mlab.com as address and <port> number as port, also at Authentication enter the datbase name (e.g. webhook) and <dbuser> and <dbpassword>.

Environment variables

At the .vscode\launch.json, find the env vars and add your Forge Client ID, Secret and callback URL. Also define the ASPNETCORE_URLS variable. The end result should be as shown below:

"env": {
    "ASPNETCORE_ENVIRONMENT": "Development",
    "ASPNETCORE_URLS" : "http://localhost:3000",
    "FORGE_CLIENT_ID": "your id here",
    "FORGE_CLIENT_SECRET": "your secret here",
    "FORGE_CALLBACK_URL": "http://localhost:3000/api/forge/callback/oauth",
    "FORGE_WEBHOOK_CALLBACK_URL": "http://1234.ngrok.io/api/forge/callback/webhook",
    "OAUTH_DATABASE": "mongodb://<dbuser>:<dbpassword>@ds<number>.mlab.com:<port>/webhook"
},

Open http://localhost:3000 to start the app.

Open http://localhost:3000/hangfire for jobs dashboard.

Deployment

To deploy this application to Heroku, the Callback URL for Forge must use your .herokuapp.com address. After clicking on the button below, at the Heroku Create New App page, set your Client ID, Secret and Callback URL for Forge.

Deploy

Further Reading

Documentation:

Other APIs:

Known Issues

  • No webhook for translation: this sample tries GET Manifest every interval as, as of now, there is no webhook for Model Derivative translations on BIM 360 files. There is support for OSS Buckets translations, learn more here.

Tips & Tricks

This sample uses .NET Core and works fine on both Windows and MacOS, see this tutorial for MacOS.

Troubleshooting

  1. Cannot see my BIM 360 projects: Make sure to provision the Forge App Client ID within the BIM 360 Account, learn more here. This requires the Account Admin permission.

  2. error setting certificate verify locations error: may happen on Windows, use the following: git config --global http.sslverify "false"

License

This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.

Written by

Augusto Goncalves @augustomaia, Forge Partner Development