ASP: Get The Status Of A Letter with GetLetterStatusV2()


  1. Create a new ASP page
  2. Copy the entire code below paste the code inside the ASP page.
  3. Replace MyUsername and MyPassword with your PostalMethods user details.
  4. Replace ID with the LetterID for which you would like to get the status.
  5. Start your application. If the response is -3000, you will see the status report. If the response is any other number, check the Web Service Status Codes section.
' This asp script demonstrates how to obtain the status of a Letter, using MS SOAP 3.0
' and the GetLetterStatusV2() method within PostalMethods. 
Option Explicit 
Const MyUsername = "MyUsername"
Const MyPassword = "MyUsername"
' Replace with the LetterID of the Letter, as returned by the sending method, such as SendLetterV2()
Const LetterID=ID
Dim objSoap, objResult, ResultCode, Status, Description, LastUpdateTime
Dim i
'Create the SoapClient object    'MS SOAP v3.0
Set objSoap = Server.CreateObject("MSSOAP.SOAPClient30")
'Set to True when an Active Server Pages (ASP) application or an ISAPI DLL uses the SoapClient object.
objSoap.ClientProperty("ServerHTTPRequest") = True 
'Initializes the SoapClient object. ASP initializes the WSDL on each call. 
'For better performance, you may download the WSDL locally as an XML and refer to the local file.
'Set to True when a proxy server is to be detected automatically
objSoap.ConnectorProperty("EnableAutoProxy") = True
' Invoke the GetLetterStatusV2 method
' The data returned by the method is an object of type XML Nodelist
' For that reason, we use "Set objResult =  ..." and not a simple assignment
Set objResult = objSoap.GetLetterStatusV2( _
						MyUsername, _
						MyPassword, _
' The returned Node list is a representation of the following portion in the WSDL:
'   <GetLetterStatusV2Result>
'     <ResultCode>int</ResultCode>
'     <Status>int</Status>
'     <Description>string</Description>
'     <LastUpdateTime>dateTime</LastUpdateTime>
'   </GetLetterStatusV2Result>
' Parsing this in asp (vbs) is tricky, but possible
For i = 0 To objResult.length-1
	' The following line will display the actual results in the XML node list (comment out to activate)
	' response.write objResult.item(i).TagName & "=" & objResult.item(i).Text & "<BR>"
	' this will assign the value of each XML node to a local variable
	Select Case objResult.item(i).TagName
		Case "ResultCode"
			ResultCode = CLng(objResult.item(i).Text)
		Case "Status"
			Status = CLng(objResult.item(i).Text)
		Case "Description"
			Description = objResult.item(i).Text
		Case "LastUpdateTime"
			LastUpdateTime = GetDateTime(objResult.item(i).Text)
	End Select
If ResultCode = -3000 Then 
	' -3000 means the request was successfully marked for cancellation.
	Response.Write "Status=" & Status & "<BR>"
	Response.Write "LastUpdateTime=" & LastUpdateTime & "<BR>"
	' A value less than -3000 means an error occurred.
	' See the PostalMethods Status Codes:
    Response.Write "Error is: " & ResultCode & "<BR>"
End If
Response.Write "Description: " & Description
Function GetDateTime(S)
' This utility method will convert the SOAP format of the DateTime 
' to a format that can be easily parsed by VBS.
	Dim DT : DT = Replace(S,"T"," ")
	GetDateTime = CDate(DT)
End function