FastComments.com

FastComments Java SDK

This is the official Java SDK for FastComments.

Official Java SDK for the FastComments API

Repository

View on GitHub


Installation Internal Link

Maven

Add the Repsy repository to your project's POM:

<repositories>
    <repository>
        <id>repsy</id>
        <name>FastComments Maven Repository on Repsy</name>
        <url>https://repo.repsy.io/mvn/winrid/fastcomments</url>
    </repository>
</repositories>

Then add the dependencies you need:

<dependencies>
    <!-- API Client -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>client</artifactId>
        <version>2.0.0</version>
    </dependency>
    
    <!-- Core Library (includes SSO) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>core</artifactId>
        <version>2.0.0</version>
    </dependency>
    
    <!-- PubSub Library (for live events) -->
    <dependency>
        <groupId>com.fastcomments</groupId>
        <artifactId>pubsub</artifactId>
        <version>2.0.0</version>
    </dependency>
</dependencies>

Gradle

Add the Repsy repository to your build.gradle file:

repositories {
    mavenCentral()
    maven {
        url "https://repo.repsy.io/mvn/winrid/fastcomments"
    }
}

dependencies {
    // API Client
    implementation "com.fastcomments:client:2.0.0"
    
    // Core Library (includes SSO)
    implementation "com.fastcomments:core:2.0.0"
    
    // PubSub Library (for live events)
    implementation "com.fastcomments:pubsub:2.0.0"
}

Library Contents

This library contains three modules. The generated API client, the core Java library which contains hand-written utilities to make working with the API easier, and the pubsub module which is a library for subscribing to change feeds.

Public vs Secured APIs

For the API client, there are three classes, DefaultApi, PublicApi, and ModerationApi. The DefaultApi contains methods that require your API key, and PublicApi contains methods that can be made directly from a browser/mobile device/etc without authentication.

The ModerationApi powers the moderator dashboard. It contains methods for comment moderation (list, count, search, logs, and export), moderation actions (remove/restore, flag, set review/spam/approval status, votes, and reopen/close thread), bans (ban from comment, undo a ban, pre-ban summaries, ban status and preferences, and banned-user counts), and badges & trust (award/remove a badge, manual badges, get/set trust factor, and user internal profile). Every ModerationApi method accepts an sso parameter so the call can be performed on behalf of an SSO-authenticated moderator.

Quick Start Internal Link

Using Authenticated APIs (DefaultApi)

Important: You must set your API key on the ApiClient before making authenticated requests. If you don't, requests will fail with a 401 error.

import com.fastcomments.invoker.ApiClient;
import com.fastcomments.invoker.ApiException;
import com.fastcomments.api.DefaultApi;
import com.fastcomments.model.*;

public class Example {
    public static void main(String[] args) {
        // Create and configure the API client
        ApiClient apiClient = new ApiClient();

        // REQUIRED: Set your API key (get this from your FastComments dashboard)
        apiClient.setApiKey("YOUR_API_KEY_HERE");

        // Create the API instance with the configured client
        DefaultApi api = new DefaultApi(apiClient);

        // Now you can make authenticated API calls
        try {
            // Example: Add an SSO user
            CreateAPISSOUserData userData = new CreateAPISSOUserData();
            userData.setId("user-123");
            userData.setEmail("user@example.com");
            userData.setDisplayName("John Doe");

            AddSSOUserAPIResponse response = api.addSSOUser("YOUR_TENANT_ID", userData)
                .execute();
            System.out.println("User created: " + response);

        } catch (ApiException e) {
            System.err.println("Error: " + e.getResponseBody());
            // Common errors:
            // - 401: API key is missing or invalid
            // - 400: Request validation failed
        }
    }
}

Using Public APIs (PublicApi)

Public endpoints don't require authentication:

import com.fastcomments.api.PublicApi;
import com.fastcomments.invoker.ApiException;

PublicApi publicApi = new PublicApi();

try {
    var response = publicApi.getCommentsPublic("YOUR_TENANT_ID", "page-url-id")
        .execute();
    System.out.println(response);
} catch (ApiException e) {
    e.printStackTrace();
}

Using Moderation APIs (ModerationApi)

The ModerationApi drives the moderator dashboard. Each method accepts an sso parameter identifying the SSO-authenticated moderator on whose behalf the request is made:

import com.fastcomments.api.ModerationApi;
import com.fastcomments.invoker.ApiException;
import com.fastcomments.model.*;

ModerationApi moderationApi = new ModerationApi();

try {
    // List comments awaiting moderation
    ModerationAPIGetCommentsResponse response = moderationApi.getApiComments()
        .sso("YOUR_SSO_TOKEN")
        .execute();
    System.out.println(response);
} catch (ApiException e) {
    e.printStackTrace();
}

Common Issues

  1. 401 "missing-api-key" error: Make sure you call apiClient.setApiKey("YOUR_KEY") before creating the DefaultApi instance.
  2. Wrong API class: Use DefaultApi for server-side authenticated requests, PublicApi for client-side/public requests.
  3. Null API key: The SDK will silently skip authentication if the API key is null, leading to 401 errors.

Notes Internal Link

Broadcast Ids

You'll see you're supposed to pass a broadcastId in some API calls. When you receive events, you'll get this ID back, so you know to ignore the event if you plan to optimistically apply changes on the client (which you'll probably want to do since it offers the best experience). Pass a UUID here. The ID should be unique enough to not occur twice in a browser session.

Need Help?

If you encounter any issues or have questions about the Java SDK, please:

Contributing

Contributions are welcome! Please visit the GitHub repository for contribution guidelines.