USPS Web Tools for Address Validation, part two

(As noted in part one, this was originally written in 2010 or so, but everything should still apply today.)

In Part 1, I walked through the PHP code needed to send and retrieve the XML data the USPS Web Tools API works with. We managed to work our way through the first scripted test you are required to run on the USPS’ testing servers. That was a lot of words just to get through one of the 4 required tests, wasn’t it?

Now we come to the second scripted test. Shouldn’t be rocket science, right? I mean, we’ve already done the heavy lifting of figuring out how to use PHP to send the XML data and receive the response, so how hard could this be?

The second test looks like so:

<ZipCodeLookupRequest USERID=”xxxxxxxx”>
<Address ID=”1”><Address1></Address1>
<Address2>8 Wildwood Drive</Address2><City>Old Lyme</City><State>CT</State>

Notice this time, you are sending <Address ID=”1”>. The system will allow you to send up to 5 requests at a time, which is why the need the Address ID field. At one point in testing, this tripped me up, as I pulled the code from the first test, which uses <Address ID=”0”>. This will make the test fail. According to USPS, you have to send the test request and receive the response verbatim.

I fixed that mistake and tried again, and it didn’t work. No matter what I tried, it kept coming back in error, with the message that the XML Data was invalid according the the DTD/Schema. What the hell? I’m sending the test data exactly as they specified, but the response is failing. This was late at night that I was testing, so I eventually gave up for the evening and considered calling the Customer Care Center to see if they were aware the testing server seemed to be broken.

The next day, though, I thought I’d try something different before I called. I reran the test, but I stripped the <Zip5>06371</Zip5><Zip4></Zip4> out of the XML. Success! So, if you try the second test with the test data they provide and it fails, try again after removing the ZIP code XML tags.

I’ve noticed there appears to be a mistake in the API docs, indicating you need to send the Zip5 & Zip4 tags. If you look further down in the ‘Send Live Data’ section, you will see that they are not required. Not only that, but the validation will fail if you send them.

So, I’ve passed the scripted tests. Following their instructions, I tried calling the ICCC to have my results validated and be switched to their production servers. After sitting on hold for a good long while, which wouldn’t have been so bad if it hadn’t been for the interruption every 15 seconds to tell me my call was important to them, I gave up and emailed instead.

The next day, I get a reply back saying that my scripted tests were all good, but now I have to provide additional information on a web form. I clicked the link, providing the url that would host the tool interface, and went through their little checkbox list of what I intended to do with it. One piece of advice, do not check the ‘database cleansing’ box. If you do, you will be denied. I was being a bit of an idiot, and thinking of it backwards. I had no intention of scrubbing the database I already have, I just meant to keep it clean going forward. And so I had to write them back, essentially apologizing for being an idiot, assuring them that I only intend to use it within their T&C, and asking them to reconsider their decision.

They did reconsider, I’m happy to report, and I have been switched to the live server. It works like a charm for my purposes.

However, while I was waiting on their reconsideration, I started working on doing this another way, which will be in another post later.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>