Skip to main content
POST
/
batch
/
scrape
/
{batchId}
/
retry
Retry Failed Items
curl --request POST \
  --url https://api.spidra.io/api/batch/scrape/{batchId}/retry \
  --header 'x-api-key: <api-key>'
{
  "status": "queued",
  "retriedCount": 3
}
After a batch completes with some failures, retry only the failed scrapes. Successful items are never touched. Fresh credits are reserved for the retry, and the batch status resets to running.
curl -X POST https://api.spidra.io/api/batch/scrape/YOUR_BATCH_ID/retry \
  -H "x-api-key: YOUR_API_KEY"

Full Retry Pattern

async function runWithRetry(urls, options, maxAttempts = 3) {
  // Submit the initial batch
  const submit = await fetch("https://api.spidra.io/api/batch/scrape", {
    method: "POST",
    headers: {
      "x-api-key": "YOUR_API_KEY",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ urls, ...options }),
  });
  const { batchId } = await submit.json();

  for (let attempt = 1; attempt <= maxAttempts; attempt++) {
    // Poll until terminal
    let data;
    while (true) {
      const res = await fetch(
        `https://api.spidra.io/api/batch/scrape/${batchId}`,
        { headers: { "x-api-key": "YOUR_API_KEY" } }
      );
      data = await res.json();
      if (["completed", "failed", "cancelled"].includes(data.status)) break;
      await new Promise((r) => setTimeout(r, 3000));
    }

    if (data.failedCount === 0) break; // All done

    if (attempt < maxAttempts) {
      console.log(`Attempt ${attempt}: ${data.failedCount} failed. Retrying...`);
      await fetch(
        `https://api.spidra.io/api/batch/scrape/${batchId}/retry`,
        { method: "POST", headers: { "x-api-key": "YOUR_API_KEY" } }
      );
    }
  }

  // Fetch final state
  const final = await fetch(
    `https://api.spidra.io/api/batch/scrape/${batchId}`,
    { headers: { "x-api-key": "YOUR_API_KEY" } }
  );
  return (await final.json()).items;
}

Response

202 Accepted:
{
  "status": "queued",
  "retriedCount": 3
}
FieldTypeDescription
status"queued"Confirms the retry was accepted
retriedCountnumberNumber of failed items that were re-queued
After a successful retry:
  • Failed items reset to pending status
  • Batch failedCount decrements by retriedCount
  • Batch status resets to running
  • Poll the same batchId — it will complete again when all retried items finish

Errors

CodeReason
400No failed items to retry in this batch
401Missing x-api-key header
403Monthly credit limit reached — not enough credits to reserve for the retry
404No batch found with this ID, or it belongs to a different user
No failed items:
{
  "status": "error",
  "message": "No failed items to retry.",
  "code": "NO_FAILED_ITEMS"
}

Get Batch Status

Poll for results after retrying

Cancel a Batch

Stop the batch entirely instead

Authorizations

x-api-key
string
header
required

Path Parameters

batchId
string<uuid>
required

The batch ID containing failed items to retry

Response

Failed items re-queued

status
enum<string>
Available options:
queued
retriedCount
integer

Number of failed items that were re-queued