• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1164
  • Last Modified:

UPS API learning to post XML, and retrieving error status from server. Need someone to check code.

I'm trying to figure out how to implement UPS API tools into ASP.NET. I already have Access Key, ID + password from www.ups.com. First of all I would like check authentification status. I have find this code from microsoft.com, and past necessary information.

Server response:
<?xml version="1.0"?>
<ErrorDescription>No Access Identification provided</ErrorDescription>

Open in new window

Code behind:
Imports System
Imports System.IO
Imports System.Net
Imports System.Text
Partial Class _Default
    Inherits System.Web.UI.Page
    Public Sub Main()
        Dim myxml As String = ""
        myxml = "<?xml version=""1.0""?>"
        myxml = "<AccessRequest xml:lang=""en-US"">"
        myxml = "<merchantAuthentication>"
        myxml = "<AccessLicenseNumber>2**************5</AccessLicenseNumber>"
        myxml = "<UserId>A****3</UserId>"
        myxml = "<Password>D******4</Password>"
        myxml = "</AccessRequest>"

            ' Create a request using a URL that can receive a post. 
            Dim request As WebRequest = WebRequest.Create("https://wwwcie.ups.com/ups.app/xml/AV")
            ' Set the Method property of the request to POST.
            request.Method = "POST"
            ' Create POST data and convert it to a byte array.
            Dim postData As String = myxml
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
            ' Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded"
            ' Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length
            ' Get the request stream.
            Dim dataStream As Stream = request.GetRequestStream()
            ' Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length)
            ' Close the Stream object.
            ' Get the response.
            Dim response As WebResponse = request.GetResponse()
            ' Display the status.
            Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
            ' Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            TextBox1.Text = responseFromServer
            ' Clean up the streams.
        Catch ex As Exception
        End Try

    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    End Sub
End Class

Open in new window

Thank you in advance for help!
  • 2
1 Solution
David Johnson, CD, MVPOwnerCommented:
Which API are you using? As there are two parts.. a sent item and a response.


confirm the address is correct.
dejandejanovicAuthor Commented:
Well, all APIs have first request authentification, successful communication with this wwwcie (UPS testing enviroment) server.
So, I have start with just first part of below XML, with  authentification, which I have pickup from ups.com api zip file.
I have also found ups common error descriptions. And, for my error is:
250005 - No Access and Authentication Credentials provided

Do you have any idea what could be wrong?
Did you use your own UPS access key, ID +pass?
Did you use your own code? If yes, is it possible to post here?

Template code:
<?xml version="1.0"?>
<AccessRequest xml:lang="en-US">
<?xml version="1.0"?>
<AddressValidationRequest xml:lang="en-US">
      <CustomerContext>Your Test Case Summary Description</CustomerContext>
    <AddressLine>AIRWAY ROAD SUITE 7</AddressLine>	
    <PoliticalDivision2>SAN DIEGO</PoliticalDivision2>

Open in new window

dejandejanovicAuthor Commented:
I was expect more help here.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now