Skip to main content
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

Quickstart

Get started with CatchAll in three steps:
1

Initialize the client

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

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

Create a job

const job = await client.jobs.createJob({
  query: "AI company acquisitions",
  limit: 10,
});
const jobId = job.job_id;
3

Wait and retrieve results

const POLL_INTERVAL_MS = 60000;

// Poll for completion
while (true) {
  const status = await client.jobs.getJobStatus({ job_id: jobId });
  if (status.status === "completed") {
    break;
  }
  await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
}

// Get results
const results = await client.jobs.getJobResults({ job_id: jobId });
console.log(`Found ${results.valid_records} valid records`);
Jobs process asynchronously and typically complete in 10-15 minutes. See the Quickstart for a complete walkthrough.

Working with jobs

Get suggested validators, enrichments, and date ranges before creating a job:
import { CatchAllApiClient } from "newscatcher-catchall-sdk";

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

const suggestions = await client.jobs.initialize({
  query: "AI company acquisitions",
  context: "Focus on deal size and acquiring company details"
});

console.log(JSON.stringify(suggestions, null, 2));
To learn more, see the Initialize endpoint.
import { CatchAllApiClient, CatchAllApiError } from "newscatcher-catchall-sdk";

const POLL_INTERVAL_MS = 60000;

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

try {
  // Create job with custom enrichments
  const job = await client.jobs.createJob({
    query: "AI company acquisitions",
    context: "Focus on deal size and acquiring company details",
    limit: 10,
    enrichments: [
      {
        name: "acquirer_company",
        description: "Extract the acquiring company name",
        type: "company"
      },
      {
        name: "deal_value",
        description: "Extract acquisition price if mentioned",
        type: "number"
      }
    ]
  });
  const jobId = job.job_id;
  console.log(`Job created: ${jobId}`);

  // Poll with early results access
  while (true) {
    const status = await client.jobs.getJobStatus({ job_id: jobId });

    if (status.status === "enriching" || status.status === "completed") {
      const results = await client.jobs.getJobResults({ job_id: jobId });
      if (results.valid_records > 0) {
        console.log(`Progress: ${results.valid_records} valid records`);
      }

      if (status.status === "completed") {
        break;
      }
    }

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

  // Continue if needed
  let results = await client.jobs.getJobResults({ job_id: jobId });
  if (results.valid_records >= 10) {
    await client.jobs.continueJob({
      job_id: jobId,
      new_limit: 50,
    });

    while (true) {
      const status = await client.jobs.getJobStatus({ job_id: jobId });
      if (status.status === "completed") {
        break;
      }
      await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
    }

    results = await client.jobs.getJobResults({ job_id: jobId });
  }

  // Display results
  console.log(`\nFinal: ${results.valid_records} valid records`);
  for (const record of results.all_records) {
    console.log(`  ${record.record_title}`);
  }
} catch (err) {
  if (err instanceof CatchAllApiError) {
    console.error(`Status: ${err.statusCode}`);
    console.error(`Error: ${err.message}`);
  }
}

Working with monitors

Automate recurring queries with scheduled execution.
Create a monitor from a completed job:
const monitor = await client.monitors.createMonitor({
  reference_job_id: 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.monitor_id}`);
Monitors require a minimum 24-hour interval between executions. Learn more in the Monitors documentation.
import { CatchAllApiClient, CatchAllApiError } from "newscatcher-catchall-sdk";

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

try {
  // Create monitor from completed job
  const jobId = "af7a26d6-cf0b-458c-a6ed-4b6318c74da3";

  const monitor = await client.monitors.createMonitor({
    reference_job_id: jobId,
    schedule: "every day at 12 PM UTC",
    webhook: {
      url: "https://your-endpoint.com/webhook",
      method: "POST",
      headers: { Authorization: "Bearer YOUR_TOKEN" },
    },
  });
  const monitorId = monitor.monitor_id;
  console.log(`Monitor created: ${monitorId}`);

  // Update webhook
  await client.monitors.updateMonitor({
    monitor_id: monitorId,
    webhook: {
      url: "https://new-endpoint.com/webhook",
      method: "POST",
    },
  });

  // List all monitors
  const allMonitors = await client.monitors.listMonitors();
  for (const m of allMonitors.monitors) {
    const status = m.enabled ? "active" : "paused";
    console.log(`${m.monitor_id}: ${status}`);
  }

  // Control execution
  await client.monitors.disableMonitor({ monitor_id: monitorId });
  await client.monitors.enableMonitor({ monitor_id: monitorId });

  // List execution history
  const jobs = await client.monitors.listMonitorJobs({
    monitor_id: monitorId,
    sort: "desc",
  });
  console.log(`\nMonitor executed ${jobs.total_jobs} jobs`);
  for (const job of jobs.jobs) {
    console.log(`  Job ${job.job_id}: ${job.start_date} to ${job.end_date}`);
  }

  // Get aggregated results
  const results = await client.monitors.pullMonitorResults({
    monitor_id: monitorId,
  });
  console.log(`\nCollected ${results.records} total records`);
  for (const record of results.all_records) {
    console.log(`  ${record.record_title}`);
  }
} catch (err) {
  if (err instanceof CatchAllApiError) {
    console.error(`Status: ${err.statusCode}`);
    console.error(`Error: ${err.message}`);
  }
}

Type safety

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

const request: CatchAllApi.SubmitRequestDto = {
  query: "AI company acquisitions",
  context: "Focus on deal size and acquiring company details",
  limit: 10,
};

const job = await client.jobs.createJob(request);

Error handling

Handle API errors with structured exception handling:
import { CatchAllApiError } from "newscatcher-catchall-sdk";

try {
  await client.jobs.createJob({
    query: "AI company acquisitions",
  });
} catch (err) {
  if (err instanceof CatchAllApiError) {
    console.log(`Status: ${err.statusCode}`);
    console.log(`Error: ${err.message}`);
  }
}

Advanced usage

Pagination

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

  console.log(`Page ${results.page}/${results.total_pages}`);

  for (const record of results.all_records) {
    console.log(`  ${record.record_title}`);
  }

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

Timeouts

Configure custom timeouts at the request level:
const response = await client.jobs.createJob(
  {
    query: "AI company acquisitions",
  },
  {
    timeoutInSeconds: 30,
  }
);

Retries

Configure automatic retry behavior for failed requests:
const response = await client.jobs.createJob(
  {
    query: "AI company acquisitions",
  },
  {
    maxRetries: 3,
  }
);

Aborting requests

Cancel requests using an abort signal:
const controller = new AbortController();

const response = await client.jobs.createJob(
  {
    query: "AI company acquisitions",
  },
  {
    abortSignal: controller.signal,
  }
);

// Cancel the request
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