Skip to main content
CatchAll API is currently in beta. Breaking changes may occur in minor version updates. See the Changelog for updates.
Java SDK provides access to the CatchAll API from Java applications.

Installation

Gradle

dependencies {
    implementation 'com.newscatcherapi:newscatcher-catchall-sdk:0.1.0'
}

Maven

<dependency>
    <groupId>com.newscatcherapi</groupId>
    <artifactId>newscatcher-catchall-sdk</artifactId>
    <version>0.1.0</version>
</dependency>

Basic usage

Jobs

Submit a query and retrieve structured results:
import com.newscatcher.catchall.CatchAllApi;
import com.newscatcher.catchall.resources.jobs.requests.SubmitRequestDto;
import com.newscatcher.catchall.types.StatusResponseDto;
import com.newscatcher.catchall.types.PullJobResponseDto;

public class JobsExample {
    public static void main(String[] args) throws InterruptedException {
        CatchAllApi client = CatchAllApi.builder()
            .apiKey("YOUR_API_KEY")
            .build();

        // Create a job
        var job = client.jobs().createJob(
            SubmitRequestDto.builder()
                .query("Tech company earnings this quarter")
                .context("Focus on revenue and profit margins")
                .schema("Company [NAME] earned [REVENUE] in [QUARTER]")
                .build()
        );
        System.out.println("Job created: " + job.getJobId());

        // Poll for completion
        String jobId = job.getJobId();
        while (true) {
            StatusResponseDto status = client.jobs().getJobStatus(jobId);

            if ("job_completed".equals(status.getStatus())) {
                System.out.println("Job completed!");
                break;
            }

            Thread.sleep(60000); // Wait 60 seconds
        }

        // Retrieve results
        PullJobResponseDto results = client.jobs().getJobResults(jobId);
        System.out.println(String.format(
            "Found %d valid records",
            results.getValidRecords()
        ));

        results.getAllRecords().forEach(record ->
            System.out.println(record.getRecordTitle())
        );
    }
}
Jobs process asynchronously and typically complete in 10-15 minutes. See the Quickstart for a complete walkthrough.

Monitors

Automate recurring queries with scheduled execution:
import com.newscatcher.catchall.resources.monitors.requests.CreateMonitorRequestDto;
import com.newscatcher.catchall.types.WebhookDto;
import java.util.Map;

// Create a monitor from a completed job
var monitor = client.monitors().createMonitor(
    CreateMonitorRequestDto.builder()
        .referenceJobId(jobId)
        .schedule("every day at 12 PM UTC")
        .webhook(WebhookDto.builder()
            .url("https://your-endpoint.com/webhook")
            .method("POST")
            .headers(Map.of("Authorization", "Bearer YOUR_TOKEN"))
            .build())
        .build()
);
System.out.println("Monitor created: " + monitor.getMonitorId().orElse("N/A"));

// Get aggregated results
monitor.getMonitorId().ifPresent(monitorId -> {
    var results = client.monitors().pullMonitorResults(monitorId);
    System.out.println("Collected " + results.getRecords() + " records");
});
Learn more about monitors in the Monitors documentation.

Error handling

import com.newscatcher.catchall.core.CatchAllApiApiException;

try {
    client.jobs().createJob(
        SubmitRequestDto.builder()
            .query("Tech company earnings this quarter")
            .build()
    );
} catch (CatchAllApiApiException e) {
    System.out.println("Status: " + e.statusCode());
    System.out.println("Error: " + e.body());
}

Advanced features

Pagination

Retrieve large result sets with pagination:
import com.newscatcher.catchall.resources.jobs.requests.GetJobResultsRequest;

int page = 1;
while (true) {
    var results = client.jobs().getJobResults(
        jobId,
        GetJobResultsRequest.builder()
            .page(page)
            .pageSize(100)
            .build()
    );

    results.getAllRecords().forEach(record -> {
        System.out.println("  - " + record.getRecordTitle());
    });

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

Timeouts

Set custom timeouts at the client or request level:
import com.newscatcher.catchall.core.RequestOptions;

// Client-level timeout
CatchAllApi client = CatchAllApi.builder()
    .apiKey("YOUR_API_KEY")
    .timeout(30) // 30 seconds
    .build();

// Request-level timeout
client.jobs().createJob(
    SubmitRequestDto.builder()
        .query("Tech company earnings this quarter")
        .build(),
    RequestOptions.builder()
        .timeout(10)
        .build()
);

Retries

Configure retry behavior for failed requests:
// Client-level retries
CatchAllApi client = CatchAllApi.builder()
    .apiKey("YOUR_API_KEY")
    .maxRetries(3)
    .build();

// Request-level retries
client.jobs().createJob(
    SubmitRequestDto.builder()
        .query("Tech company earnings this quarter")
        .build(),
    RequestOptions.builder()
        .maxRetries(3)
        .build()
);

Resources