Each example follows these steps:
- Send
POST /warmupfor cameras 1 and 2, using their assigned Camera List numbers. - Check that the warmup operation succeeded.
- Wait 500 ms in the client.
- Send
POST /triggerfor those cameras and check its operation.
These are direct actions, not the configured trigger button. They do not inherit its countdown, repeat, or bound timeline. Current camera modes still apply. The delay is a settling interval, not confirmation that autofocus or other camera preparation has finished. Successful dispatch does not mean files are ready.
Before running
- To run on another computer, the operator must first turn on Settings > General > Allow API access from other computers. Use a trusted studio network only. Every device that can reach the API has full supported public API access; firewall, binding, and forwarding determine actual exposure.
- Confirm that the operator wants cameras 1 and 2 triggered. Change the example's
numbersarray when necessary. - Set these process environment variables through your terminal or application launcher:
| Variable | Value |
|---|---|
XANGLE_CAMERA_SERVER_HOST |
Optional server address. Defaults to 127.0.0.1; use the Camera Server computer's reachable address for remote access. |
XANGLE_CAMERA_SERVER_PORT |
Actual Camera Server HTTP port, usually 8680. |
XANGLE_CAPTURE_ID |
A UUID identifying one intended capture sequence. |
Generate the capture UUID once, using Node's crypto.randomUUID(), Python's uuid.uuid4(), or .NET's Guid.NewGuid(), and retain it. Both requests derive separate idempotency keys from that UUID. Keep the same UUID when recovering an uncertain request; use a new UUID only for a new intended capture. These examples do not automatically retry.
Read Connection and access and Operations and retries before adding retries. All API clients share history and idempotency keys, so do not reuse a UUID across unrelated clients or captures.
A network error or timeout does not prove the command failed. Reusing the same capture UUID and unchanged camera selection replays admitted requests rather than firing a second capture. Ambiguous legacy keys fail instead of redispatching. Do not renumber cameras during recovery.
If a previous operation failed, inspect its error instead of changing the UUID to force another attempt.
All three examples use standard runtime libraries, with no third-party packages. Run only the example you need, after approval to operate the cameras.
Node.js
Use Node.js 22 or newer, not browser JavaScript. Save as warmup-trigger.mjs and run node warmup-trigger.mjs.
const host = process.env.XANGLE_CAMERA_SERVER_HOST || "127.0.0.1";
const port = Number(process.env.XANGLE_CAMERA_SERVER_PORT);
const captureId = (process.env.XANGLE_CAPTURE_ID || "").toLowerCase();
if (!Number.isInteger(port) || port < 1 || port > 65535) {
throw new Error("Set XANGLE_CAMERA_SERVER_PORT to the actual HTTP port.");
}
if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(captureId)) {
throw new Error("Set XANGLE_CAPTURE_ID to a retained UUID for this sequence.");
}
const base = `http://${host}:${port}/api/v1`;
const body = JSON.stringify({ target: { numbers: [1, 2] } });
async function post(path) {
const response = await fetch(base + path, {
method: "POST",
redirect: "error",
signal: AbortSignal.timeout(15000),
headers: {
"Content-Type": "application/json",
"Idempotency-Key": `${captureId}:${path.slice(1)}`,
},
body,
});
const text = await response.text();
if (!response.ok) throw new Error(`HTTP ${response.status}: ${text}`);
const data = JSON.parse(text);
if (data.operation?.state !== "succeeded") {
throw new Error(`Operation did not succeed: ${text}`);
}
return data.operation;
}
await post("/warmup");
await new Promise(resolve => setTimeout(resolve, 500));
const operation = await post("/trigger");
console.log("Capture dispatched; operation:", operation.id);
Python
Use Python 3.10 or newer. This uses the standard library, not requests. Save as warmup_trigger.py and run python warmup_trigger.py.
import json
import os
import time
import uuid
import urllib.error
import urllib.request
host = os.environ.get("XANGLE_CAMERA_SERVER_HOST", "127.0.0.1")
port = int(os.environ["XANGLE_CAMERA_SERVER_PORT"])
capture_id = str(uuid.UUID(os.environ["XANGLE_CAPTURE_ID"]))
if not 1 <= port <= 65535:
raise ValueError("Set XANGLE_CAMERA_SERVER_PORT to the actual HTTP port.")
base = f"http://{host}:{port}/api/v1"
body = json.dumps({"target": {"numbers": [1, 2]}}).encode("utf-8")
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
def post(path):
request = urllib.request.Request(
base + path,
data=body,
method="POST",
headers={
"Content-Type": "application/json",
"Idempotency-Key": f"{capture_id}:{path[1:]}",
},
)
try:
with opener.open(request, timeout=15) as response:
data = json.load(response)
except urllib.error.HTTPError as error:
detail = error.read().decode("utf-8", errors="replace")
raise RuntimeError(f"HTTP {error.code}: {detail}") from None
if data.get("operation", {}).get("state") != "succeeded":
raise RuntimeError(f"Operation did not succeed: {json.dumps(data)}")
return data["operation"]
post("/warmup")
time.sleep(0.5)
operation = post("/trigger")
print("Capture dispatched; operation:", operation["id"])
C# / .NET
Use a .NET 8 or newer console application. Create one with dotnet new console -n CameraApiExample, replace its Program.cs with this code, and run dotnet run --project CameraApiExample. No NuGet packages are needed.
using System.Net.Http.Json;
using System.Text.Json;
string Required(string name) =>
Environment.GetEnvironmentVariable(name) is { Length: > 0 } value
? value
: throw new InvalidOperationException($"Set {name}.");
var host = Environment.GetEnvironmentVariable("XANGLE_CAMERA_SERVER_HOST") ?? "127.0.0.1";
var port = int.Parse(Required("XANGLE_CAMERA_SERVER_PORT"));
if (port < 1 || port > 65535)
throw new InvalidOperationException("Use the actual Camera Server HTTP port.");
var captureId = Guid.Parse(Required("XANGLE_CAPTURE_ID")).ToString("D");
using var handler = new HttpClientHandler { AllowAutoRedirect = false, UseProxy = false };
using var client = new HttpClient(handler) {
BaseAddress = new Uri($"http://{host}:{port}/api/v1/"),
Timeout = TimeSpan.FromSeconds(15),
};
var body = new { target = new { numbers = new[] { 1, 2 } } };
async Task<JsonElement> Post(string path)
{
using var request = new HttpRequestMessage(HttpMethod.Post, path) {
Content = JsonContent.Create(body),
};
request.Headers.Add("Idempotency-Key", $"{captureId}:{path}");
using var response = await client.SendAsync(request);
var text = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
throw new InvalidOperationException($"HTTP {(int)response.StatusCode}: {text}");
using var data = JsonDocument.Parse(text);
if (!data.RootElement.TryGetProperty("operation", out var operation)
|| !operation.TryGetProperty("state", out var state)
|| state.GetString() != "succeeded")
throw new InvalidOperationException($"Operation did not succeed: {text}");
return operation.Clone();
}
await Post("warmup");
await Task.Delay(500);
var capture = await Post("trigger");
Console.WriteLine($"Capture dispatched; operation: {capture.GetProperty("id").GetString()}");
Which example to choose
- Node.js: JavaScript backends, desktop tools, and agent integrations. Browser
fetchis unsupported; put API calls in a backend. - Python: automation tools, image-processing applications, and short local scripts.
- C# / .NET: Windows desktop applications and existing .NET services.
- PowerShell: the Local client examples page already covers direct actions, settings, and complete Script management.
For operator-configured warmup, countdown, repeat, or a bound timeline, call POST /trigger-managed with {} instead. For a server-executed sequence, use a Timeline script. For settings followed by a delay and capture, see Local client examples.