How To Access Rates of Multiple Shipping Carriers through a Single API (With Free Shipping API)

Multi Carrier

Last updated - February 24, 2020

In this article, you will understand how to access this API and get domestic and international rates for your package from different shipping carriers like FedEx, UPS, and USPS. You just have to specify shipper address, recipient address, type of service, and authorization details for the specific carrier as an encrypted JSON data.

To use this API, you need to register on http://shippingapi.storepep.com and get a free API key in your email, you just need to provide your email id during signup.

GET : List of Available Services

1: Get All Available FedExServices:
Comand:       curl   http://shippingapi.storepep.com/api/shippings/fedex-services        

Output:
{
"FEDEX_1_DAY_FREIGHT":"FEDEX 1 DAY FREIGHT",
"FEDEX_2_DAY":"FEDEX 2 DAY",
"FEDEX_2_DAY_AM":"FEDEX 2 DAY AM",
"FEDEX_2_DAY_FREIGHT":"FEDEX 2 DAY FREIGHT",
"FEDEX_3_DAY_FREIGHT":"FEDEX 3 DAY FREIGHT",
"FEDEX_DISTANCE_DEFERRED":"FEDEX DISTANCE DEFERRED",
"FEDEX_EXPRESS_SAVER":"FEDEX EXPRESS SAVER",
"FEDEX_FIRST_FREIGHT":"FEDEX FIRST FREIGHT",
"FEDEX_FREIGHT_ECONOMY":"FEDEX FREIGHT ECONOMY",
"FEDEX_FREIGHT_PRIORITY":"FEDEX FREIGHT PRIORITY",
"FEDEX_GROUND":"FEDEX GROUND",
"FEDEX_NEXT_DAY_AFTERNOON":"FEDEX NEXT DAY AFTERNOON",
"FEDEX_NEXT_DAY_EARLY_MORNING":"FEDEX NEXT DAY EARLY MORNING",
"FEDEX_NEXT_DAY_END_OF_DAY":"FEDEX NEXT DAY END OF DAY",
"FEDEX_NEXT_DAY_FREIGHT":"FEDEX NEXT DAY FREIGHT",
"FEDEX_NEXT_DAY_MID_MORNING":"FEDEX NEXT DAY MID MORNING",
"FIRST_OVERNIGHT":"FIRST OVERNIGHT",
"GROUND_HOME_DELIVERY":"GROUND HOME DELIVERY",
"EUROPE_FIRST_INTERNATIONAL_PRIORITY":"EUROPE FIRST INTERNATIONAL PRIORITY",
"INTERNATIONAL_ECONOMY":"INTERNATIONAL ECONOMY",
"INTERNATIONAL_ECONOMY_FREIGHT":"INTERNATIONAL ECONOMY FREIGHT",
"INTERNATIONAL_FIRST":"INTERNATIONAL FIRST",
"INTERNATIONAL_PRIORITY":"INTERNATIONAL PRIORITY",
"INTERNATIONAL_PRIORITY_FREIGHT":"INTERNATIONAL PRIORITY FREIGHT",
"PRIORITY_OVERNIGHT":"PRIORITY OVERNIGHT",
"SAME_DAY":"SAME DAY",
"SAME_DAY_CITY":"SAME DAY CITY",
"SMART_POST":"SMART POST",
"STANDARD_OVERNIGHT":"STANDARD OVERNIGHT"
}

2: Get All Available UPS Services:
Comand:       curl   http://shippingapi.storepep.com/api/shippings/ups-services        
Output:

{
'01': 'UPS Next Day Air',
'02': 'UPS Second Day Air',
'03': 'UPS Ground',
'07': 'UPS Worldwide Express',
'08': 'UPS Worldwide Expedited',
'11': 'UPS Standard',
'12': 'UPS Three-Day Select',
'13': 'UPS Next Day Air Saver',
'14': 'UPS Next Day Air Early A.M.',
'54': 'UPS Worldwide Express Plus',
'59': 'UPS Second Day Air A.M.',
'65': 'UPS Saver',
'82': 'UPS Today Standard',
'83': 'UPS Today Dedicated Courier',
'84': 'UPS Today Intercity',
'85': 'UPS Today Express',
'86': 'UPS Today Express Saver',
'92': 'UPS SurePost (USPS) < 1lb', '93': 'UPS SurePost (USPS) > 1lb',
'94': 'UPS SurePost (USPS) BPM',
'95': 'UPS SurePost (USPS) Media'
}

3: Get All Available USPS Services:
Comand:       curl   http://shippingapi.storepep.com/api/shippings/usps-services        
Output:

{
'First Class>LETTER':'First Class>LETTER',
'First Class>FLAT':'First Class>FLAT',
'First Class>PARCEL':'First Class>PARCEL',
'First Class>POSTCARD':'First Class>POSTCARD',
'First Class>PACKAGE SERVICE':'First Class>PACKAGE SERVICE',
'First Class Commercial>PACKAGE SERVICE':'First Class Commercial>PACKAGE SERVICE',
'First Class HFP Commercial>PACKAGE SERVICE':'First Class HFP Commercial>PACKAGE SERVICE',
'Priority':'Priority',
'Priority Commercial':'Priority Commercial',
'Priority Cpp':'Priority Cpp',
'Priority HFP Commercial':'Priority HFP Commercial',
'Priority HFP Cpp':'Priority HFP Cpp',
'Priority Mail Express':'Priority Mail Express',
'Priority Mail Express Commercial':'Priority Mail Express Commercial',
'Priority Mail Express Cpp':'Priority Mail Express Cpp',
'Priority Mail Express HFP':'Priority Mail Express HFP',
'Priority Mail Express HFP Commercial':'Priority Mail Express HFP Commercial',
'Standard Post':'Standard Post',
'Retail Ground':'Retail Ground',
'Media':'Media',
'Library':'Library',
'Online Plus':'Online Plus',
'12':'Global Express Guaranteed',
'1':'Priority Mail Express International',
'2':'Priority Mail International',
'9':'Priority Mail International Medium Flat Rate Box',
'11':'Priority Mail International Large Flat Rate Box',
'16':'Priority Mail International Small Flat Rate Box',
'15':'First Class Package International Service'
}


 

POST: Rates API

To use Rates API first we need to understand the structure of this API request

Name Description
  Common_Params  Contains inner elements common to all shipping companies
  Common_Params >environment  for test mode: sandbox, for production mode: live
  Common_Params >emailid  Email id registered for this API
  Common_Params >key  API Key received during registration
  Common_Params >host  Optional (your host name)
  Common_Params >os  Optional (your operating system details)
  Common_Params >Shipper_PersonName  Sender’s name
  Common_Params >Shipper_CompanyName  Sender’s company
  Common_Params >Shipper_PhoneNumber  Sender’s phone number
  Common_Params >Shipper_Address_StreetLines  Sender’s street address
  Common_Params >Shipper_Address_City  Sender’s city
  Common_Params >Shipper_Address_StateOrProvinceCode  Sender’s state/province code  (*not more than two letter)
  Common_Params >Shipper_Address_PostalCode  Sender’s postal code
  Common_Params >Shipper_Address_CountryCode  Sender’s country code (*only two letter code)
  Common_Params >Recipient_PersonName  Recipient’s name
  Common_Params >Recipient_CompanyName  Recipient’s company
  Common_Params >Recipient_PhoneNumber  Recipient’s phone number
  Common_Params >Recipient_Address_StreetLines  Recipient’s street address
  Common_Params >Recipient_Address_City  Recipient’s city
  Common_Params >Recipient_Address_StateOrProvinceCode  Recipient’s state/province code ()
  Common_Params >Recipient_Address_PostalCode  Recipient’s postal code
  Common_Params >Recipient_Address_CountryCode  Receipient’s country code
  Common_Params >Recipient_Address_CountryName  Recipient’s country name
  Common_Params >Recipient_Address_Residential  True/False  (is recipient’s residential address)
  Common_Params >fedex_key  Key received from FedEx
  Common_Params >fedex_password  FedEx password
  Common_Params >fedex_account_number  FedEx account number
  Common_Params >fedex_meter_number  FedEx meter number
  Common_Params >ups_key Key received from UPS
  Common_Params >ups_password  UPS password
  Common_Params >ups_account_number  UPS account number
  Common_Params >ups_username  User name received from UPS
  Common_Params >usps_username  USPS user name
  Request_Array  This object contains requests for multiple companies and multiple packages
  Request_Array > Array of Request  Multiple request passed in one array

 

Structure of Request (as in Request_Array  )

Name Description
  Request  Contains inner elements common to all carriers (shipping companies)
  Request>id  Any unique ID to identify this package (ID of this array element)
  Request>company  Name of the shipping carrier (eg: ‘fedex’, ‘ups’, ‘usps’) to get rates from these companies for this package
  Request>Weight_Units  Unit of weight (currently only ‘LB’ is supported)
  Request>ServiceType  Service code for the specific carrier service for which rate is required. Refer to  carriers’ API documentation.
  Request>RateRequestTypes  ‘NONE’ for account specific rates and ‘LIST’ for retail rates
  Request>packages

Sample JSON (Before Encryption)
:
{
	"Common_Params": {
		"environment": "sandbox",
		"emailid": "123@example.com",
		"key": "b52ee1f3ab8454589d6a9bd5018d60be",
		"host": "www.storepep.com",
		"os": "Windows NT 6.3 build 9600 (Windows 8.1 Home) i586",
		"Shipper_PersonName": "JOE CHRIST",
		"Shipper_CompanyName": "MY COMPANY",
		"Shipper_PhoneNumber": "0123456789",
		"Shipper_Address_StreetLines": "SILK BOARD",
		"Shipper_Address_City": "COLUMBUS",
		"Shipper_Address_StateOrProvinceCode": "OH",
		"Shipper_Address_PostalCode": "43218",
		"Shipper_Address_CountryCode": "US",
		"Recipient_PersonName": "Recipient Name",
		"Recipient_CompanyName": "XYZ",
		"Recipient_PhoneNumber": "0123456789",
		"Recipient_Address_StreetLines": "123 , XYZ ROAD",
		"Recipient_Address_City": "",
		"Recipient_Address_StateOrProvinceCode": "WA",
		"Recipient_Address_PostalCode": "98503",
		"Recipient_Address_CountryCode": "US",
		"Recipient_Address_CountryName": "United States (US)",
		"Recipient_Address_Residential": "false",
		"fedex_key": "UzxdpT3cy7UDF3Vl",
		"fedex_password": "I1IWFyvBz34QnJOwqZyBn9oll",
		"fedex_account_number": "110087444",
		"fedex_meter_number": "128768444",
		"ups_key": "DCEF2E428E10BBB7",
		"ups_password": "Q1w2e3r4t5o5",
		"ups_account_number": "189Y5A",
		"ups_username": "iahtai21",
		"usps_username": "806XDDAP3116",
		"usps_password": "516GD04CJ256"
	},
	"Request_Array": [
		{
			"id": "53:1",
			"company": [
				"usps"
			],
			"Weight_Units": "LB",
			"ServiceType": "Priority",
			"RateRequestTypes": "NONE",
			"packages": [
				{
					"weight": 2,
					"unit": "LBS",
					"Description": "My Package",
					"no_of_packages": 1,
					"SequenceNumber": 1
				}
			]
		},
		{
			"id": "53,37:1",
			"company": [
				"fedex"
			],
			"Weight_Units": "LB",
			"ServiceType": "FEDEX_GROUND",
			"RateRequestTypes": "NONE",
			"packages": [
				{
					"weight": 1.5,
					"unit": "LBS",
					"Description": "My Package",
					"no_of_packages": 1,
					"SequenceNumber": 3
				}
			]
		}
	]
}

After generating such a JSON object, you need to encode this object using your unique API Key. We are providing the Encoding Algorithm below, so that it would be easy for you to proceed.

PHP function to encode this JSON request

<?php
    function encode($key,$data)
    {
     $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
     $key256 = $key;
     $iv = '1156651@Xadapter';
     mcrypt_generic_init($cipher, $key256, $iv);
     $cipherText256 = mcrypt_generic($cipher,$data );
     mcrypt_generic_deinit($cipher);
     $cipherHexText256 =bin2hex($cipherText256);
     return $cipherHexText256;
    }
?>

Next, put this encoded object into another JSON object (with two elements, ’emailid’ and ‘data’) and send it to the server.

<?php
  $req=array();
  $req['emailid']='123@example.com'; Your API Registered Email ID
  $apikey='b52ee1f3ab8454589d6a9bd5018d60be'; Your API Registered KEY
  $req['data']=$this->encode($apikey,$JSON_Req);
  $content =json_encode($req);
?>

Final JSON request looks like this:

   {"emailid":"123@example.com",
    "data":"839d8aff496f1cb1d62416eaaa9c79d07ffdca2c42e220ed64acf6af83e6db6119bb672339983138ab190cc9a985822b5d97c99c5a61b990e2ffe91f229bf5372884f4a4483328e7ce61196bb266047439639a5c1245822064584373cdfa4383d8b2c6a69e4b09f823916845108141557a9fbb7cebd4f2e20c862023bca3a78a903a98f0341af52122bfcf0cbadbd3dae20232ad603df9edd2e5ad42c46bb19b12445a3b431921244a16a3cec95d5e1b8b23b1256e7fc4221b7645765ab527ba0275d204f0b4ec713157aa0d50c4ff7a79333ba7411a266ba085e071740cc21664a49dc48384c8ef96dc4ab15557383c280416a2fedefa58e0dbb962d53adf515fec3e41ec5c4adc4b4e9f1fd1694a75e5f1ed75fe69bceba8bdf99b066dcfde231715e8bb9702b5f7acebbe60e965b1dd5f3fd8f090b9d0d0c2c77d7ccf7e7c2ce3f5c6288db8df24d562fb6a6aa8dd02eebbd96837a72915ae7dafae78eaa1ce8d616f2520289dd8c00a2ef75712e38d0307db3adc281ca4c7d6b5d7d6c2c2eda24781ef23d7cdf10f3621261abf215b53d08b969203e3fb12abd86e8a59f3882cfa6f2b551bb59d8621699b8c1452ebbc94ed2cbfe3ffb32be29ea83c73a2fa82df34631779286404f3b168ca8b71447ee03a033bf5bf5b44b692d54ef0d1b8126eea11468b0c583488874e425e43be46ba3f74835a3a12fa685455747c49d9a40ed94b2b33958fa7272da2635147"
   }

Send this JSON object to the server.

Have a look at the below example to understand how to send request in PHP:

                $curl = curl_init("http://shippingapi.storepep.com/api/shippings/rates");
                curl_setopt($curl, CURLOPT_HEADER, false);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
                curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
                curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, $content);  // this is the $content we created in code above
                $json_response = curl_exec($curl);
                $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
                curl_close($curl);
                $response = json_decode($json_response, true);
                print_r($response);

1 COMMENT

  1. Really want to get this – Went to the link provided, however it says the access is denied.

    Does one have to be a purchasing member to get the API?

Leave a Reply to wulfgen Cancel reply

Please enter your comment!
Please enter your name here