C# · Track 1 · Tutorial 1 of 3

Set up your C# project

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

You will needThe .NET 8 SDK 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 C# and your settings are ready.

1Check .NET

You need the .NET 8 SDK or later. Nothing else is installed: the scripts use .NET's own HttpClient and System.Text.Json.

dotnet --version

Check

It prints 8.0 or later. If dotnet isn't found, install the .NET SDK first.

2Create the project

Create a console project called BrizoTutorial in a folder called brizo-tutorial:

dotnet new console -o brizo-tutorial -n BrizoTutorial
cd brizo-tutorial

Each tutorial adds one script: a class with a Run method, in its own file. Replace Program.cs with this, so dotnet run -- Companies runs the class called Companies:

Program.cs

// Program.cs - runs the tutorial script you name, for example:  dotnet run -- Companies
using System.Reflection;

var name = args.Length > 0 ? args[0] : "Setup";
var script = Assembly.GetExecutingAssembly().GetType(name)?.GetMethod("Run");
if (script is null)
{
    Console.Error.WriteLine($"There is no script called {name}.");
    return 1;
}

await (Task)script.Invoke(null, new object[] { args[1..] })!;
return 0;
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.cs with the Brizo class and the part that reads the settings. The next two tutorials add signing in and sending requests inside the same class.

Brizo.cs

using System.Globalization;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;

public record Answer(int Status, Dictionary<string, string> Headers, JsonNode? Body);

public static class Brizo
{
    const int TimeoutSeconds = 60;

    public static string Setting(string name)
    {
        var value = Environment.GetEnvironmentVariable(name);
        if (string.IsNullOrEmpty(value))
        {
            Console.Error.WriteLine($"Set the environment variable {name} first.");
            Environment.Exit(1);
        }
        return value;
    }

    public static readonly string BaseUrl = Setting("BRIZO_BASE_URL").TrimEnd('/'); // e.g. https://sg.brizoconsol.com/api/v1
    static readonly string ClientId = Setting("BRIZO_CLIENT_ID");
    static readonly string ClientSecret = Setting("BRIZO_CLIENT_SECRET");
    public static readonly string CompanyId = Setting("BRIZO_COMPANY_ID");

    // An amount as 1,234.56, whether the answer holds it as a number or as text.
    public static string Money(JsonNode? amount) =>
        double.Parse(amount!.ToString(), CultureInfo.InvariantCulture).ToString("N2", CultureInfo.InvariantCulture);
}
Settings flow from the environment into Brizo.cs, then into every script
The secret never appears in a script: Brizo.cs reads it from the environment.

5Run the check

Create Setup.cs:

Setup.cs

// Setup.cs - checks that .NET and your settings are ready.
public static class Setup
{
    public static Task Run(string[] args)
    {
        var version = Environment.Version;
        Console.WriteLine($".NET {version}" + (version.Major >= 8 ? " - ready" : " - needs 8 or later"));

        Console.WriteLine($"Base URL: {Brizo.BaseUrl}");
        Console.WriteLine($"Company: {Brizo.CompanyId}");
        return Task.CompletedTask;
    }
}
dotnet run -- Setup

Check

.NET 8.0.33 - ready
Base URL: https://sg.brizoconsol.com/api/v1
Company: 149

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

Want more detail? See the documentation