HTTP API Examples (curl + REST)

Many teams integrate with nfltr.xyz from CI, internal portals, or agent frameworks using plain HTTP. This guide uses the relay's API with curl and your machine's certificate: list your connected agents, watch them come and go, and change an agent's labels.

You need a machine enrolled in your account (nfltr config login), whose certificate authenticates each request, and a connected agent under the same account (the dashboard Machines view lists them).


Authentication

Every request presents this machine's certificate, the same one the CLI uses. nfltr config login saved it beside the config file as machine.json (the certificate chain in its chain field) and machine.key (PEM, mode 0600). curl wants the chain as a PEM file:

D=~/.config/nfltr                        # the directory of NFLTR_CONFIG, when you set it
jq -r .chain "$D/machine.json" > "$D/machine.pem"
C=(--cert "$D/machine.pem" --key "$D/machine.key")

curl -s https://nfltr.xyz/api/v1/presence/agents "${C[@]}"

The certificate lasts 24 hours and the CLI renews it; extract the PEM again at the start of each script run. Browser sessions on the dashboard use cookies instead.


1. Who is connected

List your connected agents (the same scope as /api/v1/my/agents), optionally only those whose labels match:

curl -s "https://nfltr.xyz/api/v1/presence/agents?selector%5Bstatus%5D=busy" \
  "${C[@]}" \
  | jq '{cursor, agents: [.agents[] | {agent_id, labels}]}'

The answer carries a cursor taken before the list, so a watcher that starts from it misses nothing.


2. Watch agents come and go

A long-poll: it answers as soon as an agent you may see connects (up), leaves (down) or advertises new labels (labels), or after wait_ms (at most 25000) with no events. Pass the returned cursor to the next call. reset: true means changes may be missing (the cursor is too old, or the relay restarted): list again.

CURSOR=$(curl -s https://nfltr.xyz/api/v1/presence/events "${C[@]}" | jq -r .cursor)
while :; do
  R=$(curl -s "https://nfltr.xyz/api/v1/presence/events?cursor=$CURSOR&wait_ms=25000" "${C[@]}")
  echo "$R" | jq -c '.events[]?'
  CURSOR=$(echo "$R" | jq -r .cursor)
done

Errors are google.rpc.Status JSON: branch on details[0].reason (for example ERROR_REASON_UNAUTHENTICATED, ERROR_REASON_LIMIT_EXCEEDED), never on the message.


3. An agent changes its own labels

The labels the presence API filters on are the ones an agent connected with, plus the ones it advertises since. An agent written with the Go SDK changes them while connected with one call to the relay's own agent, nfltr-relay (rpcclient.RelayAgentID):

req, _ := protojson.Marshal(&presencev1.UpdateLabelsRequest{
	Labels: map[string]string{"status": "busy"},
	Patch:  true, // merge into the previous update; false replaces it
})
reply, err := agent.Invoke(ctx, rpcclient.RelayAgentID, req) // agent: an *rpcclient.Agent
var resp presencev1.UpdateLabelsResponse
_ = protojson.Unmarshal(reply, &resp) // the full label set now advertised

The relay applies the update to the connection that sent it, never to another agent, and keeps the connect-time labels as they were. Watchers of /api/v1/presence/events get a labels event. The SDK's README ("Change your own labels") has the whole example and the bounds.


Endpoint map (relay)

MethodPathUse
GET/api/v1/presence/agentsConnected agents you may see, with labels; selector[key]=value filters; returns a watch cursor
GET/api/v1/presence/events?cursor=C&wait_ms=NLong-poll for agents connecting, leaving and re-advertising labels
GET/api/v1/my/agentsYour connected agents with traffic counters
POST/api/v1/mailboxes/{name}/messages, …/messages:pull, …/messages:ackDurable mailboxes: append, read from a cursor, acknowledge (Mailboxes and Webhooks)
POST/api/v1/webhooks, /api/v1/webhooks/{id}/deliveriesWebhooks into a mailbox, and their ingress
GET/api/v1/machines/resolve?name=NThe machine id of a machine name of your account; without name, the caller's own
GET/api/v1/machines/revoked?cursor=C&wait_ms=NYour account's revoked machines; a long-poll from the cursor

Related docs