PHP
Install the PHP SDK, the bimbase/bimworks Composer package, from the private registry, and check that it logs in.
For PHP developers. The PHP SDK is one of the OpenAPI SDKs (SDKs): it is generated from the OpenAPI document, so it covers the operations of the OpenAPI (login and tokens, the account, the tree, uploads and downloads, queries, checks, model comparison, transactions, actions, workspaces, linked data, geo references, CityGML and 3D Tiles, renders, text to action) and talks plain HTTPS through Guzzle. See PHP SDK for the classes and PHP quick start for a first script.
Before you start#
- PHP 8.1 or newer with the
curl,jsonandmbstringextensions. - Composer.
- Credentials for the private registry
https://composer.bim.works. Your company portal has them, or ask support@bimbase.nl.
1. Register the repository#
Add the registry to composer.json:
"repositories": [
{
"type": "composer",
"url": "https://composer.bim.works"
}
]2. Store the credentials#
Create auth.json next to composer.json (or in ~/.composer/), and keep it out of version control:
{
"http-basic": {
"composer.bim.works": {
"username": "[your username]",
"password": "[your password]"
}
}
}3. Require the package#
Use the version that matches your BIM.works server (the version pill at the top of this page is the server's):
"require": {
"bimbase/bimworks": "3.0.0-beta.192"
}Then run composer install (or composer update bimbase/bimworks). The package autoloads the BIMworks\ namespace: API classes live in BIMworks\Api, one per tag of the document (AuthApi, FsApi, ModelApi, IFCApi, GISApi, … all of them) and request and response models in BIMworks\Model.
Check#
Save the program below as check.php next to composer.json, put in your address and API token, and run php check.php. It connects to your instance's OpenAPI root (the application address plus /openapi), logs in, and asks for the root node of that token. Every example of the PHP SDK has these four steps (reference/sdk/php#example-shape).
<?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;It prints a UUID. The two calls are AuthApi::loginWithApiToken and FsApi::getRootNodeUuid in PHP SDK, the operations behind them LoginWithApiToken and GetRootNodeUuid. Next: Log in with an API token.