Java
The Java SDK enables seamless integration with Optum Connections APIs for Java applications. It provides strongly-typed models, easy configuration, and asynchronous methods to simplify API interactions. Below is a guide to help you get started with the SDK.
Installation
-
Add the SDK to Your Project:
- If using Maven, add the following dependency to your
pom.xml:<dependency> <groupId>com.optum.financial</groupId> <artifactId>public-api-sdk</artifactId> <version>1.0.0</version> </dependency> - If using Gradle, add the following to your
build.gradle:implementation 'com.optum.financial:public-api-sdk:1.0.0'
- If using Maven, add the following dependency to your
-
Download and Sync:
- Run
mvn install(for Maven) orgradle build(for Gradle) to download the SDK and its dependencies.
- Run
Configuration
-
Set environment and API Key:
- The SDK requires an environment (e.g.,
nonprod,prod) and an API key for authentication. Replace the placeholders in the example below with your actual values:String env = "nonprod"; // Replace with your environment String apiKey = "your-api-key"; // Replace with your API key
- The SDK requires an environment (e.g.,
-
Initialize the payments API:
- Use the
ApiCollectionclass to configure thePaymentsApi:PaymentsApi paymentsApi = ApiCollection.configureV1PaymentsApi(env, apiKey);
- Use the
-
Access API sections:
- The
PaymentsApiprovides access to various sections, such asFaxSectionfor fax-related operations:FaxSection faxApi = paymentsApi.fax;
- The
Usage
Here’s an example of how to use the SDK to retrieve fax details:
package com.optum.financial;
import com.optum.financial.sdk.ApiCollection;
import com.optum.financial.sdk.V1.PaymentsApi;
import com.optum.financial.sdk.V1.paymentsApiSections.FaxSection;
import com.optum.financial.sdk.V1.models.faxSection.FaxDetails;
import java.util.UUID;
public class App {
public static void main(String[] args) {
System.out.println("Testing FaxApi#v1FaxFaxIdGet method");
// Configuration
String env = "nonprod"; // Replace with your environment
String apiKey = "your-api-key"; // Replace with your API key
String faxId = "6461dd48-dbd6-512f-2b5d-7b7354caf3dc"; // Replace with your fax ID
// Initialize the Payments API
PaymentsApi paymentsApi = ApiCollection.configureV1PaymentsApi(env, apiKey);
FaxSection faxApi = paymentsApi.fax;
try {
// Retrieve fax details
FaxDetails result = faxApi.getFax(UUID.fromString(faxId));
System.out.println(result);
} catch (Exception e) {
System.err.println("Error message: " + e.getMessage());
}
}
}Explanation of the code
1. Environment and API Key:
- Replace
envwith the appropriate environment (nonprod,prod, etc.). - Replace
apiKeywith your actual API key.
2. Initialize the payments API:
- Use
ApiCollection.configureV1PaymentsApito configure thePaymentsApiwith the environment and API key.
3. Access the Fax section:
- The
FaxSectionof thePaymentsApiprovides methods to interact with fax-related operations.
4. Retrieve Fax details:
- Use the
getFaxmethod of theFaxSectionto retrieve details of a specific fax by its UUID.
5. Error handling:
- Wrap the API call in a
try-catchblock to handle any exceptions and print error messages.
Updated 7 months ago
