PHP · Track 1 · Tutorial 1 of 3

Set up your PHP project

Get a PHP project ready for the BrizoConsol API: check PHP, create the folder every tutorial in this series builds on, and keep your credential where your code can read it but nobody else can.

You will needPHP 8.0 or later, and the credential and API address from Getting started.
By the endA project folder with a shared client file, and a check that says PHP and your settings are ready.

1Check PHP

You need PHP 8.0 or later with the curl extension, which most installations include. Nothing else is installed: the scripts use PHP's own cURL and JSON.

php --version
php -m

Check

The first line says PHP 8 or later, and curl is in the list of modules. If it isn't, turn on extension=curl in your php.ini.

2Create the project folder

Make a folder called brizo-tutorial. Every script in this series goes in it, next to one shared file.

The project folder and the four settings
The project: one folder, one shared file, and four settings kept outside the code.

3Keep your settings out of the code

Your client secret is a password: keep it out of any file you might share. Set the four settings as environment variables in the terminal you'll run the scripts from. In bash or zsh:

export BRIZO_BASE_URL=https://sg.brizoconsol.com/api/v1
export BRIZO_CLIENT_ID=your-client-id
export BRIZO_CLIENT_SECRET=your-client-secret
export BRIZO_COMPANY_ID=149

In PowerShell:

$env:BRIZO_BASE_URL = "https://sg.brizoconsol.com/api/v1"
$env:BRIZO_CLIENT_ID = "your-client-id"
$env:BRIZO_CLIENT_SECRET = "your-client-secret"
$env:BRIZO_COMPANY_ID = "149"

Use your own region's address, the client ID and secret from Getting started, and your company's ID. You'll find the ID in tutorial 3; until then leave 149.

4Add the shared client

Create brizo.php with the part that reads the settings. The next two tutorials add signing in and sending requests to the same file.

brizo.php

const BRIZO_TIMEOUT = 60; // seconds

function setting(string $name): string
{
    $value = getenv($name);
    if ($value === false || $value === '') {
        fwrite(STDERR, "Set the environment variable $name first.\n");
        exit(1);
    }
    return $value;
}

$baseUrl = rtrim(setting('BRIZO_BASE_URL'), '/');   // e.g. https://sg.brizoconsol.com/api/v1
$clientId = setting('BRIZO_CLIENT_ID');
$clientSecret = setting('BRIZO_CLIENT_SECRET');
$companyId = setting('BRIZO_COMPANY_ID');
Settings flow from the environment into brizo.php, then into every script
The secret never appears in a script: brizo.php reads it from the environment.

5Run the check

Create setup.php:

setup.php

<?php
// setup.php - checks that PHP and your settings are ready.

echo 'PHP ' . PHP_VERSION . (version_compare(PHP_VERSION, '8.0', '>=') ? " - ready\n" : " - needs 8.0 or later\n");
echo 'cURL: ' . (extension_loaded('curl') ? "installed\n" : "missing - turn on the curl extension in php.ini\n");

require __DIR__ . '/brizo.php';

echo "Base URL: $baseUrl\n";
echo "Company: $companyId\n";
php setup.php

Check

PHP 8.3.6 - ready
cURL: installed
Base URL: https://sg.brizoconsol.com/api/v1
Company: 149

Your PHP version and address will be your own. If a setting is missing, the script names it and stops.

Want more detail? See the documentation