PHP SDK

The PHP SDK generated from the OpenAPI document (Composer bimbase/bimworks) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.

The PHP SDK is generated from the OpenAPI document: one API class per group of operations, one method per operation, and a model class per request and response. It talks HTTPS through Guzzle. Since 3.0 it is generated with openapi-generator's php-nextgen generator, which needs PHP 8.1 and has typed properties and return types.

Package#

Package bimbase/bimworks from the BIM.works Composer registry, version equal to your BIM.works server (PHP)
PHP 8.1 or later, with the curl, json and mbstring extensions
Namespaces BIMworks\Api (the API classes), BIMworks\Model (the models), BIMworks (Configuration, ObjectSerializer, ApiException)
Dependencies Guzzle 7 and guzzlehttp/psr7 2, installed by Composer

An example is a script next to your composer.json: it loads vendor/autoload.php and runs with php example.php.

Connect and log in#

A Configuration holds the address of your instance's OpenAPI root (BIM_WORKS_ADDRESS/openapi) and, after the login, the bearer token; every API class is made from it (new IFCApi(config: $client), a named argument, because the first one is the Guzzle client). The login, LoginWithApiToken with your API token, answers an AuthResult whose getBase64() is the auth token; setAccessToken makes every later call send it. Use the default response_format: the PHP SDK cannot read the plain-string answer of "base64".

<?php
require __DIR__ . '/vendor/autoload.php';

use BIMworks\Api\AuthApi;
use BIMworks\Api\FsApi;
use BIMworks\Configuration;
use BIMworks\Model\LoginWithApiTokenRequest;

// 1. Connect to BIM.works and log in with your API token
$client = (new Configuration())->setHost('https://bim.works/openapi');
$auth = (new AuthApi(config: $client))->loginWithApiToken(new LoginWithApiTokenRequest(['token' => "<your API token>"]));
$client->setAccessToken($auth->getBase64());

// 2. The request
// (GetRootNodeUuid takes no request)

// 3. The call
$result = (new FsApi(config: $client))->getRootNodeUuid();

// 4. The result
echo $result, PHP_EOL;

Every example in four steps#

Every example on these pages and on the operation pages of the API part is a complete script in the same four steps (reference/sdk#example-shape):

  1. Connect — the Configuration, logged in as above. An operation that needs no login (the logins, GetApplicationVersion) skips the login.
  2. The request — ObjectSerializer::deserialize($json, Model::class) makes the request from the JSON with the wire names that the operation's page shows, in a nowdoc, so nothing in it is escaped. Multipart operations take their form fields as an array of named arguments, spread into the call (...$request).
  3. The call — (new Api(config: $client))->method($request).
  4. The result — printed with json_encode, which writes the wire names; a file is copied into place, and a call without a result prints Done.

So the same JSON goes into every language, and copying an example is enough once the package is installed. With several calls, keep one $client and repeat steps 2 to 4.

Classes#

ClassGroupMethods
ActionsApiActionsaddAction, deleteAction, getAction, listActions, undeleteAction, updateAction
LinkedDataApiLinked dataaddLinkTargets, confirmLinkMatch, deleteLinkedData, downloadLinkedData, endLink, getLinkedData, getLinkedDataCounts, getLinkedDataPolicy, linkData, listLinkedData, reattachLink, replaceLinkedData, restoreLinkedData, unlinkData, updateLinkedData
ModelApiModeladdModelWithUrl, augmentBcf, download, downloadIfcXml, exportGeometry, exportVectorSvg, getCheckin, getValidationReport, lookupModelHashes, render, schemaConversionReport, uploadModel
AccountApiAccountchangePassword, getSettings, listReferenceValues, logout, register, requestPasswordReset, requestValidationEmail, saveSettings, signOutOtherSessions, validateEmailAddress
IFCApiIFC - Industry Foundation Classescheck, commitTransaction, compareModels, compareObjects, deleteComparePairOverride, exportCompareResult, getCompareBul, getCompareResult, getMatchCandidates, getObjectHistory, getVersionChanges, listBuildingStoreys, listComparePairOverrides, mapQids, parseQuery, query, recordUploadAsTransaction, resolveBvl, setComparePairOverride, textSearch, upgradeSyntax
GISApiGIS - Geographic Information SystemscopyGeoReference, exportCityGML3, extractGeoReference, generate3DTilesUrl, getGeoReference, setGeoReference
AuthApiAuth - AuthenticationcreateAnonymousToken, createApiToken, createNodesToken, createRecursiveNodeToken, createVersionsToken, deleteApiToken, getSession, listApiTokens, loginAnonymous, loginWithAnonymousToken, loginWithApiToken, loginWithUsernamePassword, updateApiToken
FsApiFs - FileSystemcreateNode, deleteNode, deleteNodeError, deleteVersion, downloadAsZip, getNode, getRootNodeUuid, getVersion, listNodeErrors, listNodes, listNodesRecursive, listVersions, moveNode, undeleteNode, updateNode, updateVersion
WorkspacesApiWorkspacescreateWorkspace, deleteWorkspace, listWorkspaces, publishWorkspace, updateWorkspace
InfoApiInfogetApplicationVersion
ViewerApiViewergetGeometryMetaData
AdminApiAdminlistAccountUserFeatures, listAccounts, listOrganizations
AIApiAI - Artificial IntelligencetextToAction
VersionsApiVersionsversion
ModelsRequests and responses289 model classes

In code, every model property has a getter and a setter. Build a request from JSON with ObjectSerializer::deserialize rather than with a model's constructor: the constructor takes PHP property names and leaves nested objects as arrays, and a model identifier without its type cannot be sent. A key the model does not have is dropped, so use the names on the models page.

Errors#

A call that the server answers with an error status throws BIMworks\ApiException: getCode() is the HTTP status, getResponseBody() the server's error (Errors) and getResponseObject() its ErrorResponse.

PHP#
try {
    (new IFCApi(config: $client))->query($request);
} catch (\BIMworks\ApiException $e) {
    echo $e->getCode(), ' ', $e->getResponseBody(), PHP_EOL;
}

Query decodes its answer as JSON, so a query with "format": "csv", "xlsx", "ifc" or "ifcxml" throws an ApiException with code 200 whose getResponseBody() is the file.

Files#

  • Downloads return an SplFileObject on a temporary file; the examples copy it into place.
  • Uploads take an SplFileObject. The examples also pass filename: the server names the model and reads its file type from filename, and without it the SDK sends model.ifc.

Pages#

  • Java SDKThe Java SDK generated from the OpenAPI document (Maven nl.bimbase.bimworks:sdk) — the artifact, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • .NET SDKThe .NET SDK generated from the OpenAPI document (NuGet BIMworks.Sdk) — the package, connecting and logging in, the four steps of every example, the API classes and models, responses and errors, files and uploads.
  • TypeScript SDKThe TypeScript and JavaScript SDK generated from the OpenAPI document (npm @bimworks/sdk) — installation, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • PHP SDKThe PHP SDK generated from the OpenAPI document (Composer bimbase/bimworks) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.
  • Python SDKThe Python SDK generated from the OpenAPI document (bimworks on the BIM.works Python index) — the package, connecting and logging in, the four steps of every example, the API classes and models, errors, files and uploads.