Bruno collection that polls a Sume job until it is terminal

Use bru.setNextRequest and bru.sleep in a Bruno post-response script to poll a Sume job's status route with a bounded attempt count, then fetch the result.

5 min readSume
All posts

Bruno is a file-based API client, and its scripting API is enough to poll a Sume job without a separate script. The Bruno JavaScript reference lists bru.setVar, bru.getVar, bru.getEnvVar, bru.getSecretVar, bru.setNextRequest(name|null), await bru.sleep(ms) and res.getBody() and res.getStatus(), read 2026-10-03. Runtime variables last only during a collection run, while environment variables persist to disk.

The three requests

Build a folder with Submit, Status and Result. Submit posts to the Sume REST API in async mode with an Idempotency-Key; per the Sume jobs guide it answers 202 with status_url, result_url and next_poll_after_seconds. Keep the API key as a secret variable read with bru.getSecretVar, not typed into the request.

Sume status fields the script reads, read 2026-10-03.
FieldMeaningScript action
terminalThe job reached an end stateStop polling
result_readyThe result can be fetchedMove on to Result
sume_statusSume's job statusLog it
next_poll_after_seconds (from submit)Suggested poll gapUse it for bru.sleep

The scripts

In Submit's post-response script, store the job id and gap with bru.setVar. In Status, loop on itself while the job is not terminal, with an attempt counter so a stuck job cannot loop forever.

Run it from the collection runner, since the loop depends on setNextRequest ordering.

// Status: post-response script
const b = res.getBody();
const n = Number(bru.getVar("tries") || 0) + 1;
bru.setVar("tries", n);
if (b.terminal || n >= 60) {
  bru.setNextRequest(b.result_ready ? "Result" : null);
} else {
  const gap = Number(bru.getVar("gap") || 5);
  await bru.sleep(gap * 1000);
  bru.setNextRequest("Status");
}

Rules the collection must respect

  • Never resubmit on a failed or timed-out poll; resubmitting is a second paid job unless the idempotency key repeats.
  • /result returns 409 job_not_completed until the job is done, so only call it after result_ready.
  • A 429 carries retry-after; honor it before the next request.
  • Cancel with POST /v1/jobs/:id/cancel; it returns 409 job_generation_already_started once generation has begun.
  • Reset the tries variable at the start of Submit.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume