USPS get multiple package rates

USPS-get multiple package rateI am currently working on a domestic shipping rate comparison project and one of the carriers that I need to get rates was USPS. In my project , we had more than just one package to get rate and this can turn into a real problem to deal with. In order to get rates in one shot, I went with the batch processing.

You can find USPS’ s API documentation here about getting rates. For the USPS rate API we don’t need to specify a password and note that We can only add packages up to 25 which makes our calls pretty fast.

Lets take a look at xml request example which is given here. All we need to do is using the production link and producing a valid xml structure for making request.

You can see the xml request for rate API below:

In response, we get this from USPS :

Multiple Package Thing

For getting multi-package rates from USPS, we only need to append a new “Package” item with a unique ID into the xml request, but as i mentioned above we can’t just keep on adding packages, limit is 25 package per request. So I end up writing something  like this in C#. In foreach loop it checks the limit and behave appropriate to the situation.

Here is the github link of the class.

Leave a Reply

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