asp asp.net usps print label

Webboy2008
Webboy2008 used Ask the Experts™
on
I have the following codes.
the goal is to call USPS services to print get confirmation number
and print the shipping label.

It does not show any err description so I have no idea what to do ...any one can help?

Function PrintUspsLabel()
sXML ="<DeliveryConfirmationV3.0Request USERID=""" & sUSPSUserID & """>"
sXML = sXML & "<Option>1</Option>"
sXML = sXML & "<ImageParameters />"
sXML = sXML & "<FromName>John Smith</FromName>"
sXML = sXML & "<FromFirm />"
sXML = sXML & "<FromAddress1 />"
sXML = sXML & "<FromAddress2>475 L'Enfant Plaza, SW</FromAddress2>"
sXML = sXML & "<FromCity>Washington</FromCity>"
sXML = sXML & "<FromState>DC</FromState>"
sXML = sXML & "<FromZip5>20260</FromZip5>"
sXML = sXML & "<FromZip4 />"
sXML = sXML & "<ToName>Joe Customer</ToName>"
sXML = sXML & "<ToFirm />"
sXML = sXML & "<ToAddress1>STE 201</ToAddress1>"
sXML = sXML & "<ToAddress2>6060 PRIMACY PKWY</ToAddress2>"
sXML = sXML & "<ToCity>MEMPHIS</ToCity>"
sXML = sXML & "<ToState>TN</ToState>"
sXML = sXML & "<ToZip5 />"
sXML = sXML & "<ToZip4 />"
sXML = sXML & "<WeightInOunces>2</WeightInOunces>"
sXML = sXML & "<ServiceType>Priority</ServiceType>"
sXML = sXML & "<POZipCode />"
sXML = sXML & "<ImageType>TIF</ImageType>"
sXML = sXML & "<LabelDate />"
sXML = sXML & "</DeliveryConfirmationV3.0Request>"
sUSPSLabelXmL=sXML  

 Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
  ' Production Server = http://production.shippingapis.com/ShippingAPI.dll?
  ' Test Server = http://testing.shippingapis.com/ShippingAPITest.dll?
  oXMLHTTP.Open "Get","http://testing.shippingapis.com/ShippingAPITest.dll?" & sUSPSLabelXmL,false
  oXMLHTTP.setRequestHeader "Content-Type", "text/xml"
  On Error Resume Next
  oXMLHTTP.send ""
  response.Write err.Description & "<br><br>"
   response.Write "Error Description: " & err.Description & "<br><br>"
  response.Write "Error Total Count: " & err.number & "<br><br>"
  GetUSPSXMLlabel = oXMLHTTP.responseText
  '==================================================================
  'response value
  Set oUSPSXML=Server.CreateObject("Microsoft.xmlDOM")
      oUSPSXML.loadxml(GetUSPSXMLlabel)
     ' oUSPSXML.getElementsByTagName("Postage")
      Set oUSPSLabel = oUSPSXML.getElementsByTagName("DeliveryConfirmationV3.0Response")
      For x = 0 To oUSPSLabel.length - 1
            sDisplayString =sDisplayString & oUSPSLabel.Item(x).selectSingleNode("DeliveryConfirmationNumber").Text
      Next
      response.Write "Confirmation Number: " &  sDisplayString 
  '==================================================================    
    
     
End Function

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Hi,

I tested your asp.
And I think there is no error.
But testing.shippingapis.com returns null.

Author

Commented:
Have you tried to put different shipping address?

Commented:
I created an account and tried it. Even looking at their documentation (ignoring your code for now) I was not able to get this to work.

From what I can tell, the test server is always broken in some why or another.  Have you already had your account upgraded to be able to use production?  If so, please try using that.  However, note that you need to use https for delivery confirmation, and also that you should be passing an API as part of the query string (and you should also be passing XML, which you aren't).

Line 32 should look like this:
oXMLHTTP.Open "GET","https://secure.shippingapis.com/ShippingAPI.dll?API=DeliveryConfirmationV3&XML=" & sUSPSLabelXmL,false
HTML5 and CSS3 Fundamentals

Build a website from the ground up by first learning the fundamentals of HTML5 and CSS3, the two popular programming languages used to present content online. HTML deals with fonts, colors, graphics, and hyperlinks, while CSS describes how HTML elements are to be displayed.

Author

Commented:
Thank for your helps. I just called and switch everything to production. and also corrected some of codes based on your suggestions, but it is till not working...:-(

I also tried to put https but the error shown invalid url, so I put http back instead.

No wonder why.
Function PrintUspsLabel()
sXML ="API=DeliveryConfirmationV3&XML="
sXML = sXML & "<DeliveryConfirmationV3.0Request USERID=""" & sUSPSUserID & """>"
sXML = sXML & "<Option>1</Option>"
sXML = sXML & "<ImageParameters />"
sXML = sXML & "<FromName>John Smith</FromName>"
sXML = sXML & "<FromFirm />"
sXML = sXML & "<FromAddress1>100 Main Street.</FromAddress1>"
sXML = sXML & "<FromAddress2>Suite 100</FromAddress2>"
sXML = sXML & "<FromCity>Los Angeles</FromCity>"
sXML = sXML & "<FromState>CA</FromState>"
sXML = sXML & "<FromZip5>90032</FromZip5>"
sXML = sXML & "<FromZip4 />"
sXML = sXML & "<ToName>Joe Customer</ToName>"
sXML = sXML & "<ToFirm />"
sXML = sXML & "<ToAddress1>9000 Airport blvd.</ToAddress1>"
sXML = sXML & "<ToAddress2></ToAddress2>"
sXML = sXML & "<ToCity>Los Angeles</ToCity>"
sXML = sXML & "<ToState>CA</ToState>"
sXML = sXML & "<ToZip4>90045</ToZip4>"
sXML = sXML & "<ToZip5 />"
sXML = sXML & "<WeightInOunces>2</WeightInOunces>"
sXML = sXML & "<ServiceType>Priority</ServiceType>"
sXML = sXML & "<POZipCode />"
sXML = sXML & "<ImageType>TIF</ImageType>"
sXML = sXML & "<LabelDate />"
sXML = sXML & "</DeliveryConfirmationV3.0Request>"
sUSPSLabelXmL=sXML  

 Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
  ' Production Server = http://production.shippingapis.com/ShippingAPI.dll?
  ' Test Server = http://testing.shippingapis.com/ShippingAPITest.dll?
  oXMLHTTP.Open "Get","http://production.shippingapis.com/ShippingAPI.dll?" & sUSPSLabelXmL,false
  oXMLHTTP.setRequestHeader "Content-Type", "text/xml"
  On Error Resume Next
  oXMLHTTP.send ""
  response.Write err.Description & "<br><br>"
  response.Write "Error Description: " & err.Description & "<br><br>"
  response.Write "Error Total Count: " & err.number & "<br><br>"
  GetUSPSXMLlabel = oXMLHTTP.responseText
  '==================================================================
  'response value
  Set oUSPSXML=Server.CreateObject("Microsoft.xmlDOM")
      oUSPSXML.loadxml(GetUSPSXMLlabel)
     ' oUSPSXML.getElementsByTagName("Postage")
      Set oUSPSLabel = oUSPSXML.getElementsByTagName("DeliveryConfirmationV3.0Response")
      For x = 0 To oUSPSLabel.length - 1
            sDisplayString =sDisplayString & oUSPSLabel.Item(x).selectSingleNode("DeliveryConfirmationNumber").Text
      Next
      response.Write "Confirmation Number: " &  sDisplayString 
  '================================================================== 
  
  End Function 

Open in new window

Commented:
There was more to the change in url than just adding https.  You have to use https://secure.shippingapis.com.  The DeliveryConfirmationV3 request cannot be preformed over an unsecure connection.  What do you mean that it is not working?

Also, I see no reason to set the content-type since you are not sending any content.

Author

Commented:
When I add "s"
oXMLHTTP.Open "Get","https://production.shippingapis.com/ShippingAPI.dll?" & sUSPSLabelXmL,false

I see the following error message.

A connection with the server could not be established

Error Description: A connection with the server could not be established

Error Total Count: -2147012867

Confirmation Number:

Author

Commented:
If I added url
 oXMLHTTP.Open "Get","https://secure.shippingapis.com" & sUSPSLabelXmL,false
I have the following error.

msxml3.dll error '80072ee5'

The URL is invalid

/usps/uspsfunctions.asp, line 72

Commented:
You still have to include the ShippingAPI.dll and the question mark, so it would be:

oXMLHTTP.Open "GET","https://secure.shippingapis.com/ShippingAPI.dll?" & sUSPSLabelXmL,false

Author

Commented:
I added it. but all I see is as follow. It returns nothing

Error Description:

Error Total Count: 0

Confirmation Number:

Commented:
Add:
Response.Write GetUSPSXMLlabel

And post what the result is.

Author

Commented:
I added the Response.Write GetUSPSXMLlabel, and still blank.

In addition, I modified the xml body based on the usps web doc
http://www.usps.com/webtools/htm/Delivery-Confirmation1.htm 
(Find: 3.3      Run Sample Requests). You can see the structure in xml request.
Function PrintUspsLabel()
sXML ="API=DeliveryConfirmationV3&XML="
sXML = sXML & "<DeliveryConfirmationV3.0Request USERID=""" & sUSPSUserID & """>"
sXML = sXML & "<Option>1</Option>"
sXML = sXML & "<ImageParameters />"
sXML = sXML & "<FromName>John Smith</FromName>"
sXML = sXML & "<FromFirm />"
sXML = sXML & "<FromAddress1>Suite 100</FromAddress1>"
sXML = sXML & "<FromAddress2>100 Main Street</FromAddress2>"
sXML = sXML & "<FromCity>Los Angeles</FromCity>"
sXML = sXML & "<FromState>CA</FromState>"
sXML = sXML & "<FromZip5>90032</FromZip5>"
sXML = sXML & "<FromZip4 />"
sXML = sXML & "<ToName>Joe Customer</ToName>"
sXML = sXML & "<ToFirm />"
sXML = sXML & "<ToAddress1></ToAddress1>"
sXML = sXML & "<ToAddress2>9000 Airport blvd</ToAddress2>"
sXML = sXML & "<ToCity>Los Angeles</ToCity>"
sXML = sXML & "<ToState>CA</ToState>"
sXML = sXML & "<ToZip5>90045</ToZip5>"
sXML = sXML & "<ToZip4></ToZip4>"
sXML = sXML & "<WeightInOunces>32</WeightInOunces>"
sXML = sXML & "<ServiceType>Priority</ServiceType>"
sXML = sXML & "<SeparateReceiptPage>False</SeparateReceiptPage>"
sXML = sXML & "<POZipCode />"
sXML = sXML & "<ImageType>TIF</ImageType>"
sXML = sXML & "<LabelDate />"
sXML = sXML & "<CustomerRefNo />"
sXML = sXML & "<AddressServiceRequested />"
sXML = sXML & "<SenderName />"
sXML = sXML & "<SenderEMail />"
sXML = sXML & "<RecipientName />"
sXML = sXML & "<RecipientEMail />"
sXML = sXML & "</DeliveryConfirmationV3.0Request>"
sUSPSLabelXmL=sXML  

 Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
  oXMLHTTP.Open "Get","https://secure.shippingapis.com/ShippingAPI.dll" & sUSPSLabelXmL,false
  oXMLHTTP.setRequestHeader "Content-Type", "text/xml"
  On Error Resume Next
  oXMLHTTP.send ""
  response.Write err.Description & "<br><br>"
  response.Write "Error Description: " & err.Description & "<br><br>"
  response.Write "Error Total Count: " & err.number & "<br><br>"
  GetUSPSXMLlabel = oXMLHTTP.responseText
  '==================================================================
  'response value
  Set oUSPSXML=Server.CreateObject("Microsoft.xmlDOM")
      oUSPSXML.loadxml(GetUSPSXMLlabel)
     ' oUSPSXML.getElementsByTagName("Postage")
      Set oUSPSLabel = oUSPSXML.getElementsByTagName("DeliveryConfirmationV3.0Response")
      For x = 0 To oUSPSLabel.length - 1
            sDisplayString =sDisplayString & oUSPSLabel.Item(x).selectSingleNode("DeliveryConfirmationNumber").Text
      Next
      response.Write "Confirmation Number: " &  sDisplayString 
      response.Write "<br><br>"
      Response.Write "XML Label: " & GetUSPSXMLlabel

  '================================================================== 
 End Function 

Open in new window

Commented:
Perhaps take "on error resume next" out.
And take out the setRequestHeader "Content-Type", "text/xml".   That is only used for POST (not GET).

Author

Commented:
Still blank
Function PrintUspsLabel()
sXML ="API=DeliveryConfirmationV3&XML="
sXML = sXML & "<DeliveryConfirmationV3.0Request USERID=""" & sUSPSUserID & """>"
sXML = sXML & "<Option>1</Option>"
sXML = sXML & "<ImageParameters />"
sXML = sXML & "<FromName>John Smith</FromName>"
sXML = sXML & "<FromFirm />"
sXML = sXML & "<FromAddress1>Suite 100</FromAddress1>"
sXML = sXML & "<FromAddress2>100 Main Street</FromAddress2>"
sXML = sXML & "<FromCity>Los Angeles</FromCity>"
sXML = sXML & "<FromState>CA</FromState>"
sXML = sXML & "<FromZip5>90032</FromZip5>"
sXML = sXML & "<FromZip4 />"
sXML = sXML & "<ToName>Joe Customer</ToName>"
sXML = sXML & "<ToFirm />"
sXML = sXML & "<ToAddress1></ToAddress1>"
sXML = sXML & "<ToAddress2>9000 Airport blvd</ToAddress2>"
sXML = sXML & "<ToCity>Los Angeles</ToCity>"
sXML = sXML & "<ToState>CA</ToState>"
sXML = sXML & "<ToZip5>90045</ToZip5>"
sXML = sXML & "<ToZip4></ToZip4>"
sXML = sXML & "<WeightInOunces>32</WeightInOunces>"
sXML = sXML & "<ServiceType>Priority</ServiceType>"
sXML = sXML & "<SeparateReceiptPage>False</SeparateReceiptPage>"
sXML = sXML & "<POZipCode />"
sXML = sXML & "<ImageType>TIF</ImageType>"
sXML = sXML & "<LabelDate />"
sXML = sXML & "<CustomerRefNo />"
sXML = sXML & "<AddressServiceRequested />"
sXML = sXML & "<SenderName />"
sXML = sXML & "<SenderEMail />"
sXML = sXML & "<RecipientName />"
sXML = sXML & "<RecipientEMail />"
sXML = sXML & "</DeliveryConfirmationV3.0Request>"
sUSPSLabelXmL=sXML  

 Set oXMLHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
  oXMLHTTP.Open "Post","https://secure.shippingapis.com/ShippingAPI.dll" & sUSPSLabelXmL,false
  'oXMLHTTP.setRequestHeader "Content-Type", "text/xml" 
  'On Error Resume Next
  oXMLHTTP.send ""
  response.Write err.Description & "<br><br>"
  response.Write "Error Description: " & err.Description & "<br><br>"
  response.Write "Error Total Count: " & err.number & "<br><br>"
  GetUSPSXMLlabel = oXMLHTTP.responseText
  '==================================================================
  'response value
  Set oUSPSXML=Server.CreateObject("Microsoft.xmlDOM")
      oUSPSXML.loadxml(GetUSPSXMLlabel)
     ' oUSPSXML.getElementsByTagName("Postage")
      Set oUSPSLabel = oUSPSXML.getElementsByTagName("DeliveryConfirmationV3.0Response")
      For x = 0 To oUSPSLabel.length - 1
            sDisplayString =sDisplayString & oUSPSLabel.Item(x).selectSingleNode("DeliveryConfirmationNumber").Text
      Next
      response.Write "Confirmation Number: " &  sDisplayString 
      response.Write "<br><br>"
      Response.Write "XML Label: " & GetUSPSXMLlabel

  '================================================================== 
 End Function

Open in new window

Commented:
1) Why did you switch to POST?
2) What happened to the question mark at the end of the url?

I really need you to read my posts more closely.  I have provided the exact text you need for line 38 several times now.

Author

Commented:
I switched. I believe it is miscommunicated...
After switch, it returns something. I believe I need to call usps, and then continue. Agree?

XML Label: 80040b1a API Authorization failure. User 913RNYGR4533 is not authorized to use API DeliveryConfirmationV3. UspsCom::DoAuth

Commented:
Yes, I had the same issue.  I searched the internet for a USERID that worked so that I could test it, but you will need to get yours working if you want to do it the "right way".

Author

Commented:
I called and operator helped me immediately to open the acct.

I I got it working and having confirmation no. 420900459101969010386827874474
and a xml string. Thanks!

Now the issue is: how can I take the longggggg string and convert into gif/pdf and print in the browser.

Another side question. Once it is generated, how do i pay for the label as a buyer? assuming I have some sort of shopping cart - backend office system.


Commented:
You already have that question open elsewhere.

And I have no idea how to pay for the label.

Author

Commented:
Thanks.

I am going to point you now since you already helped me alotttt and I do appreicate your time and help.
If you have extra time, you are welcome to answer another question.

Author

Commented:
Very helpful guy for this usps issue.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial