All View & Data API applications access the service using an API key. The API key enables you to monitor your application's API usage and ensures that Autodesk can contact you about your application if necessary. Because these keys are used to authenticate your access to the API, this also protects your data from being accessed without your permission.
To create your API key:
-
Visit the Autodesk Developers Page and sign in with your Autodesk Account, or click the Sign Up link to create an account for free if you don't already have one.
-
Click the 'Create an App' link.
- Select the API you want to generate a key for. For this tutorial, select the 'View and Data API'.
- Complete the form and submit your request by pushing the 'Create App' button. Your application will appear in your application list. (Note: The 'Redirect URL' field is a required field, but you don't have to provide a real URL if you don't have one – just add something like 'http://www.mysite.com').
- Click on the newly created App to access your Consumer Key and Secret. You can review your App and API keys whenever you like by clicking on the 'My Apps' link after signing in.
By default, a key can be used on any site and application. However, we strongly recommend that you restrict the use of your key to domains that you administer, to prevent use on unauthorized sites. We also recommend you create a new App (API key) for every new application rather than reusing the same key in multiple applications.
Now you have your API key, the next step is to upload and translate a model so it can be displayed on your webpage.
Upload one of your models to your account and get its URN using the following web page.
Alternatively, you can use one of the following desktop solutions instead if you prefer:
If you prefer using other programming languages or methods, there are even more samples in our GitHub collection and on the developer page.
If you don't have your own model to work with, some 2D and 3D sample models are provided with this workshop, in the Sample files folder.
Each of these solutions will upload and translate models on your account which you can use and view later.
Steps to translate a model using the web page.
-
Enter you Consumer key and secret key, and press the 'Get my access token' button
-
Select one of the models from the 'Samples' list. For example the 'Robot Arm' sample. Or Drag 'n Drop one of yours on the gray area. Then press the 'Translation this one for me' button.
-
You should see a progress bar in the 'Currently translating...' area, please give it some time, ...
-
Once the translation is over, You would see your model listed int he 'Ready"' section with the 'urn' that you need later. Make sure to copy and save that urn somewhere for later use.
For this tutorial, we'll create a minimal Node.js web server to serve your html/css/js files as usual as well as providing code to access your translated files.
If you prefer to use another web server technology, you can adapt these instructions yourself to serve the index.html file included with the project.
Check out the appropriate workshop starting point version of the node.js skeleton application from the View and Data API Node.js basic sample as explained in Prerequisites - Get the sources:
$ git clone https://github.com/Developer-Autodesk/workflow-node.js-view.and.data.api
$ cd workflow-node.js-view.and.data.api
$ git checkout v1.0-workshop
Before you can run the sample, you need to download the node.js dependency modules used by the sample. You do this by executing the following command:
npm install
This command will download the following modules into the node_modules directory:
- express: Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
- request: Request is designed to be the simplest way possible to make http calls. It supports HTTPS and follows redirects by default.
- serve-favicon: Node.js middleware for serving a favicon.
Rename or copy the ./credentials_.js file into ./credentials.js
Windows
copy credentials_.js credentials.js
OSX/Linux
cp credentials_.js credentials.js
Configure your local server with your keys. Replace the placeholder with your own keys in credentials.js, line #29 and #30
client_id: process.env.CONSUMERKEY || '<replace with your consumer key>',
client_secret: process.env.CONSUMERSECRET || '<replace with your consumer secret>',
Copy the URN which you generated prior installing the server in file /www/index.js at line #18
Note: the URN needs to be base64 encoded as mentioned here under "Step 6: Register Your Data with the Viewing Services"
var defaultUrn = '<replace with your encoded urn>';
Run the server from the Node.js console, by running the following command:
node server.js
Connect to your local server using a WebGL-compatible browser:
Note that we use port 3000 and not the default http port 80 because if you are on Mac OSX or use Skype, port 80 may already be in use. If you want to use port 80 to avoid having to specify the port in the URL, edit the server.js file, change the default port from 3000 to 80 and restart the node.js server.