Use the following guide to assist in the upgrade process of the easypost-java
library between major versions.
EasyPost now offers Carbon Neutral shipments by default for free! Because of this, there is no longer a need to specify if you want to offset the carbon footprint of a shipment. The withCarbonOffset
parameter of the create
, buy
, and regenerateRates
shipment functions have been removed as a result, as well as the overload functions that have withCarbonOffset
parameter. This is a high-impact change for those using EndShippers
as the function interfaces have changed. You will need to inspect the callsites to create and buy shipments to ensure that the EndShipper parameter is being passed in the correct place now that the withCarbonOffset
parameter has been removed.
The createAndBuy
Batch endpoint has been deprecated and removed from the library. The correct procedure is to first create a batch and then purchase it with two separate API calls.
The return type of all
function in webhook service has been changed from WebhookCollection
to a list of webhooks
, the reason of this change is this endpoint returns a unpaginated list of webhooks. Therefore, there is no need to have WebhookCollection
class which wraps the list of webhooks.
NOTICE: v6 is deprecated.
Likelihood of Impact: High
The library is now designed around the idea of a EasyPostClient
. Users will initialize an EasyPostClient
instance with their API key and then use that instance to make API calls.
This change allows for multiple clients to be instantiated with different API keys which allows this library to be safely used in a multi-threaded environment.
// Old
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY"); // global API key
// New
EasyPostClient client1 = new EasyPostClient("EASYPOST_API_KEY_1"); // per-client API key
EasyPostClient client2 = new EasyPostClient("EASYPOST_API_KEY_2"); // per-client API key
All functions are now accessed via the EasyPostClient
instance. For example, to create a shipment:
// Old
EasyPost.apiKey = System.getenv("EASYPOST_API_KEY");
Shipment shipment = Shipment.create(shipmentMap);
// New
EasyPostClient client = new EasyPostClient("EASYPOST_API_KEY_1");
Shipment shipment = client.shipment.create(shipmentMap);
Likelihood of Impact: High
Error handling has been overhauled and a number of specific exception types have been introduced.
All exceptions inherit from EasyPost.Exception.EasyPostException
(which extends Java Exception
class). Users can catch this exception type to handle all errors thrown by the library.
Subclasses of EasyPostException
are grouped into two categories:
EasyPost.Exception.API
for errors returned by the API. Subclasses of this exception type are:ExternalApiError
- thrown when an issue occurs with an external API (e.g. Stripe)ForbiddenError
- thrown when you don't have permission to access this API resourceGatewayTimeoutError
- thrown when the API gateway times out (504 status code)InternalServerError
- thrown when an internal server error occurs (500 status code)InvalidRequestError
- thrown when the API received an invalid request (422 status code)MethodNotAllowedError
- thrown when the API receives a request with an invalid HTTP method ( 405 status code)NotFoundError
- thrown when the API receives a request for a resource that does not exist ( 404 status code)PaymentError
- thrown when a payment error occurs (402 status code)ProxyError
- thrown when the library is unable to connect to the API via a proxyRateLimitError
- thrown when the API rate limit is exceeded (429 status code)RedirectError
- thrown when the http status is between 300 and 308.ServiceUnavailableError
- thrown when the API is unavailable (503 status code)TimeoutError
- thrown when the API request times out (408 status code)UnauthorizedError
- thrown when the API receives an unauthorized request (401 or 403 status code)UnknownApiError
- thrown when an unknown API error occurs (unexpected 4xx status code)
EasyPost.Exception.General
for Generic error returned by the client library. Subclasses of this exception type are:FilteringError
- thrown when an error occurs during filtering (e.g. calculating lowest rate)InvalidObjectError
- thrown when an invalid object is being usedInvalidParameterError
- thrown when an invalid parameter is being usedMissingPropertyError
- thrown when a required property is missing (e.g.Id
for most objects)SignatureVerificationError
- thrown when the signature for a webhook is invalid
Any exception thrown by the EasyPost library will be one of the above types.
Any EasyPost.Exception.API
exception will have the following properties:
String Code
- the HTTP status code returned by the API call (e.g. 404)String Message
- the error message returned by the API (e.g. "PARAMETER.INVALID")List<Error> Errors
- a list of errors returned by the API (e.g. "Invalid parameter: to_address")
Users can better anticipate exception information through utilities in the EasyPost.Exception.Constants
file.
Likelihood of Impact: High
The following functions return an empty body from the API have been changed to return void.
fundWallet()
anddeletePaymentMethod()
in Billing classcreateList()
in Tracker classupdateEmail()
in ReferralCustomer class
Likelihood of Impact: High
Static and instance-based methods have been divided into separate services and resources, methods that have API interactions are in services now.
For example:
- The static method
Shipment.buy()
is now accessible in the Shipment service viaclient.shipment.buy("shp_...")
. - The instance method
myShipment.lowestRate()
is still accessible only via a Shipment instance because there is no API interaction. - The instance method of
refresh()
has been removed because you can no longer use an object to make a HTTP request.
Instances of an object cannot be initialized directly. Instead, use the service to create the instance via a create
, retrieve
, or all
API call.
Likelihood of Impact: Medium
Objects no longer have setters. The use case of the setter is extremely low, but if you need to use the setter for a specific reason, try to use reflection
in Java.
Likelihood of Impact: Medium
The following getters have been renamed:
- Pickup class:
getPickoutRates()
->getPickupRates()
- PaymentMethod class:
getPrimaryPaymentMethodObject()
->getPrimaryPaymentMethod()
- PaymentMethod class:
getSecondaryPaymentMethodObject()
->getSecondaryPaymentMethod()
Likelihood of Impact: Low
The following properties have changed types:
result
of Event fromEasyPostResource
toMap<String, object>
amount
of Insurance fromFloat
toString
NOTICE: v5 is deprecated.
Likelihood of Impact: High
Java 8 Required
easypost-java now requires Java 8 or greater.
Dependencies
All dependencies had minor version bumps.
Likelihood of Impact: High
All POST
and PUT
request bodies are now JSON encoded instead of form-encoded. You may see subtle inconsistencies to how certain data types were previously sent to the API. We have taken steps to mitigate and test against these edge cases.
Likelihood of Impact: Medium
Default timeouts for all HTTP requests are now set to 30 seconds for connection and 60 seconds for requests. If you require longer timeouts, you can set them by overriding the defaults:
// Timeouts are in milliseconds
EasyPostResource.setConnectTimeoutMilliseconds(30000);
EasyPostResource.setReadTimeoutMilliseconds(60000);
Likelihood of Impact: Low
The Item
and Container
objects were removed as they have not been supported for some time.