The VAX (Vendasta API Extensions) Java SDK provides a modern, type-safe client library for interacting with Vendasta's APIs using both HTTP and gRPC protocols. Built with Java 21, it offers a clean builder pattern API, comprehensive credential management, and excellent performance.
- π§ Builder Pattern API: Fluent, readable client configuration
- π Flexible Authentication: Support for environment variables, credential objects, or input streams
- β‘ Modern HTTP Stack: Uses Java 11+
java.net.http.HttpClientfor optimal performance - π‘οΈ Type Safety: Compile-time safety with method references instead of reflection
- β»οΈ Resource Management: AutoCloseable clients for proper cleanup
- π― Smart Defaults: Sensible default values (HTTPS enabled, 10-second timeouts)
- π¦ Minimal Dependencies: Lean dependency footprint with no unused libraries
- Java 21 or later
- Maven 3.6+ or Gradle 7.0+
<dependency>
<groupId>com.vendasta</groupId>
<artifactId>vax.v1</artifactId>
<version>1.1.0</version>
</dependency>implementation 'com.vendasta:vax.v1:1.1.0'Set your service account credentials:
export VENDASTA_APPLICATION_CREDENTIALS=/path/to/your/service-account.jsonimport com.vendasta.vax.HTTPClient;
import com.vendasta.vax.RequestOptions;
// Simple HTTP client with defaults
HTTPClient client = HTTPClient.builder()
.host("api.vendasta.com")
.build();
// Make a request
MyResponse response = client.doRequest(
"/api/v1/resource",
myRequest,
MyResponse.newBuilder(),
RequestOptions.newBuilder()
);
// Don't forget to close!
client.close();import com.vendasta.vax.GRPCClient;
import com.vendasta.vax.RequestOptions;
// Custom gRPC client implementation
public class MyServiceClient extends GRPCClient<MyServiceGrpc.MyServiceBlockingStub> {
public MyServiceClient(String host) throws SDKException {
super(GRPCClient.builder().host(host));
}
@Override
protected MyServiceGrpc.MyServiceBlockingStub newBlockingStub(ManagedChannel channel) {
return MyServiceGrpc.newBlockingStub(channel);
}
public MyResponse callService(MyRequest request) throws SDKException {
return doRequest(
stub -> stub.myMethod(request),
RequestOptions.newBuilder()
);
}
}
// Usage
try (MyServiceClient client = new MyServiceClient("grpc.vendasta.com")) {
MyResponse response = client.callService(myRequest);
// Process response
}Both HTTPClient and GRPCClient support the same builder pattern:
HTTPClient client = HTTPClient.builder()
.host("api.example.com") // Required: API hostname
.secure(true) // Optional: HTTPS/secure gRPC (default: true)
.defaultTimeout(15000) // Optional: timeout in milliseconds (default: 10000)
.credentials(myCredentials) // Optional: custom credentials
.serviceAccount(inputStream) // Optional: service account stream
.build();// Uses VENDASTA_APPLICATION_CREDENTIALS environment variable
HTTPClient client = HTTPClient.builder()
.host("api.example.com")
.build();VAXCredentials.Credentials creds = new VAXCredentials.Credentials();
creds.setPrivateKeyID("your-key-id");
creds.setPrivateKey("-----BEGIN PRIVATE KEY-----\n...");
creds.setEmail("service@example.com");
creds.setTokenURI("https://oauth2.googleapis.com/token");
HTTPClient client = HTTPClient.builder()
.host("api.example.com")
.credentials(creds)
.build();InputStream serviceAccount = new FileInputStream("service-account.json");
HTTPClient client = HTTPClient.builder()
.host("api.example.com")
.serviceAccount(serviceAccount)
.build();To test an SDK against demo from your laptop as yourself, build the client without credentials and use one of these.
Your mscli key, which mscli auth login -e demo writes and which refreshes its own token:
export VENDASTA_APPLICATION_CREDENTIALS=~/.config/vendasta/demo_default_credentials.jsonOr your Vendasta bearer token, sent as Authorization: Bearer <token> (a value copied with its Bearer prefix works too). It is not refreshed, so get a new one when calls start failing with UNAUTHENTICATED:
export VENDASTA_ACCESS_TOKEN=<your token>VENDASTA_ACCESS_TOKEN takes precedence over VENDASTA_APPLICATION_CREDENTIALS (vax logs a warning when both are set), and explicit credentials(...) or serviceAccount(...) take precedence over both.
Configure individual requests:
RequestOptions options = RequestOptions.newBuilder()
.setIncludeToken(true) // Include auth token (default: true)
.setTimeout(30000) // Request timeout in ms
.build();
MyResponse response = client.doRequest("/path", request, responseBuilder, options);Both clients implement AutoCloseable for proper resource cleanup:
// Try-with-resources (recommended)
try (HTTPClient client = HTTPClient.builder().host("api.example.com").build()) {
// Use client
} // Automatically closed
// Manual cleanup
HTTPClient client = HTTPClient.builder().host("api.example.com").build();
try {
// Use client
} finally {
client.close();
}try {
HTTPClient client = HTTPClient.builder()
.host("api.example.com")
.build();
MyResponse response = client.doRequest(path, request, responseBuilder, options);
} catch (SDKException e) {
// getStatus() is the gRPC status carried by the failure, with UNAVAILABLE as the fallback when there is none.
// A rejected key is UNAUTHENTICATED, and an unreachable host times out as DEADLINE_EXCEEDED.
if (e.getStatus().getCode() == io.grpc.Status.Code.PERMISSION_DENIED) {
// ...
}
logger.error("SDK Error: {}", e.getMessage(), e);
} catch (Exception e) {
// Handle other errors
logger.error("Unexpected error: {}", e.getMessage(), e);
}public class AccountServiceClient extends GRPCClient<AccountServiceGrpc.AccountServiceBlockingStub> {
public AccountServiceClient(Builder builder) throws SDKException {
super(builder);
}
public static AccountServiceClient create(String host) throws SDKException {
return new AccountServiceClient(
GRPCClient.builder().host(host)
);
}
@Override
protected AccountServiceGrpc.AccountServiceBlockingStub newBlockingStub(ManagedChannel channel) {
return AccountServiceGrpc.newBlockingStub(channel);
}
public Account getAccount(String accountId) throws SDKException {
GetAccountRequest request = GetAccountRequest.newBuilder()
.setAccountId(accountId)
.build();
return doRequest(
stub -> stub.getAccount(request),
RequestOptions.newBuilder()
);
}
}The 1.0.0 release introduces breaking changes. Here's how to migrate:
Before (0.x):
HTTPClient client = new HTTPClient(host, scope, secure, timeout);
GRPCClient client = new GRPCClient(host, scope, secure, timeout);After (1.0.0):
HTTPClient client = HTTPClient.builder()
.host(host)
.secure(secure)
.defaultTimeout(timeout)
.build();
GRPCClient client = GRPCClient.builder()
.host(host)
.secure(secure)
.defaultTimeout(timeout)
.build();The scope parameter has been completely removed as it was unused:
Before:
// scope parameter was required but ignored
new HTTPClient(host, "unused-scope", secure);After:
// No scope parameter needed
HTTPClient.builder().host(host).secure(secure).build();Update your Java version and build configuration:
<!-- Maven -->
<properties>
<maven.compiler.release>21</maven.compiler.release>
</properties>// Gradle
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}- Reuse Clients: Create clients once and reuse them for multiple requests
- Resource Cleanup: Always close clients when done (use try-with-resources)
- Timeout Configuration: Set appropriate timeouts for your use case
- Connection Pooling: HTTP clients automatically pool connections
Authentication Errors:
CredentialsException: Could not refresh token
- Verify
VENDASTA_APPLICATION_CREDENTIALSenvironment variable - Ensure service account file exists and is readable
- Check service account permissions
Timeout Errors:
SDKException: Request timeout
- Increase timeout with
.defaultTimeout()orRequestOptions.setTimeout() - Check network connectivity
- Verify server responsiveness
Build Errors:
UnsupportedClassVersionError
- Ensure you're using Java 21 or later
- Update your IDE and build tools
| Method | Description | Default |
|---|---|---|
host(String) |
API hostname (required) | - |
secure(boolean) |
Use HTTPS | true |
defaultTimeout(float) |
Timeout in milliseconds | 10000 |
credentials(Credentials) |
Custom credentials | Environment variable |
serviceAccount(InputStream) |
Service account stream | Environment variable |
| Method | Description | Default |
|---|---|---|
host(String) |
gRPC server hostname (required) | - |
secure(boolean) |
Use secure gRPC (TLS) | true |
defaultTimeout(float) |
Timeout in milliseconds | 10000 |
credentials(Credentials) |
Custom credentials | Environment variable |
serviceAccount(InputStream) |
Service account stream | Environment variable |
| Method | Description | Default |
|---|---|---|
setIncludeToken(boolean) |
Include auth token | true |
setTimeout(float) |
Request timeout in ms | Client default |
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Documentation: API Docs
- Issues: GitHub Issues
- Email: support@vendasta.com
See CHANGELOG.md for detailed release notes and migration guides.