Skip to content
ColdFusion CFC used to connect to the USPS API.
Latest commit 3e671cf Jul 9, 2014 @matthewriley Merge pull request #1 from sfeldkamp/patch-1
fix prod secure url
Failed to load latest commit information.
LICENSE-2.0.txt ColdFusion 9 updates. Oct 1, 2012
ManualTester.html ColdFusion 9 updates. Oct 1, 2012
NOTICE.txt Significant update. Includes CarrierPickupAvailability, CityStateLook… Jun 9, 2012 Changed XML blocks so optional nodes are not passed in. Added support… Dec 17, 2012
usps.cfc fix prod secure url Jul 5, 2014

ColdFusion USPS CFC

This is a ColdFusion CFC used to connect to the USPS API. This has been tested with ColdFusion 9 and 10.

API's Supported:

  • CarrierPickupAvailability
  • CityStateLookup
  • ExpressMailCommitment
  • IntlRateV2
  • RateV4
  • TrackV2
  • Verify
  • ZipCodeLookup

In order for this CFC to work you need a USPS API account and you'll need to perform the tests required by the USPS to activate your account.


This is a straight forward CFC. You can initialize it using your preferred method. Here are a few examples. The named arguments are listed for clarity but you can also pass the values in by themselves.


variables.uspsUserID = 'YourIdHere';
variables.usps = CreateObject('component', 'usps').init(isProduction=false, isSecure=false, uspsUserID=variables.uspsUserID);

New Keyword

variables.uspsUserID = 'YourIdHere';
variables.usps = New usps(isProduction=false, isSecure=false, uspsUserID=variables.uspsUserID);


This assumes you're setting the properties elsewhere, otherwise you can set them as static strings.

<bean id="usps" class="usps" singleton="true" lazy-init="true" autowire="no">
    <constructor-arg name="isProduction"><value>${isProduction}</value></constructor-arg>
    <constructor-arg name="isSecure"><value>${isSecure}</value></constructor-arg>
    <constructor-arg name="uspsUserID"><value>${uspsUserID}</value></constructor-arg>

Sample Usage

Here's an example in cfscript:

variables.uspsUserID = 'YourIdHere';
variables.usps = New usps(false, false, variables.uspsUserID);

// USPS Canned Test: This test cleanses an address and provides the ZIP+4 value.
variables.Verify1 = variables.usps.AddressValidate(
    Address2 = '6406 Ivy Lane',
    City = 'Greenbelt',
    State = 'MD'

// USPS Canned Test: This test will also cleanse the address and completes the ZIP Code.
variables.Verify2 = variables.usps.AddressValidate(
    Address2 = '6406 IVY LN',
    City = 'GREENBELT',
    State = 'MD',
    Zip5 = '20770',
    Zip4 = '1440'

Files Included


This is where the magic happens.


The USPS Development Guide includes a number of canned tests. This file has them preconfigured and ready to go. Plug in your USPS user ID and run it.


This is a plain HTML file with a form to post directly to the USPS Test API. Useful for debugging the XML outside of ColdFusion.

Pull Requests

I don't have all the USPS API's implemented so if there's one you'd like to add, feel free to do so with a pull request. Just be sure to follow the general method pattern for a consistent implementation.


Copyright © Matthew Riley

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
Something went wrong with that request. Please try again.