Skip to content

avadev/Avalara-SDK-Java

Repository files navigation

Avalara.SDK

Avalara Shipping Verification only

  • API version: 3.1.0

API for evaluating transactions against direct-to-consumer Beverage Alcohol shipping regulations.

This API is currently in beta.

Requirements

Building the API client library requires:

  1. Java 1.7+
  2. Maven/Gradle

Installation

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>Avalara.SDK</groupId>
  <artifactId>Avalara.SDK</artifactId>
  <version>2.4.29</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

  repositories {
  mavenCentral()     // Needed if the 'Avalara.SDK' jar has been published to maven central.
  mavenLocal()       // Needed if the 'Avalara.SDK' jar has been published to the local maven repo.
}

dependencies {
  implementation "Avalara.SDK:Avalara.SDK:2.4.29"
}

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/Avalara.SDK-2.4.29.jar
  • target/lib/*.jar

Getting Started

Please follow the installation instruction and execute the following Java code:

import Avalara.SDK.*;
import Avalara.SDK.auth.*;
import Avalara.SDK.model.Avatax.*;
import Avalara.SDK.api.Avatax.AddressesApi;

public class AddressesApiExample {

  public static void main(String[] args) {
    Configuration configuration = new Configuration();
    configuration.setAppName("Test");
    configuration.setAppVersion("1.0");
    configuration.setMachineName("LocalBox");
    configuration.setTimeout(5000);
    configuration.setEnvironment(AvaTaxEnvironment.Sandbox);
    // Configure HTTP basic authorization
    configuration.setUsername("YOUR USERNAME");
    configuration.setPassword("YOUR PASSWORD");
    // Configure OAuth2 access token for authorization
    configuration.setBearerToken("YOUR ACCESS TOKEN");

    ApiClient apiClient = new ApiClient(configuration);
    AddressesApi apiInstance = new AddressesApi(apiClient);
    String xAvalaraClient = "Swagger UI; 22.7.0; Custom; 1.0"; // String | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
    AddressValidationInfo body = new AddressValidationInfo(); // AddressValidationInfo | The address to resolve
    try {
      AddressResolutionModel result = apiInstance.resolveAddressPost(xAvalaraClient, body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling AddressesApi#resolveAddressPost");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Documentation for Authorization

Authentication schemes defined for the API:

OAuth Client Credentials

  • Type: OAuth
  • Flow: client_credentials
  • Scopes:
    • avatax_api: avatax_api scope.
import Avalara.SDK.*;
import Avalara.SDK.auth.*;
import Avalara.SDK.model.Avatax.*;
import Avalara.SDK.api.Avatax.AddressesApi;

public class AddressesApiExample {

  public static void main(String[] args) {
    Configuration configuration = new Configuration();
    configuration.setAppName("Test");
    configuration.setAppVersion("1.0");
    configuration.setMachineName("LocalBox");
    configuration.setTimeout(5000);
    configuration.setEnvironment(AvaTaxEnvironment.Sandbox);
    // Configure OAUTH2 Client Credentials flow
    configuration.setClientId("YOUR CLIENT_ID");
    configuration.setClientSecret("YOUR CLIENT_SECRET");

    ApiClient apiClient = new ApiClient(configuration);
    AddressesApi apiInstance = new AddressesApi(apiClient);
    String xAvalaraClient = "Swagger UI; 22.7.0; Custom; 1.0"; // String | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
    AddressValidationInfo body = new AddressValidationInfo(); // AddressValidationInfo | The address to resolve
    try {
      // SDK will fetch OAuth token using client creds flow with Avalara Identity and append Authorization header to the request with the access token.
      AddressResolutionModel result = apiInstance.resolveAddressPost(xAvalaraClient, body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling AddressesApi#resolveAddressPost");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

OAuth Device Code Flow

  • Type: OAuth
  • Flow: device_code
  • Scopes:
    • avatax_api: avatax_api scope.
import Avalara.SDK.*;
import Avalara.SDK.auth.*;
import Avalara.SDK.model.Avatax.*;
import Avalara.SDK.api.Avatax.AddressesApi;

public class AddressesApiExample {

  public static void main(String[] args) {
    Configuration configuration = new Configuration();
    configuration.setAppName("Test");
    configuration.setAppVersion("1.0");
    configuration.setMachineName("LocalBox");
    configuration.setTimeout(5000);
    configuration.setEnvironment(AvaTaxEnvironment.Sandbox);
    // Configure OAUTH2 Device code flow
    configuration.setClientId("YOUR CLIENT_ID");

    DeviceAuthResponse response = ApiClientHelper.initiateDeviceAuthorizationOAuth(null, configuration);
    DeviceAccessTokenResponse tokenResponse = ApiClientHelper.getAccessTokenForDeviceFlow(response.getDeviceCode(), configuration);
    configuration.setBearerToken(tokenResponse.getAccessToken());

    ApiClient apiClient = new ApiClient(configuration);
    AddressesApi apiInstance = new AddressesApi(apiClient);
    String xAvalaraClient = "Swagger UI; 22.7.0; Custom; 1.0"; // String | Identifies the software you are using to call this API.  For more information on the client header, see [Client Headers](https://developer.avalara.com/avatax/client-headers/) .
    AddressValidationInfo body = new AddressValidationInfo(); // AddressValidationInfo | The address to resolve
    try {
      // SDK will fetch OAuth token using client creds flow with Avalara Identity and append Authorization header to the request with the access token.
      AddressResolutionModel result = apiInstance.resolveAddressPost(xAvalaraClient, body);
      System.out.println(result);
    } catch (ApiException e) {
      System.err.println("Exception when calling AddressesApi#resolveAddressPost");
      System.err.println("Status code: " + e.getCode());
      System.err.println("Reason: " + e.getResponseBody());
      System.err.println("Response headers: " + e.getResponseHeaders());
      e.printStackTrace();
    }
  }
}

Recommendation

It's recommended to create an instance of ApiClient per thread in a multithreaded environment to avoid any potential issues.

Author

Documentation for API Endpoints

EInvoicing V1 API Documentation

Class Method HTTP request Description
DataInputFieldsApi getDataInputFields GET /data-input-fields Returns the mandatory and conditional invoice or creditnote input fields for different country mandates
DocumentsApi downloadDocument GET /documents/{documentId}/$download Returns a copy of the document
DocumentsApi getDocumentList GET /documents Returns a summary of documents for a date range
DocumentsApi getDocumentStatus GET /document/{documentId}/status Checks the status of a document
DocumentsApi submitDocument POST /documents Submits a document to Avalara E-Invoicing API
MandatesApi getMandates GET /mandates List country mandates that are supported by the Avalara E-Invoicing platform

Documentation for Models

EInvoicing V1 Model Documentation