Skip to main content
CatchAll API is currently in beta. Breaking changes may occur in minor version updates. See the Changelog for updates.
TypeScript SDK provides access to the CatchAll API from TypeScript or JavaScript applications with full type safety and modern async/await patterns.

Installation

npm install newscatcher-catchall-sdk

Basic usage

Jobs

Submit a query and retrieve structured results:
import { CatchAllApiClient } from "newscatcher-catchall-sdk";

const client = new CatchAllApiClient({ apiKey: "YOUR_API_KEY" });

// Create a job
const job = await client.jobs.createJob({
  query: "Tech company earnings this quarter",
  context: "Focus on revenue and profit margins",
  schema: "Company [NAME] earned [REVENUE] in [QUARTER]",
});
console.log(`Job created: ${job.jobId}`);

// Poll for completion
while (true) {
  const status = await client.jobs.getJobStatus(job.jobId);

  const completed = status.steps.some(
    (s) => s.status === "completed" && s.completed
  );
  if (completed) {
    console.log("Job completed!");
    break;
  }

  const currentStep = status.steps.find((s) => !s.completed);
  if (currentStep) {
    console.log(
      `Processing: ${currentStep.status} (step ${currentStep.order}/7)`
    );
  }

  await new Promise((resolve) => setTimeout(resolve, 60000));
}

// Retrieve results
const results = await client.jobs.getJobResults(job.jobId);
console.log(`Found ${results.validRecords} records`);

for (const record of results.allRecords) {
  console.log(record.recordTitle);
}
Jobs process asynchronously and typically complete in 10-15 minutes. See the Quickstart for a complete walkthrough.

Monitors

Automate recurring queries with scheduled execution:
// Create a monitor from a completed job
const monitor = await client.monitors.createMonitor({
  referenceJobId: job.jobId,
  schedule: "every day at 12 PM UTC",
  webhook: {
    url: "https://your-endpoint.com/webhook",
    method: "POST",
    headers: { Authorization: "Bearer YOUR_TOKEN" },
  },
});
console.log(`Monitor created: ${monitor.monitorId}`);

// Get aggregated results
const results = await client.monitors.pullMonitorResults(monitor.monitorId);
console.log(`Collected ${results.records} records`);
Learn more about monitors in the Monitors documentation.

Type safety

The SDK exports all request and response types:
import { CatchAllApi } from "newscatcher-catchall-sdk";

const request: CatchAllApi.SubmitRequestDto = {
  query: "Tech company earnings this quarter",
  context: "Focus on revenue and profit margins",
};

Error handling

import { CatchAllApiError } from "newscatcher-catchall-sdk";

try {
  await client.jobs.createJob({
    query: "Tech company earnings this quarter",
  });
} catch (err) {
  if (err instanceof CatchAllApiError) {
    console.log(`Status: ${err.statusCode}`);
    console.log(`Message: ${err.message}`);
    console.log(`Body: ${JSON.stringify(err.body)}`);
  }
}

Advanced features

Pagination

Retrieve large result sets with pagination:
let page = 1;
while (true) {
  const results = await client.jobs.getJobResults(jobId, {
    page: page,
    pageSize: 100,
  });

  for (const record of results.allRecords) {
    console.log(`  - ${record.recordTitle}`);
  }

  if (results.page >= results.totalPages) {
    break;
  }
  page++;
}

Timeouts

Set custom timeouts at the request level:
const response = await client.jobs.createJob(
  {
    query: "Tech company earnings this quarter",
  },
  {
    timeoutInSeconds: 30,
  }
);

Retries

Configure retry behavior for failed requests:
const response = await client.jobs.createJob(
  {
    query: "Tech company earnings this quarter",
  },
  {
    maxRetries: 3,
  }
);

Aborting requests

Cancel requests using an abort signal:
const controller = new AbortController();
const response = await client.jobs.createJob(
  {
    query: "Tech company earnings this quarter",
  },
  {
    abortSignal: controller.signal,
  }
);
controller.abort();

Runtime compatibility

The SDK works in the following runtimes:
  • Node.js 18+
  • Vercel
  • Cloudflare Workers
  • Deno v1.25+
  • Bun 1.0+
  • React Native

Resources