Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Repository files navigation

UNSUPPORTED

Forge PHP SDK

Forge API: oAuth2Data-ManagementOSSModel-Derivative

Overview

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

Requirements

Installation

Composer

To install the bindings via Composer, run:

composer require autodesk/forge-client

Manual Installation

Download the files and include autoload.php:

require_once('/path/to/ForgeClient/autoload.php');

Tutorial

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

Create an App

Create an app on the Forge Developer portal. Note the client ID and client secret.

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. The tutorial uses 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. Note that you need to replace your-client-id and your-client-secret with your app's client ID and client secret.

<?phpAutodesk\Auth\Configuration::getDefaultConfiguration()
->setClientId('<your-client-id>')
->setClientSecret('<your-client-secret>');
$twoLeggedAuth = newAutodesk\Auth\OAuth2\TwoLeggedAuth();
$twoLeggedAuth->setScopes(['bucket:read']);
$twoLeggedAuth->fetchToken();
$tokenInfo = [
'applicationToken' => $twoLeggedAuth->getAccessToken(),
'expiry' => time() + $twoLeggedAuth->getExpiresIn(),
];

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.

Replace your-client-id, your-client-secret, and your-redirect-url with your app's client ID, client secret, and redirect URL, and run the code to create a consent page URL.

Note that the redirect URL must match the callback URL you provided when you created the app.

<?phpAutodesk\Auth\Configuration::getDefaultConfiguration()
->setClientId('<your-client-id>')
->setClientSecret('<your-client-secret>')
->setRedirectUrl('<your-redirect-url>');
$threeLeggedAuth = newAutodesk\Auth\OAuth2\ThreeLeggedAuth();
$threeLeggedAuth->addScope('code:all');
$authUrl = $threeLeggedAuth->createAuthUrl();
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:

<?phpAutodesk\Auth\Configuration::getDefaultConfiguration()
->setClientId('<your-client-id>')
->setClientSecret('<your-client-secret>')
->setRedirectUrl('<your-redirect-url>');
$threeLeggedAuth = newAutodesk\Auth\OAuth2\ThreeLeggedAuth();
$threeLeggedAuth->addScope('code:all');
$threeLeggedAuth->fetchToken($_GET['code']);
$userToken = [
'accessToken' => $threeLeggedAuth->getAccessToken(),
'refreshToken' => $threeLeggedAuth->getRefreshToken(),
'expiry' => time() + $threeLeggedAuth->getExpiresIn(),
];

Note that access tokens expire after a short period of time. The expires_in field gives the validity of an access token in seconds. To refresh your access token, call the $threeLeggedAuth->refreshToken($refreshToken); method.

Example API Calls

Use the TwoLeggedAuth object or the ThreeLeggedAuth object to call the Forge APIs.

<?php$apiInstance = newAutodesk\Forge\Client\Api\ActivitiesApi($threeLeggedAuth);
$activity = new \Autodesk\Forge\Client\Model\Activity(); // \Autodesk\Forge\Client\Model\Activity$result = $apiInstance->createActivity($activity);

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, the createActivity URI is 'https://developer.api.autodesk.com/autocad.io/us-east/v2/Activities'.

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.
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/AppPackages/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
FoldersApipostFolderPOST /data/v1/projects/{project_id}/folders
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
ItemsApipostItemPOST /data/v1/projects/{project_id}/items
ItemsApipostItemRelationshipsRefPOST /data/v1/projects/{project_id}/items/{item_id}/relationships/refs
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
ObjectsApigetSignedResourceGET /oss/v2/signedresources/{id}
ObjectsApigetStatusBySessionIdGET /oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId}
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
ProjectsApigetHubProjectsGET /project/v1/hubs/{hub_id}/projects
ProjectsApigetProjectGET /project/v1/hubs/{hub_id}/projects/{project_id}
ProjectsApigetProjectHubGET /project/v1/hubs/{hub_id}/projects/{project_id}/hub
ProjectsApigetProjectTopFoldersGET /project/v1/hubs/{hub_id}/projects/{project_id}/topFolders
ProjectsApipostStoragePOST /data/v1/projects/{project_id}/storage
UserProfileApigetUserProfileGET /userprofile/v1/users/@meReturns the profile information of an authorizing end user.
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
VersionsApipostVersionPOST /data/v1/projects/{project_id}/versions
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 PHP SDK: Enables you to easily integrate the Forge REST APIs into your application, including OAuth, Data Management,Model Derivative, and Design Automation

Resources

Stars

41 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages