Skip to content

Instantly share code, notes, and snippets.

@joncalhoun
Created October 1, 2012 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joncalhoun/3810769 to your computer and use it in GitHub Desktop.
Save joncalhoun/3810769 to your computer and use it in GitHub Desktop.
Buy postage with Easy Post and Java
EasyPost.setApiKey("ek_0HbTD15HeT6RFTwCKoUQ7rrB2NzMZ");
// Create the package
EasyPost.Package package = new EasyPost.Package()
.setWeigth(1.1)
.setHeight(12)
.setWidth(14)
.setLength(7);
// Create the to and from addresses
EasyPost.Address toAddress = new EasyPost.Address()
.setName("Reed Rothchild")
.setStreet1("101 California St")
.setStreet2("Suite 1290")
.setCity("San Francisco")
.setState("CA")
.setZip("94111");
EasyPost.Address fromAddress = new EasyPost.Address()
.setName("Dirk Diggler")
.setStreet1("300 Granelli Ave")
.setCity("Half Moon Bay")
.setState("CA")
.setZip("94019");
// Create the request for postage
EasyPost.PostageRequest pr = new EasyPost.PostageRequest()
.setTracking(true)
.setInsurance(true)
.setPackage(package)
.setTo(toAddress)
.setFrom(fromAddress)
// Optionally
.setDescription("Postage for VHS of Boogie Nights")
.setExternalId("31224974"); // The ID of the order in your own DB.
// Purchase the postage
EasyPost.Postage.buy(pr);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment