This PHP SDK enables you to easily integrate the Forge REST APIs into your application, including OAuth, Data Management, Model Derivative, and Design Automation.
- PHP version 5.4.0 and above.
- A registered app on the Forge Developer portal.
- Documentation is not everywhere since fork
- Forked from forge-php-client to fix deprecation since 30/09/2022 and keep this package working
To install the bindings via Composer, run:
composer require autodesk/forge-client
Download the files and include autoload.php
:
require_once('/path/to/ForgeClient/autoload.php');
Follow this tutorial to see a step-by-step authentication guide, and examples of how to use the Forge APIs.
Create an app on the Forge Developer portal. Note the client ID and client secret.
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.
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.
<?php
Autodesk\Auth\Configuration::getDefaultConfiguration()
->setClientId('<your-client-id>')
->setClientSecret('<your-client-secret>');
$twoLeggedAuth = new Autodesk\Auth\OAuth2\TwoLeggedAuth();
$twoLeggedAuth->setScopes(['bucket:read']);
$twoLeggedAuth->fetchToken();
$tokenInfo = [
'applicationToken' => $twoLeggedAuth->getAccessToken(),
'expiry' => time() + $twoLeggedAuth->getExpiresIn(),
];
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.
<?php
Autodesk\Auth\Configuration::getDefaultConfiguration()
->setClientId('<your-client-id>')
->setClientSecret('<your-client-secret>')
->setRedirectUrl('<your-redirect-url>');
$threeLeggedAuth = new Autodesk\Auth\OAuth2\ThreeLeggedAuth();
$threeLeggedAuth->addScope('code:all');
$authUrl = $threeLeggedAuth->createAuthUrl();
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}
Request an access token using the authorization code you received, as shown below:
<?php
Autodesk\Auth\Configuration::getDefaultConfiguration()
->setClientId('<your-client-id>')
->setClientSecret('<your-client-secret>')
->setRedirectUrl('<your-redirect-url>');
$threeLeggedAuth = new Autodesk\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.
Use the TwoLeggedAuth
object or the ThreeLeggedAuth
object to call the Forge APIs.
<?php
$apiInstance = new Autodesk\Forge\Client\Api\ActivitiesApi($threeLeggedAuth);
$activity = new \Autodesk\Forge\Client\Model\Activity(); // \Autodesk\Forge\Client\Model\Activity
$result = $apiInstance->createActivity($activity);
You can get the full documentation for the API on the Developer Portal
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'.
Class | Method | HTTP request | Description |
---|---|---|---|
ActivitiesApi | createActivity | POST /autocad.io/us-east/v2/Activities | Creates a new Activity. |
ActivitiesApi | deleteActivity | DELETE /autocad.io/us-east/v2/Activities('{id}') | Removes a specific Activity. |
ActivitiesApi | deleteActivityHistory | POST /autocad.io/us-east/v2/Activities('{id}')/Operations.DeleteHistory | Removes the version history of the specified Activity. |
ActivitiesApi | getActivity | GET /autocad.io/us-east/v2/Activities('{id}') | Returns the details of a specific Activity. |
ActivitiesApi | getActivityVersions | GET /autocad.io/us-east/v2/Activities('{id}')/Operations.GetVersions | Returns all old versions of a specified Activity. |
ActivitiesApi | getAllActivities | GET /autocad.io/us-east/v2/Activities | Returns the details of all Activities. |
ActivitiesApi | patchActivity | PATCH /autocad.io/us-east/v2/Activities('{id}') | Updates an Activity by specifying only the changed attributes. |
ActivitiesApi | setActivityVersion | POST /autocad.io/us-east/v2/Activities('{id}')/Operations.SetVersion | Sets the Activity to the specified version. |
AppPackagesApi | createAppPackage | POST /autocad.io/us-east/v2/AppPackages | Creates an AppPackage module. |
AppPackagesApi | deleteAppPackage | DELETE /autocad.io/us-east/v2/AppPackages('{id}') | Removes a specific AppPackage. |
AppPackagesApi | deleteAppPackageHistory | POST /autocad.io/us-east/v2/AppPackages('{id}')/Operations.DeleteHistory | Removes the version history of the specified AppPackage. |
AppPackagesApi | getAllAppPackages | GET /autocad.io/us-east/v2/AppPackages | Returns the details of all AppPackages. |
AppPackagesApi | getAppPackage | GET /autocad.io/us-east/v2/AppPackages('{id}') | Returns the details of a specific AppPackage. |
AppPackagesApi | getAppPackageVersions | GET /autocad.io/us-east/v2/AppPackages('{id}')/Operations.GetVersions | Returns all old versions of a specified AppPackage. |
AppPackagesApi | getUploadUrl | GET /autocad.io/us-east/v2/AppPackages/Operations.GetUploadUrl | Requests a pre-signed URL for uploading a zip file that contains the binaries for this AppPackage. |
AppPackagesApi | getUploadUrlWithRequireContentType | GET /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. |
AppPackagesApi | patchAppPackage | PATCH /autocad.io/us-east/v2/AppPackages('{id}') | Updates an AppPackage by specifying only the changed attributes. |
AppPackagesApi | setAppPackageVersion | POST /autocad.io/us-east/v2/AppPackages('{id}')/Operations.SetVersion | Sets the AppPackage to the specified version. |
AppPackagesApi | updateAppPackage | PUT /autocad.io/us-east/v2/AppPackages('{id}') | Updates an AppPackage by redefining the entire Activity object. |
BucketsApi | createBucket | POST /oss/v2/buckets | |
BucketsApi | deleteBucket | DELETE /oss/v2/buckets/{bucketKey} | |
BucketsApi | getBucketDetails | GET /oss/v2/buckets/{bucketKey}/details | |
BucketsApi | getBuckets | GET /oss/v2/buckets | |
DerivativesApi | deleteManifest | DELETE /modelderivative/v2/designdata/{urn}/manifest | |
DerivativesApi | getDerivativeManifest | GET /modelderivative/v2/designdata/{urn}/manifest/{derivativeUrn} | |
DerivativesApi | getFetchDerivativeManifest | GET /modelderivative/v2/designdata/{urn}/manifest/{derivativeUrn}/signedcookies | |
DerivativesApi | getFormats | GET /modelderivative/v2/designdata/formats | |
DerivativesApi | getManifest | GET /modelderivative/v2/designdata/{urn}/manifest | |
DerivativesApi | getMetadata | GET /modelderivative/v2/designdata/{urn}/metadata | |
DerivativesApi | getModelviewMetadata | GET /modelderivative/v2/designdata/{urn}/metadata/{guid} | |
DerivativesApi | getModelviewProperties | GET /modelderivative/v2/designdata/{urn}/metadata/{guid}/properties | |
DerivativesApi | getThumbnail | GET /modelderivative/v2/designdata/{urn}/thumbnail | |
DerivativesApi | translate | POST /modelderivative/v2/designdata/job | |
EnginesApi | getAllEngines | GET /autocad.io/us-east/v2/Engines | Returns the details of all available AutoCAD core engines. |
EnginesApi | getEngine | GET /autocad.io/us-east/v2/Engines('{id}') | Returns the details of a specific AutoCAD core engine. |
FoldersApi | getFolder | GET /data/v1/projects/{project_id}/folders/{folder_id} | |
FoldersApi | getFolderContents | GET /data/v1/projects/{project_id}/folders/{folder_id}/contents | |
FoldersApi | getFolderParent | GET /data/v1/projects/{project_id}/folders/{folder_id}/parent | |
FoldersApi | getFolderRefs | GET /data/v1/projects/{project_id}/folders/{folder_id}/refs | |
FoldersApi | getFolderRelationshipsRefs | GET /data/v1/projects/{project_id}/folders/{folder_id}/relationships/refs | |
FoldersApi | postFolder | POST /data/v1/projects/{project_id}/folders | |
FoldersApi | postFolderRelationshipsRef | POST /data/v1/projects/{project_id}/folders/{folder_id}/relationships/refs | |
HubsApi | getHub | GET /project/v1/hubs/{hub_id} | |
HubsApi | getHubs | GET /project/v1/hubs | |
ItemsApi | getItem | GET /data/v1/projects/{project_id}/items/{item_id} | |
ItemsApi | getItemParentFolder | GET /data/v1/projects/{project_id}/items/{item_id}/parent | |
ItemsApi | getItemRefs | GET /data/v1/projects/{project_id}/items/{item_id}/refs | |
ItemsApi | getItemRelationshipsRefs | GET /data/v1/projects/{project_id}/items/{item_id}/relationships/refs | |
ItemsApi | getItemTip | GET /data/v1/projects/{project_id}/items/{item_id}/tip | |
ItemsApi | getItemVersions | GET /data/v1/projects/{project_id}/items/{item_id}/versions | |
ItemsApi | postItem | POST /data/v1/projects/{project_id}/items | |
ItemsApi | postItemRelationshipsRef | POST /data/v1/projects/{project_id}/items/{item_id}/relationships/refs | |
ObjectsApi | copyTo | PUT /oss/v2/buckets/{bucketKey}/objects/{objectName}/copyto/{newObjName} | |
ObjectsApi | createSignedResource | POST /oss/v2/buckets/{bucketKey}/objects/{objectName}/signed | |
ObjectsApi | deleteObject | DELETE /oss/v2/buckets/{bucketKey}/objects/{objectName} | |
ObjectsApi | deleteSignedResource | DELETE /oss/v2/signedresources/{id} | |
ObjectsApi | getObject | GET /oss/v2/buckets/{bucketKey}/objects/{objectName} | |
ObjectsApi | getObjectDetails | GET /oss/v2/buckets/{bucketKey}/objects/{objectName}/details | |
ObjectsApi | getObjects | GET /oss/v2/buckets/{bucketKey}/objects | |
ObjectsApi | getSignedResource | GET /oss/v2/signedresources/{id} | |
ObjectsApi | getSignedUrls | GET /oss/v2/buckets/{bucketKey}/objects/{objectKey}/signeds3upload | |
ObjectsApi | getStatusBySessionId | GET /oss/v2/buckets/{bucketKey}/objects/{objectName}/status/{sessionId} | |
ObjectsApi | uploadChunk | PUT /oss/v2/buckets/{bucketKey}/objects/{objectName}/resumable | |
ObjectsApi | uploadObject | PUT /oss/v2/buckets/{bucketKey}/objects/{objectName} | |
ObjectsApi | uploadSignedResource | PUT /oss/v2/signedresources/{id} | |
ObjectsApi | uploadSignedResourcesChunk | PUT /oss/v2/signedresources/{id}/resumable | |
ProjectsApi | getHubProjects | GET /project/v1/hubs/{hub_id}/projects | |
ProjectsApi | getProject | GET /project/v1/hubs/{hub_id}/projects/{project_id} | |
ProjectsApi | getProjectHub | GET /project/v1/hubs/{hub_id}/projects/{project_id}/hub | |
ProjectsApi | getProjectTopFolders | GET /project/v1/hubs/{hub_id}/projects/{project_id}/topFolders | |
ProjectsApi | postSignedUpload | GET /oss/v2/buckets/{bucketKey}/objects/{objectKey}/signeds3upload | |
ProjectsApi | postStorage | POST /data/v1/projects/{project_id}/storage | |
UserProfileApi | getUserProfile | GET /userprofile/v1/users/@me | Returns the profile information of an authorizing end user. |
VersionsApi | getVersion | GET /data/v1/projects/{project_id}/versions/{version_id} | |
VersionsApi | getVersionItem | GET /data/v1/projects/{project_id}/versions/{version_id}/item | |
VersionsApi | getVersionRefs | GET /data/v1/projects/{project_id}/versions/{version_id}/refs | |
VersionsApi | getVersionRelationshipsRefs | GET /data/v1/projects/{project_id}/versions/{version_id}/relationships/refs | |
VersionsApi | postVersion | POST /data/v1/projects/{project_id}/versions | |
VersionsApi | postVersionRelationshipsRef | POST /data/v1/projects/{project_id}/versions/{version_id}/relationships/refs | |
WorkItemsApi | createWorkItem | POST /autocad.io/us-east/v2/WorkItems | Creates a new WorkItem. |
WorkItemsApi | deleteWorkItem | DELETE /autocad.io/us-east/v2/WorkItems('{id}') | Removes a specific WorkItem. |
WorkItemsApi | getAllWorkItems | GET /autocad.io/us-east/v2/WorkItems | Returns the details of all WorkItems. |
WorkItemsApi | getWorkItem | GET /autocad.io/us-east/v2/WorkItems('{id}') | Returns the details of a specific WorkItem. |
new version of library