Skip to content

Repository files navigation

Forge Java SDK

Forge API: oAuth2Data-ManagementOSSModel-DerivativeBuild Status

Overview

This Java SDK enables you to easily integrate the Forge REST APIs into your application, including OAuth, Data Management, Model Derivative, and Design Automation.

Requirements

Install the Library

To install the API client library to your local Maven repository, simply execute:

mvn install

Maven users

Add the following dependency to your pom.xml:

<dependency>
<groupId>com.autodesk</groupId>
<artifactId>forge-java-sdk</artifactId>
<version>1.0.2</version>
</dependency>

Gradle users

Add this dependency to your project's build file:

repositories {
mavenLocal()
}
dependencies {
compile "com.autodesk:com-autodesk-client:1.0.2"
}

Tutorial

Follow this tutorial to see a step-by-step process and examples of how to use the Forge APIs.

Learn Forge

Authentication

This SDK comes with an OAuth 2.0 client that allows you to retrieve 2-legged and 3-legged tokens. It also enables you to refresh 3-legged tokens. This tutorial uses both 2-legged and 3-legged tokens for calling different Data Management endpoints.

2-Legged Token

This type of token is given directly to the application. To get a 2-legged token run the following code:

StringCLIENT_ID = "" , CLIENT_SECRET = "";
List<String> scopes = newArrayList<String>();
scopes.add("data:read");
scopes.add("data:write");
// Initialize the 2-legged OAuth 2.0 client, and optionally set specific scopes.// If you omit scopes, the generated token will have all scope permissions.// Set autoRefresh to `true` to automatically refresh the access token when it expires.OAuth2TwoLeggedoauth2TwoLegged = newOAuth2TwoLegged(CLIENT_ID, CLIENT_SECRET, scopes, true);
CredentialstwoLeggedCredentials = oauth2TwoLegged.authenticate();

3-Legged Token

Generate an Authentication URL

To ask for permissions from a user to retrieve an access token, you redirect the user to a consent page. Run this code to create a consent page URL:

StringCLIENT_ID = "" , CLIENT_SECRET = "", REDIRECT_URL = "";
// Generate a url that asks permissions for specific scopes.List<String> scopes = newArrayList<String>();
scopes.add("data:read");
scopes.add("data:write");
// Initialize the 3-legged OAuth 2.0 client, and optionally set specific scopes.// If you omit scopes, the generated token will have all scope permissions.// Set autoRefresh to `true` to automatically refresh the access token when it expires.// Note that the REDIRECT_URL must match the callback URL you provided when you created the app.OAuth2ThreeLeggedoauth2ThreeLegged = newOAuth2ThreeLegged(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL, scopes, true);
// Generate a URL page that asks for permissions for the specified scopes.StringoauthUrl = oauth2ThreeLegged.getAuthenticationUrl();
//Redirect the user to authUrl (the user consent page).
Retrieve an Authorization Code

Once a user receives permissions on the consent page, Forge will redirect the page to the redirect URL you provided when you created the app. An authorization code is returned in the query string.

GET /callback?code={authorizationCode}

Retrieve an Access Token

Request an access token using the authorization code you received, as shown below:

// The `threeLeggedCredentials` object contains an `access_token` and an optional `refresh_token` that you can use to call the endpoints.ThreeLeggedCredentialsthreeLeggedCredentials = oauth2ThreeLegged.getAccessToken(authorizationCode);

Note that access tokens expire after a short period of time. The expiresAt field in the threeLeggedCredentials object gives the validity of an access token in seconds. To refresh your access token, call the oauth2ThreeLegged.refreshAccessToken(threeLeggedCredentials.getRefreshToken()); method.

Example API Calls

Use the threeLeggedCredentials object to call the Forge APIs.

importcom.autodesk.client.ApiException;
importcom.autodesk.client.ApiResponse;
importcom.autodesk.client.api.BucketsApi;
importcom.autodesk.client.api.HubsApi;
importcom.autodesk.client.auth.*;
importcom.autodesk.client.model.*;
importjava.util.ArrayList;
importjava.util.List;
publicclassForgeApiExample {
publicstaticvoidmain(String[] args) {
try {
List<String> scopes = newArrayList<String>();
scopes.add("data:read");
scopes.add("data:write");
scopes.add("bucket:create");
scopes.add("bucket:read");
// Initialize the oauth2TwoLegged object using the client key and client secret you received when creating the app on the Forge Developer portal:OAuth2TwoLeggedoauth2TwoLegged = newOAuth2TwoLegged("<CLIENT_ID>", "<CLIENT_SECRET>", scopes, true);
CredentialstwoLeggedCredentials = oauth2TwoLegged.authenticate();
// Initialize the relevant clients; in this example, the Hubs and Buckets clients (part of the Data Management API).BucketsApibucketsApi = newBucketsApi();
HubsApihubsApi = newHubsApi();
// Create a new bucket// Use the oauth2TwoLegged and twoLeggedCredentials objects that you retrieved previously.PostBucketsPayloadpayload = newPostBucketsPayload();
payload.setBucketKey("test_bucket_key");
payload.setPolicyKey(PostBucketsPayload.PolicyKeyEnum.PERSISTENT);
ApiResponse<Bucket> createBucketResponse = bucketsApi.createBucket(payload, "", oauth2TwoLegged, twoLeggedCredentials);
System.out.println(createBucketResponse.getData().getBucketKey());
// Get the buckets owned by an application.// Use the oauth2TwoLegged and twoLeggedCredentials objects that you retrieved previously.ApiResponse<Buckets> getBucketsResponse = bucketsApi.getBuckets(null, null, null, oauth2TwoLegged, twoLeggedCredentials);
for(BucketsItemsbucket: getBucketsResponse.getData().getItems()) {
System.out.println(bucket.getBucketKey());
}
// Get the hubs that are accessible for a member.// Use the oauth2ThreeLegged and threeLeggedCredentials objects that you retrieved previously.ApiResponse<Hubs> getHubsResponse = hubsApi.getHubs(null, null, oauth2ThreeLegged, threeLeggedCredentials);
for(Hubhub: getHubsResponse.getData().getData()) {
System.out.println(hub.getId());
}
} catch (Exceptione) {
System.err.println("Exception when calling Forge APIs");
e.printStackTrace();
}
}
}

API Documentation

You can get the full documentation for the API on the Developer Portal

Documentation for API Endpoints

All URIs are relative to https://developer.api.autodesk.com/ (for example createBucket URI is 'https://developer.api.autodesk.com/oss/v2/buckets')

ClassMethodHTTP requestDescription
ActivitiesApicreateActivityPOST /autocad.io/us-east/v2/ActivitiesCreates a new Activity.
ActivitiesApideleteActivityDELETE /autocad.io/us-east/v2/Activities('{id}')Removes a specific Activity.
ActivitiesApideleteActivityHistoryPOST /autocad.io/us-east/v2/Activities('{id}')/Operations.DeleteHistoryRemoves the version history of the specified Activity.
ActivitiesApigetActivityGET /autocad.io/us-east/v2/Activities('{id}')Returns the details of a specific Activity.
ActivitiesApigetActivityVersionsGET /autocad.io/us-east/v2/Activities('{id}')/Operations.GetVersionsReturns all old versions of a specified Activity.
ActivitiesApigetAllActivitiesGET /autocad.io/us-east/v2/ActivitiesReturns the details of all Activities.
ActivitiesApipatchActivityPATCH /autocad.io/us-east/v2/Activities('{id}')Updates an Activity by specifying only the changed attributes.
ActivitiesApisetActivityVersionPOST /autocad.io/us-east/v2/Activities('{id}')/Operations.SetVersionSets the Activity to the specified version.
ActivitiesApiupdateActivityPUT /autocad.io/us-east/v2/Activities('{id}')Updates an Activity by redefining the entire Activity object.
AppPackagesApicreateAppPackagePOST /autocad.io/us-east/v2/AppPackagesCreates an AppPackage module.
AppPackagesApideleteAppPackageDELETE /autocad.io/us-east/v2/AppPackages('{id}')Removes a specific AppPackage.
AppPackagesApideleteAppPackageHistoryPOST /autocad.io/us-east/v2/AppPackages('{id}')/Operations.DeleteHistoryRemoves the version history of the specified AppPackage.
AppPackagesApigetAllAppPackagesGET /autocad.io/us-east/v2/AppPackagesReturns the details of all AppPackages.
AppPackagesApigetAppPackageGET /autocad.io/us-east/v2/AppPackages('{id}')Returns the details of a specific AppPackage.
AppPackagesApigetAppPackageVersionsGET /autocad.io/us-east/v2/AppPackages('{id}')/Operations.GetVersionsReturns all old versions of a specified AppPackage.
AppPackagesApigetUploadUrlGET /autocad.io/us-east/v2/AppPackages/Operations.GetUploadUrlRequests a pre-signed URL for uploading a zip file that contains the binaries for this AppPackage.
AppPackagesApigetUploadUrlWithRequireContentTypeGET /autocad.io/us-east/v2/AppPackage/Operations.GetUploadUrl(RequireContentType={require})Requests a pre-signed URL for uploading a zip file that contains the binaries for this AppPackage. Unlike the GetUploadUrl method that takes no parameters, this method allows the client to request that the pre-signed URL to be issued so that the subsequent HTTP PUT operation will require Content-Type=binary/octet-stream.
AppPackagesApipatchAppPackagePATCH /autocad.io/us-east/v2/AppPackages('{id}')Updates an AppPackage by specifying only the changed attributes.
AppPackagesApisetAppPackageVersionPOST /autocad.io/us-east/v2/AppPackages('{id}')/Operations.SetVersionSets the AppPackage to the specified version.
AppPackagesApiupdateAppPackagePUT /autocad.io/us-east/v2/AppPackages('{id}')Updates an AppPackage by redefining the entire Activity object.
BucketsApicreateBucketPOST /oss/v2/buckets
BucketsApideleteBucketDELETE /oss/v2/buckets/{bucketKey}
BucketsApigetBucketDetailsGET /oss/v2/buckets/{bucketKey}/details
BucketsApigetBucketsGET /oss/v2/buckets
DerivativesApideleteManifestDELETE /modelderivative/v2/designdata/{urn}/manifest
DerivativesApigetDerivativeManifestGET /modelderivative/v2/designdata/{urn}/manifest/{derivativeUrn}
DerivativesApigetFormatsGET /modelderivative/v2/designdata/formats
DerivativesApigetManifestGET /modelderivative/v2/designdata/{urn}/manifest
DerivativesApigetMetadataGET /modelderivative/v2/designdata/{urn}/metadata
DerivativesApigetModelviewMetadataGET /modelderivative/v2/designdata/{urn}/metadata/{guid}
DerivativesApigetModelviewPropertiesGET /modelderivative/v2/designdata/{urn}/metadata/{guid}/properties
DerivativesApigetThumbnailGET /modelderivative/v2/designdata/{urn}/thumbnail
DerivativesApitranslatePOST /modelderivative/v2/designdata/job
EnginesApigetAllEnginesGET /autocad.io/us-east/v2/EnginesReturns the details of all available AutoCAD core engines.
EnginesApigetEngineGET /autocad.io/us-east/v2/Engines('{id}')Returns the details of a specific AutoCAD core engine.
FoldersApigetFolderGET /data/v1/projects/{project_id}/folders/{folder_id}
FoldersApigetFolderContentsGET /data/v1/projects/{project_id}/folders/{folder_id}/contents
FoldersApigetFolderParentGET /data/v1/projects/{project_id}/folders/{folder_id}/parent
FoldersApigetFolderRefsGET /data/v1/projects/{project_id}/folders/{folder_id}/refs
FoldersApigetFolderRelationshipsRefsGET /data/v1/projects/{project_id}/folders/{folder_id}/relationships/refs
FoldersApipostFolderRelationshipsRefPOST /data/v1/projects/{project_id}/folders/{folder_id}/relationships/refs
HubsApigetHubGET /project/v1/hubs/{hub_id}
HubsApigetHubsGET /project/v1/hubs
ItemsApigetItemGET /data/v1/projects/{project_id}/items/{item_id}
ItemsApigetItemParentFolderGET /data/v1/projects/{project_id}/items/{item_id}/parent
ItemsApigetItemRefsGET /data/v1/projects/{project_id}/items/{item_id}/refs
ItemsApigetItemRelationshipsRefsGET /data/v1/projects/{project_id}/items/{item_id}/relationships/refs
ItemsApigetItemTipGET /data/v1/projects/{project_id}/items/{item_id}/tip
ItemsApigetItemVersionsGET /data/v1/projects/{project_id}/items/{item_id}/versions
ItemsApipostItemRelationshipsRefPOST /data/v1/projects/{project_id}/items/{item_id}/relationships/refs
ItemsApipostItemPOST /data/v1/projects/{project_id}/items
ObjectsApicopyToPUT /oss/v2/buckets/{bucketKey}/objects/{objectName}/copyTo/{newObjName}
ObjectsApicreateSignedResourcePOST /oss/v2/buckets/{bucketKey}/objects/{objectName}/signed
ObjectsApideleteObjectDELETE /oss/v2/buckets/{bucketKey}/objects/{objectName}
ObjectsApideleteSignedResourceDELETE /oss/v2/signedresources/{id}
ObjectsApigetObjectGET /oss/v2/buckets/{bucketKey}/objects/{objectName}
ObjectsApigetObjectDetailsGET /oss/v2/buckets/{bucketKey}/objects/{objectName}/details
ObjectsApigetObjectsGET /oss/v2/buckets/{bucketKey}/objects
ObjectsApigetStatusBySessionIdGET /oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId}
ObjectsApigetSignedResourceGET /oss/v2/signedresources/{id}
ObjectsApiuploadChunkPUT /oss/v2/buckets/{bucketKey}/objects/{objectName}/resumable
ObjectsApiuploadObjectPUT /oss/v2/buckets/{bucketKey}/objects/{objectName}
ObjectsApiuploadSignedResourcePUT /oss/v2/signedresources/{id}
ObjectsApiuploadSignedResourcesChunkPUT /oss/v2/signedresources/{id}/resumable
ProjectsApigetProjectGET /project/v1/hubs/{hub_id}/projects/{project_id}
ProjectsApigetProjectHubGET /project/v1/hubs/{hub_id}/projects/{project_id}/hub
ProjectsApipostStoragePOST /data/v1/projects/{project_id}/storage
ProjectsApipostVersionPOST /data/v1/projects/{project_id}/versions
ProjectsApigetHubProjectsGET /project/v1/hubs/{hub_id}/projects
VersionsApigetVersionGET /data/v1/projects/{project_id}/versions/{version_id}
VersionsApigetVersionItemGET /data/v1/projects/{project_id}/versions/{version_id}/item
VersionsApigetVersionRefsGET /data/v1/projects/{project_id}/versions/{version_id}/refs
VersionsApigetVersionRelationshipsRefsGET /data/v1/projects/{project_id}/versions/{version_id}/relationships/refs
VersionsApipostVersionRelationshipsRefPOST /data/v1/projects/{project_id}/versions/{version_id}/relationships/refs
WorkItemsApicreateWorkItemPOST /autocad.io/us-east/v2/WorkItemsCreates a new WorkItem.
WorkItemsApideleteWorkItemDELETE /autocad.io/us-east/v2/WorkItems('{id}')Removes a specific WorkItem.
WorkItemsApigetAllWorkItemsGET /autocad.io/us-east/v2/WorkItemsReturns the details of all WorkItems.
WorkItemsApigetWorkItemGET /autocad.io/us-east/v2/WorkItems('{id}')Returns the details of a specific WorkItem.

Thumbnail

thumbnail

Support

forge.help@autodesk.com

About

Forge Java SDK: Provides Java SDK to help you easily integrate Forge REST APIs into the application

Resources

Stars

38 stars

Watchers

15 watching

Forks

Releases

Packages

Used by

Contributors

Languages