Lob
- API version: 1.3.0
The Lob API is organized around REST. Our API is designed to have predictable, resource-oriented URLs and uses HTTP response codes to indicate any API errors.
Looking for our legacy Java SDK?
For more information, please visit https://support.lob.com/
Automatically generated by the OpenAPI Generator
Building the API client library requires:
- Java 1.7+
- Maven/Gradle
First, you will need to first create an account at Lob.com and obtain your Test and Live API Keys.
Once you have created an account, you can access your API Keys from the Settings Panel.
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.
Add this dependency to your project's POM:
<dependency>
<groupId>com.lob</groupId>
<artifactId>lob-java</artifactId>
<version>13.0.0</version>
</dependency>
Some versions of the Spring framework introduce a dependency collision that prevents the Lob SDK from functioning correctly. In order to correct this, please add the following two blocks to your project's POM along with the dependency mentioned above.
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.1</version>
</dependency>
</dependencies>
</dependencyManagement>
and
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.1</version>
</dependency>
Add this dependency to your project's build file:
implementation "com.github.lob:lob-java:13.0.0"
At first generate the JAR by executing:
mvn clean package
Then manually install the following JARs:
target/lob-java-13.0.0.jar
target/lib/*.jar
package com.company.app;
import com.lob.api.ApiClient;
import com.lob.api.ApiException;
import com.lob.api.Configuration;
import com.lob.api.auth.*;
import com.lob.model.*;
import com.lob.api.client.AddressesApi;
public class App
{
public static void main( String[] args )
{
ApiClient lobClient = Configuration.getDefaultApiClient();
// Configure HTTP basic authorization: basicAuth
HttpBasicAuth basicAuth = (HttpBasicAuth) lobClient.getAuthentication("basicAuth");
basicAuth.setUsername("<YOUR_LOB_API_KEY>");
AddressesApi apiInstance = new AddressesApi(lobClient);
AddressEditable addressEditable = new AddressEditable();
addressEditable.setDescription("Harry - Office");
addressEditable.setName("Harry Zhang");
addressEditable.setCompany("Lob");
addressEditable.setAddressLine1("2261 Market Street");
addressEditable.setAddressCity("San Francisco");
addressEditable.setAddressState("CA");
addressEditable.setAddressZip("94114");
addressEditable.setAddressCountry(CountryExtended.US);
addressEditable.setPhone("555-555-5555");
addressEditable.setEmail("[email protected]");
try {
Address result = apiInstance.create(addressEditable);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling AddressesApi#addressCreate");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
The full and comprehensive documentation of Lob's APIs is available here.
$ mvn test "-Dtest=%regex[.*ApiTest.*]"
Integration tests run against a live deployment of the Lob API and require multiple valid API keys with access to specific features. As such, it is not expected that these tests will pass for every user in every environment.
To run integration tests:
$ LOB_API_TEST_KEY=<<YOUR TEST KEY>> LOB_API_LIVE_KEY=<<YOUR LIVE KEY>> mvn test "-Dtest=%regex[.*SpecTest.*]"
Run this the first time:
$ echo "LOB_API_TEST_KEY=<<YOUR TEST KEY>> LOB_API_LIVE_KEY=<<YOUR LIVE KEY>>" > LOCAL.env
Then, to run the integration tests:
$ env $(cat LOCAL.env) mvn test "-Dtest=%regex[.*SpecTest.*]"
Authentication schemes defined for the API:
- Type: HTTP basic authentication
It's recommended to create an instance of ApiClient
per thread in a multithreaded environment to avoid any potential issues.