---
title: PHP quick start
summary: Install the bimbase/bimworks Composer package, log in with an API token, list your tree, upload a model and query it, in one script.
order: 60
languages: [php]
terms: [api-token, auth-token, node, version, qid, bql]
see-also: [how-to/install/php, how-to/auth/log-in-with-an-api-token, tutorials/openapi/getting-started, reference/sdk/php]
featured: true
---

# PHP quick start

The PHP [[term:sdk|SDK]] is generated from the OpenAPI description, so it offers exactly the operations of the [OpenAPI](../openapi/index.md) as typed classes: one `Api` class per tag (`AuthApi`, `FsApi`, `ModelApi`, `IFCApi`, `GISApi` and [[page:reference/sdk/php#classes|the others]]) and one `Model` class per schema. PHP 8.1 or later, with the `curl`, `json` and `mbstring` extensions.

## Install

The package is `bimbase/bimworks` on the BIM.works Composer repository. Add the repository and the package:

```shell {#install}
composer config repositories.bimworks composer https://composer.bim.works
composer require bimbase/bimworks
```

The repository needs the credentials your BIM.works contact gives you, stored in `auth.json`; [[page:how-to/install/php]] shows how. The classes live in the `BIMworks` namespace and load through Composer's autoloader.

## Log in

```example
name: php-quick-start
code: php/quick-start.php
notes: |
  The script has the four steps of every PHP SDK example (reference/sdk/php): it connects once, then repeats the request, the call and the result for each of its three calls. A `Configuration` carries the host and, after the login, the auth token; every `Api` object is created with it. `loginWithApiToken` returns an `AuthResult` whose `getBase64()` is the token to send as bearer, valid for at most 90 days.
highlight: 14-17,19-32,34-42,44-53
```

The host is your instance's address followed by `/openapi`; the generated default points at `https://dev.bim.works/openapi`, so always set it. Every call throws `BIMworks\ApiException` on a non-2xx response, with the HTTP code and the server's `ErrorResponse` in the message. The script has the same four steps as every example of the PHP SDK ([[page:reference/sdk/php#example-shape]]): it connects once and repeats the request, the call and the result for each call.

## List the tree

`FsApi::getRootNodeUuid()` is the node your token was created on and returns its UUID as a string; `listNodes` takes a `ListNodesRequest` with a `path` relative to that root (or a `uuid`) and returns an array of `Node` objects. The script makes the request from its JSON with `ObjectSerializer::deserialize`, as every example does. `getName()`, `getFolder()`, `getPath()` and `getLastVersionUuid()` are the getters you need; a folder has no last version.

## Upload

`ModelApi::uploadModel` takes the form fields as named arguments (the script spreads an array of them into the call): the `file`, an `SplFileObject`, its `filename`, and optionally the `node_uuid` of the folder or model node to upload into (the root of your token without it). It sends the file as `multipart/form-data` and returns the new `ModelVersion` when the server has processed it. Pass `filename`: the server names the model and reads its file type from it. `addModelWithUrl` is the alternative for files the server can fetch itself.

## Query

`IFCApi::query()` takes a `QueryRequest` with the models (a `VersionModelIdentifier` per version UUID, with its `type`) and the [[term:bql|BQL]] text, and returns the rows as an array of `stdClass` objects, one per row with every feature under its path; the script prints them as JSON. An empty `models` array validates the query without running it. The [BQL course](../bql/index.md) teaches the language.

## Where to go from here

The other operations follow the same request-object pattern: `AuthApi::createVersionsToken` for tokens that only see the versions you name ([[page:explanation/tokens-and-delegation]]), `IFCApi::check` for IDS and BCL checks, `ModelApi::download` and `VersionsApi::version` for the original file, `IFCApi::commitTransaction` to write changes back. The generated [[page:reference/sdk/php|PHP reference]] lists every class; the OpenAPI [[page:api|reference]] describes the operations themselves.
