Some users write into our support desk wondering how they can increase efficiency and reduce overall API response times in order to make a high volume of requests through our platform. In this article, we will discuss some of the reasons that slow response times can happen and talk about strategies for mitigating those issues.
Problem
It's important to understand that EasyPost interacts with many different carriers who have their own API platforms, such carriers include FedEx, UPS, DHL, and others. When you make API calls we often have to query these carriers in real-time in order to provide you with rates that are applicable to your specific account. Many times the slow response you are experiencing is due to a slow response from one or more of these carriers. It's also important to understand that when you rate against multiple carriers in one API call, the slow response problem can be compounded (i.e: multiple calls waiting to resolve means more wait time).
Strategies
- Restrict the number of carriers you rate against at one time. You may have noticed in our API Documentation for shipment creation this key called "carrier_accounts" is mentioned. This key takes an array of carrier account_id's that might look something like "
carrier_accounts":["ca_...", "ca_..."]
. When you use this key with its array of values it tells our API that you only want to rate against the carrier accounts that you specified within that array. With this method, you can restrict the number of carrier accounts you rate against. If you do not pass this key/value pair we will assume that you wish to rate against ALL carrier accounts that are associated with your user account. - Skip the rating process altogether (if you wish). Sometimes you may already know what carrier and service you wish to purchase and you may not care about rating this service before you buy it. If that is the case then you can perform what we call a "one call shipment buy". A one-call shipment buy is just like creating a shipment, only this time you will specify the
carrier_account
andservice
that you wish to buy in the creation call. When you do this we will immediately purchase the service you specified and return a label to you. This methodology can help users reduce the overall time it takes to generate a shipping label. This workflow may not work for all users, so you'll want to consider your specific workflow before implementing this. Please note using the method means you will not see the cost of the rate within EasyPost (because we skip rating altogether). As such, theselected_rate.rate
will show up as a dummy rate of 1 cent, even though you'll be charged the correct price from the carrier. Here is an example of a cURL "one call buy":
curl -X POST https://api.easypost.com/v2/shipments \
-u <YOUREasyPostTESTAPIkeyKEEPtheCOLON>: \
-d 'shipment[to_address][name]=Dr. Steve Brule' \
-d 'shipment[to_address][street1]=123 Fake St' \
-d 'shipment[to_address][city]=Redondo Beach' \
-d 'shipment[to_address][state]=CA' \
-d 'shipment[to_address][zip]=90277' \
-d 'shipment[to_address][country]=US' \
-d 'shipment[to_address][phone]=1234567890' \
-d 'shipment[to_address][email]=dr_steve_brule@none.none' \
-d 'shipment[from_address][name]=EasyPost' \
-d 'shipment[from_address][street1]=123 Fake St' \
-d 'shipment[from_address][street2]=5th Floor' \
-d 'shipment[from_address][city]=San Francisco' \
-d 'shipment[from_address][state]=CA' \
-d 'shipment[from_address][zip]=94104' \
-d 'shipment[from_address][country]=US' \
-d 'shipment[from_address][phone]=1234567890' \
-d 'shipment[from_address][email]=support@easypost.com' \
-d 'shipment[parcel][length]=20.2' \
-d 'shipment[parcel][width]=10.9' \
-d 'shipment[parcel][height]=5' \
-d 'shipment[parcel][weight]=65.9' \
-d 'shipment[carrier_accounts][0]=ca_yourFedExCarrierAccountID' \
-d 'shipment[service]=FEDEX_GOUND'
3. Reuse persisted EasyPost objects. EasyPost persists many objects that are created so that you can reuse them again and again. An example of this would be a saved address object. When you create an address (see API Documentation) EasyPost will save the address as an object and it will have a unique address_id
. If you know that you will be shipping to the same address over and over or you will be shipping from the same address over and over you can save the address_id
's on your side and inject them into your shipments, rather than creating an entirely new address object every time. This is another method that can help you reduce the total number of API calls you make.
Beyond these strategies, if you still feel that you are experiencing excessive API response times that are abnormal please shoot us an email at support@easypost.com that includes the shipment_id
's or other request details as applicable and we can investigate the issues on our end.