Java SDK¶
Java client for the Agora Public API.
Requirements
Java 11 or higher.
Install¶
Configuration¶
import ai.agora.publicapi.ApiClient;
// Production
ApiClient client = new ApiClient();
client.setBasePath("https://core.agoraai.tech/api/v1");
// Development
ApiClient client = new ApiClient();
client.setBasePath("https://core-dev.agoraai.tech/api/v1");
Authentication¶
import ai.agora.publicapi.api.AuthenticationApi;
import ai.agora.publicapi.model.ApiKeyTokenRequest;
import ai.agora.publicapi.model.ApiKeyTokenResponse;
import ai.agora.publicapi.auth.HttpBearerAuth;
ApiClient client = new ApiClient();
client.setBasePath("https://core.agoraai.tech/api/v1");
AuthenticationApi auth = new AuthenticationApi(client);
ApiKeyTokenResponse token = auth.loginWithApiKey(
new ApiKeyTokenRequest().apiKey(System.getenv("AGORA_API_KEY")) // (1)!
);
// Set bearer token for all subsequent calls
((HttpBearerAuth) client.getAuthentication("bearerAuth")) // (2)!
.setBearerToken(token.getAccessToken());
- Always load from environment variables or a secrets manager — never hard-code.
- Mutates the same
clientinstance. Every API class sharing this client will now send the bearer token.
Upload leads¶
Single lead¶
import ai.agora.publicapi.api.LeadsApi;
import ai.agora.publicapi.model.LeadInput;
import ai.agora.publicapi.model.LeadUploadRequest;
import ai.agora.publicapi.model.LeadUploadResponse;
import java.util.List;
LeadsApi leadsApi = new LeadsApi(client); // (1)!
LeadUploadResponse response = leadsApi.uploadLeads(
new LeadUploadRequest()
.campaignId(1)
.leads(List.of(
new LeadInput()
.firstName("Jane")
.lastName("Doe")
.email("jane.doe@example.com")
.phone("+15551234567") // (2)!
.company("Example Co")
.title("VP of Operations")
))
.complianceAcknowledged(true) // (3)!
);
System.out.printf("valid=%d invalid=%d%n",
response.getValidCount(), response.getInvalidCount());
- Reuse the same
clientthat already has the bearer token set. - E.164 format preferred.
- Must be
true.
Bulk upload¶
List<LeadInput> leads = List.of(
new LeadInput().firstName("Jane").phone("+15551234567"),
new LeadInput().firstName("John").phone("+15559876543")
// ...
);
LeadUploadResponse response = leadsApi.uploadLeads(
new LeadUploadRequest()
.campaignId(1)
.leads(leads)
.skipDuplicates(true) // (1)!
.tags(List.of("source:api", "batch:june-2026")) // (2)!
.complianceAcknowledged(true)
);
- Default
true— skips leads already in the campaign. - String tags applied to all leads in this batch.
Handle validation errors¶
LeadUploadResponse response = leadsApi.uploadLeads(request);
if (response.getInvalidCount() > 0) {
for (LeadUploadError error : response.getErrors()) {
System.err.printf("Row %d: %s — %s%n", // (1)!
error.getRow(), error.getVarField(), error.getMessage());
}
}
getVarField()returns the field that failed (e.g."phone").getRow()is the 0-based index in yourleadslist.
Error handling¶
import ai.agora.publicapi.ApiException;
try {
LeadUploadResponse response = leadsApi.uploadLeads(request);
} catch (ApiException e) {
switch (e.getCode()) {
case 401: // (1)!
System.err.println("Token expired — re-exchange API key");
break;
case 403: // (2)!
System.err.println("Not authorised for this campaign");
break;
case 422: // (3)!
System.err.println("Validation error: " + e.getResponseBody());
break;
default:
throw e;
}
}
- Re-run
loginWithApiKeyto get a fresh token. - Confirm the API key's organisation has access to the target
campaignId. - The response body contains a structured error.
Reference¶
| Class | Package | Description |
|---|---|---|
AuthenticationApi |
ai.agora.publicapi.api |
Token exchange |
LeadsApi |
ai.agora.publicapi.api |
Lead upload |
LeadInput |
ai.agora.publicapi.model |
Per-lead fields |
LeadUploadRequest |
ai.agora.publicapi.model |
Upload request body |
LeadUploadResponse |
ai.agora.publicapi.model |
Upload response |
ApiKeyTokenRequest |
ai.agora.publicapi.model |
Token request body |
ApiKeyTokenResponse |
ai.agora.publicapi.model |
Token response |
Full model schemas → Models Reference