Using Origins

Switchboard supports request attribution and audit tracking via Origins. Origins act as request metadata identifying the specific booth, device, or capture station (e.g., "Booth-01", "Booth-02", or "Booth-03") that initiated a capture request.

Configuring the Client SDK

You can configure origin attribution in the client library in three ways: globally during registration, dynamically via ambient context, or explicitly on individual calls.

Method 1: Global Registration

Pass the default origin identifier when registering the client or using the factory:

using Switchboard.Client;
using Switchboard.Client.DependencyInjection;

// Dependency Injection:
builder.Services.AddSwitchboardClient(
    baseUrl: "https://switchboard.dnpcloud.com",
    apiKey: "your-api-key",
    origin: "Booth-01"
);

// Static Factory:
var client = SwitchboardClientFactory.Create(
    baseUrl: "https://switchboard.dnpcloud.com",
    apiKey: "your-api-key",
    origin: "Booth-01"
);

Method 2: Dynamic Ambient Context

For multi-tenant workflows or dynamic contexts, use OriginContext to set the active origin for the current asynchronous execution context:

using Switchboard.Client;

// Temporary origin override:
using (OriginContext.Begin("Booth-02"))
{
    // Any requests triggered inside this block will include 'Booth-02' in the X-Origin-Id header
    var capture = await client.UploadAsync("filter-id", stream, 1024, 1024);
}

Method 3: Explicit Parameter Passing

For one-off overrides, pass the origin parameter directly to the extension methods:

// Pass the origin parameter before the cancellation token
var capture = await client.UploadAsync(
    filter: "filter-id",
    stream: imageStream,
    width: 1024,
    height: 1024,
    origin: "Booth-03"
);

Direct HTTP Integration

If you are calling the REST API directly using custom HTTP libraries, pass the origin identifier in the X-Origin-Id request header:

POST /captures HTTP/1.1
Host: switchboard.dnpcloud.com
x-api-key: your-api-key
x-workspace-id: sandbox
X-Origin-Id: Booth-01
Content-Type: multipart/form-data; boundary=boundary-string

...