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

  1. 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'
  2. Download and Sync:

    • Run mvn install (for Maven) or gradle build (for Gradle) to download the SDK and its dependencies.

Configuration

  1. 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
  2. Initialize the payments API:

    • Use the ApiCollection class to configure the PaymentsApi:
      PaymentsApi paymentsApi = ApiCollection.configureV1PaymentsApi(env, apiKey);
  3. Access API sections:

    • The PaymentsApi provides access to various sections, such as FaxSection for fax-related operations:
      FaxSection faxApi = paymentsApi.fax;

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 env with the appropriate environment (nonprod, prod, etc.).
  • Replace apiKey with your actual API key.

2. Initialize the payments API:

  • Use ApiCollection.configureV1PaymentsApi to configure the PaymentsApi with the environment and API key.

3. Access the Fax section:

  • The FaxSection of the PaymentsApi provides methods to interact with fax-related operations.

4. Retrieve Fax details:

  • Use the getFax method of the FaxSection to retrieve details of a specific fax by its UUID.

5. Error handling:

  • Wrap the API call in a try-catch block to handle any exceptions and print error messages.