Skip to content

Instantly share code, notes, and snippets.

@lobot
Last active Sep 30, 2022
Embed
What would you like to do?
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.PostcardsApi;
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>");
PostcardsApi apiInstance = new PostcardsApi(lobClient);
PostcardEditable postcardEditable = new PostcardEditable();
AddressEditable to = new AddressEditable();
to.setName("MORTICIA ADDAMS");
to.setAddressLine1("1313 CEMETERY LN");
to.setAddressCity("WESTFIELD");
to.setAddressState("NJ");
to.setAddressZip("07091");
AddressEditable to = new AddressEditable();
to.setName("MORTICIA ADDAMS");
to.setAddressLine1("1313 CEMETERY LN");
to.setAddressCity("WESTFIELD");
to.setAddressState("NJ");
to.setAddressZip("07091");
AddressEditable from = new AddressEditable();
from.setName("FESTER");
from.setAddressLine1("001 CEMETERY LN");
from.setAddressLine2("SUITE 666");
from.setAddressCity("WESTFIELD");
from.setAddressState("NJ");
from.setAddressZip("07091");
Gson gson = new Gson();
postcardEditable.setTo(gson.toJson(to));
postcardEditable.setFrom(gson.toJson(from));
postcardEditable.setFront("https://s3-us-west-2.amazonaws.com/public.lob.com/assets/templates/4x6_pc_template.pdf");
postcardEditable.setBack("https://s3-us-west-2.amazonaws.com/public.lob.com/assets/templates/4x6_pc_template.pdf");
try {
Postcard result = apiInstance.create(postcardEditable);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PostcardsApi#postcardCreate");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment