Skip to content
Tools for accessing Autodesk Forge APIs from modern Node.js apps.
Branch: develop
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs/tutorials Fixed tutorials. Jun 24, 2019
src Support for forcing MD jobs. Jul 12, 2019
test
.gitignore Ported all existing code to TypeScript. Jun 22, 2019
.jsdoc.json
.npmignore
.travis.yml Disable cleanup before deploying from travis. Jun 23, 2019
README.md Added badges in README. Jun 25, 2019
package-lock.json
package.json Bumped version to 3.2.0. Jul 12, 2019
tsconfig.json Export all symbols & generate .d.ts files. Jun 22, 2019

README.md

forge-nodejs-utils

build status npm version node npm downloads platforms license

Unofficial tools for accessing Autodesk Forge APIs from Node.js applications, built using TypeScript and modern language features like async/await or generators.

Usage

The TypeScript implementation is transpiled into JavaScript with type definition files, so you can use it both in Node.js projects (as a CommonJS module), and in TypeScript projects (as an ES6 module):

// JavaScript
const { DataManagementClient } = require('forge-nodejs-utils');
// TypeScript
import {
	DataManagementClient,
	IBucket,
	IObject,
	IResumableUploadRange,
	DataRetentionPolicy
} from 'forge-nodejs-utils';

Authentication

If you need to generate 2-legged tokens manually, you can use the AuthenticationClient class:

const { AuthenticationClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const auth = new AuthenticationClient(FORGE_CLIENT_ID, FORGE_CLIENT_SECRET);
const authentication = await auth.authenticate(['bucket:read', 'data:read']);
console.log('2-legged token', authentication.access_token);

Other API clients in this library are typically configured using a simple JavaScript object containing either client_id and client_secret properties (for 2-legged authentication), or a single token property (for authentication using a pre-generated access token):

const { DataManagementClient, BIM360Client } = require('forge-nodejs-utils');
const dm = new DataManagementClient({ client_id: '...', client_secret: '...' });
const bim360 = new BIM360Client({ token: '...' });

Data Management

const { DataManagementClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const data = new DataManagementClient({ client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET });

const buckets = await data.listBuckets();
console.log('Buckets', buckets.map(bucket => bucket.bucketKey).join(','));

const objects = await data.listObjects('foo-bucket');
console.log('Objects', objects.map(object => object.objectId).join(','));

Model Derivatives

const { ModelDerivativeClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const derivatives = new ModelDerivativeClient({ client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET });
const job = await derivatives.submitJob('<your-document-urn>', [{ type: 'svf', views: ['2d', '3d'] }]);
console.log('Job', job);

Design Automation

const { DesignAutomationClient } = require('forge-nodejs-utils');
const { FORGE_CLIENT_ID, FORGE_CLIENT_SECRET } = process.env;
const client = new DesignAutomationClient({ client_id: FORGE_CLIENT_ID, client_secret: FORGE_CLIENT_SECRET });
const bundles = await client.listAppBundles();
console.log('App bundles', bundles);

Testing

export FORGE_CLIENT_ID=<your-client-id>
export FORGE_CLIENT_SECRET=<your-client-secret>
export FORGE_BUCKET=<your-test-bucket>
export FORGE_MODEL_URN=<testing-model-urn>
npm run build # First transpile TypeScript code is into JavaScript
npm test
You can’t perform that action at this time.