|
You need to request ExpressMailLabelCertify access by emailing uspstechnicalsupport@mailps.custhelp.com
Then add this code to USPSManager (vb.net)
Public Function GetExpressMailConfirmationLabel(package As Package) As Package
Dim labeldate As String = package.ShipDate.ToShortDateString()
If package.ShipDate.ToShortDateString() = DateTime.Now.ToShortDateString() Then
labeldate = ""
End If
Dim url As String = "?API=ExpressMailLabelCertify&XML=<ExpressMailLabelCertifyRequest USERID=""{0}""><Option>{1}</Option><Revision>2</Revision><EMCAAccount></EMCAAccount><EMCAPassword></EMCAPassword><ImageParameters></ImageParameters><FromFirstName></FromFirstName><FromLastName>{2}</FromLastName><FromFirm>{3}</FromFirm><FromAddress1>{4}</FromAddress1><FromAddress2>{5}</FromAddress2><FromCity>{6}</FromCity><FromState>{7}</FromState><FromZip5>{8}</FromZip5><FromZip4>{9}</FromZip4><FromPhone></FromPhone><ToFirstName></ToFirstName><ToLastName>{10}</ToLastName><ToFirm>{11}</ToFirm><ToAddress1>{12}</ToAddress1><ToAddress2>{13}</ToAddress2><ToCity>{14}</ToCity><ToState>{15}</ToState><ToZip5>{16}</ToZip5><ToZip4>{17}</ToZip4><WeightInOunces>{18}</WeightInOunces><FlatRate></FlatRate><SundayHolidayDelivery></SundayHolidayDelivery><StandardizeAddress></StandardizeAddress><WaiverOfSignature></WaiverOfSignature><NoHoliday></NoHoliday><NoWeekend></NoWeekend><SeparateReceiptPage></SeparateReceiptPage><POZipCode>{19}</POZipCode><FacilityType></FacilityType><ImageType>{20}</ImageType><LabelDate>{21}</LabelDate><CustomerRefNo>{22}</CustomerRefNo><SenderName>{23}</SenderName><SenderEMail>{24}</SenderEMail><RecipientName>{25}</RecipientName><RecipientEMail>{26}</RecipientEMail><HoldForManifest></HoldForManifest><CommercialPrice></CommercialPrice><InsuredAmount></InsuredAmount><Container></Container><Size></Size><Width></Width><Length></Length><Height></Height><Girth></Girth></ExpressMailLabelCertifyRequest>"
url = GetURL() & url
'url = String.Format(url,this._userid, (int)package.LabelType, package.FromAddress.Contact, package.FromAddress.FirmName, package.FromAddress.Address1, package.FromAddress.Address2, package.FromAddress.City, package.FromAddress.State, package.FromAddress.Zip, package.FromAddress.ZipPlus4, package.ToAddress.Contact, package.ToAddress.FirmName, package.ToAddress.Address1, package.ToAddress.Address2, package.ToAddress.City, package.ToAddress.State, package.ToAddress.Zip, package.ToAddress.ZipPlus4, package.WeightInOunces.ToString(), package.ServiceType.ToString().Replace("_", " "), package.OriginZipcode, package.LabelImageType.ToString(), labeldate, package.ReferenceNumber, package.AddressServiceRequested.ToString(), package.FromAddress.Contact, package.FromAddress.ContactEmail, package.ToAddress.Contact, package.ToAddress.ContactEmail);
url = [String].Format(url, Me._userid, CInt(package.LabelType), package.FromAddress.Contact, package.FromAddress.FirmName, package.FromAddress.Address1, _
package.FromAddress.Address2, package.FromAddress.City, package.FromAddress.State, package.FromAddress.Zip, package.FromAddress.ZipPlus4, package.ToAddress.Contact, _
package.ToAddress.FirmName, package.ToAddress.Address1, package.ToAddress.Address2, package.ToAddress.City, package.ToAddress.State, package.ToAddress.Zip, _
package.ToAddress.ZipPlus4, package.WeightInOunces.ToString(), package.OriginZipcode, package.LabelImageType.ToString(), labeldate, _
package.ReferenceNumber, "", "", "", "")
Dim xml As String = web.DownloadString(url)
If xml.Contains("<Error>") Then
Dim idx1 As Integer = xml.IndexOf("<Description>") + 13
Dim idx2 As Integer = xml.IndexOf("</Description>")
Dim l As Integer = xml.Length
Dim errDesc As String = xml.Substring(idx1, idx2 - idx1)
Throw New USPSManagerException(errDesc)
End If
Dim i1 As Integer = xml.IndexOf("<ExpressMailLabelRequest>") + 27
Dim i2 As Integer = xml.IndexOf("</ExpressMailLabelRequest>")
'package.ShippingLabel = StringToUTF8ByteArray(xml.Substring(i1, i2 - i1))
'package.ShippingLabel = StringToUTF8ByteArray(xml.Substring(i1, i2 - i1))
package.ShippingLabel = Convert.FromBase64String(xml.Substring(i1, i2 - i1))
Return package
End Function
|
|
|
|
|
Can this be implemented in some way as an MS Office Add-in for say Excel?
|
|
|
|
|
Hi did you ever get to implement this in Excel? I am also looking for the same.
|
|
|
|
|
Unfortunately, have not had adequate time to investigate it further. Plus being stuck behind a firewall requires some advanced firewall rules to allow pass through which I am still fighting with my administrator on.
|
|
|
|
|
What reference do I add to the project for USPSManager and what file provides this? What references are added?
|
|
|
|
|
And this is the most valuable part.
|
|
|
|
|
How to Get Shipping Calculation? I want to get Rate.
|
|
|
|
|
|
The "MpSuffix" and "MpDate" are fields returned from the tracking response. It's unique to the tracking ID.
Flipping Fun
|
|
|
|
|
I'm trying this code out on one of my websites and it seems to be working great with the exception that it doesn't handle military address validation. (Ex: FPO AE, or APO AA)
Does anybody have some advice on how to format the url string for this?
|
|
|
|
|
Hello, I need to create shiping labels by using the api. For that I think I need to use Shipping Labels API. I am wondering if you have any experience with it. If so can you please share some sample code? Thank you very much
|
|
|
|
|
i am using following code to write the image to file but it is not working.
using (MemoryStream ms = new MemoryStream(p.ShippingLabel, 0, p.ShippingLabel.Length))
{
//ms.Write(p.ShippingLabel, 0, p.ShippingLabel.Length);
ms.Seek(0,SeekOrigin.Begin);
Image returnImage;
returnImage = Image.FromStream(ms); //here is gives error, Paramter is not valid
returnImage.Save("label.tif");
}
anyone please help
|
|
|
|
|
I noticed the article is under the The Code Project Open License (CPOL) (able to use in commercial software, redistribute, etc.), but the code says "Copyright by Scott Smith 2006". Are we able to use this in commercial products? Thanks, and great wrapper by the way.
|
|
|
|
|
Just wanted to place a recent note on this one, delivery confirmation is NOT activated on the testing server, so in order to be moved to the production Server, you need to successfully call the API 2 or 3 times (I've heard both) using the other API methods such as the following, than call or email and request to be upgraded!
These were copied from test options here: http://www.usps.com/webtools/htm/Development-Guide-v3-0b.htm#_Toc205879418[^]
Good Luck!
http://www.xbox360outletstore.com
string trackingNumber = "EJ958083578US";<br />
TrackingInfo info = new TrackingInfo();<br />
USPSManager manager = new USPSManager("<yourAPIusername>", true);<br />
info = manager.GetTrackingInfo(trackingNumber);<br />
Console.WriteLine(info.Summary);
<br />
Address resultAddress = new Address();<br />
Address address = new Address();<br />
address.Address2 = "6406 Ivy Lane";<br />
address.City = "Greenbelt";<br />
address.State = "MD";<br />
address.ID = 0;<br />
USPSManager manager = new USPSManager("<yourAPIusername>", true);<br />
resultAddress = manager.ValidateAddress(address);
|
|
|
|
|
Great article/library.
According to the USPS site, FirmName is limited to 38 characters. I've noticed that most of your setters do validations, but perhaps you've forgotten to include this validation for the FirmName property.
|
|
|
|
|
You Ever Finish The FedEx, UPS, & DHL Version Of This?
|
|
|
|
|
If anyone is wondering about shipping in Canada, check out purolator.com/eship for how to do it. I can give advice in more detail too.
|
|
|
|
|
I am completely new to XML so I'm sure I'm missing something fundamental here. I selected what looked like the simplest test - get city and state from zip - and attempted to display the results on a button click. Nuthin! Here's my code:
protected void TestButton_Click(object sender, EventArgs e)
{
USPSManager m = new USPSManager("//my_user_id//", true);
Address a = m.GetCityState("90210");
string city = a.City;
string state = a.State;
ResultLabel.Text = city + ", " + state;
}
Help plz ... thanks.
|
|
|
|
|
There is a bug in the library and that code won't work. Testing it myself now. Related to the earlier comment about FromXML method and the different Response types - FromXML only works with the AddressValidateRepsonse.
I'm trying with CityStateLookupResponse, and the code doesn't work.
|
|
|
|
|
You need to recompile this wrapper as MAX.USPS.DLL ..
USPS changed the way they return some of the XML and the programmer of this code hasn't updated to reflect that.. so that is why it doesn't work.
So before you recompile it, change the lines below..
public static Address FromXml(string xml)
{
Address a = new Address();
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(xml);
System.Xml.XmlNode element = doc.SelectSingleNode("/ZipCodeLookupResponse");
element = doc.SelectSingleNode("/CityStateLookupResponse/ZipCode/City");
if (element != null)
a._City = element.InnerText;
element = doc.SelectSingleNode("/CityStateLookupResponse/ZipCode/State/text()");
if (element != null)
a._State = element.InnerText;
element = doc.SelectSingleNode("/CityStateLookupResponse/ZipCode/Zip5");
if (element != null)
a._Zip = element.InnerText;
return a;
}
I am using vb.net so i add a reference to the max.usps.dll, and i just call it in a button
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create a new instance of the USPS Manager class
'The constructor takes 2 arguments, the first is
'your USPS Web Tools User ID and the second is
'true if you want to use the USPS Test Servers.
Dim m As New MAX.USPS.USPSManager("YOUR_USER_ID", False) 'REPLACE YOUR_USER_ID with your USERID!
Dim a As MAX.USPS.Address = m.GetCityState("90210")
Dim city As String = a.City
Dim zip As String = a.Zip
Dim state As String = a.State
'Dim firmname As String = a.FirmName
MsgBox(city)
MsgBox(state)
MsgBox(zip)
End Sub
In future, if you need to understand selecting xml nodes, i recommend checking out a freeware tool like visual xpath.
Also.. you have to contact USPS a couple of times before they give you full access to production servers & all API's.
hope that helps!
modified on Friday, November 5, 2010 4:06 PM
|
|
|
|
|
Can some one shed some light how to process certified mail using this api?
|
|
|
|
|
I amd recieving 80040b1a API Authorization failure. User xxxxxxxxxxxx is not authorized to use API DeliveryConfirmationV3. UspsCom::DoAuth
|
|
|
|
|
Hi: I had the same problem, and fixed it by going to the production server. The test server is not set up to work with deliver confirmation. Also, you need to use the secure servers (that is in the email they send you) for the shipping label stuff. The documentation does not tell you this. You have to call them (800-344-7779) and be promoted to the production server:
'For Secure Servers (shipping labels, RMA), use these
Private Const ProductionUrl As String = "https://secure.shippingapis.com/ShippingAPI.dll"
Private Const TestingUrl As String = "https://secure.shippingapis.com/ShippingAPITest.dll"
'For Standard servers (address check, zip code check), use these
Private Const ProductionUrl As String = "http://production.shippingapis.com/ShippingAPI.dll"
Private Const TestingUrl As String = "http://testing.shippingapis.com/ShippingAPITest.dll"
Also, remember to use the: API=DelivConfirmCertifyV3 for testing label while on the production server.
Using these server settings, I'm able to retrieve the xml of the delivery confirmation number as well as the shipping label.
Good luck, tim1198
|
|
|
|
|
Hi,
Please get Address Vertification (Address Verify API) permissions from the USPS. I called the first time and I didn't get it. I asked for it the second time and it was activated. Here is the phone #:
Telephone: 1-800-344-7779 (7:00AM to 11:00PM ET)
Press 3
|
|
|
|
|
I used the above coede and getting "The remote server returned an error: (502) Bad Gateway." error
Pls help me on this
modified on Thursday, February 12, 2009 2:43 AM
|
|
|
|
|