ColdFusion: Get Letter And Postcard Metadata with GetDetails()

Instructions

  1. Make sure your ColdFusion environment is ready and create a new CFM page.
  2. Copy the entire code below and paste the code in the CFM page.
  3. Replace the values of the Const lines with your details:
    • Replace MyUsername and MyPassword with your PostalMethods user details.
    • Replace MyResponseID with a single ID of one of your sent mail items, multiple IDs (ID1,ID2,ID3) or a range of IDs (ID1-ID2)
  4. 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.
  5. <!--- /************* Settings  Begin ****************/ --->
     
    <cfset webserviceUrl = 'https://api.postalmethods.com/2009-02-26/PostalWS.asmx?WSDL'>
    <cfset MyUsername = 'MyUsername'>
    <cfset MyPassword = 'MyPassword'>
    <!---
    	check documentation for GetStatus (http://www.postalmethods.com/method/2009-02-26/GetDetails)
    --->
    <cfset MyResponseID = 'MyResponseID'>
    <!---
    	for more details, check http://www.postalmethods.com/statuscodes#webservice
    	-3000 means successfully received Web Service request
    --->
    <cfset ResultCodeOK = '-3000'>
     
    <!--- /************* Settings  End ******************/ --->
     
    <cfinvoke
    	webservice="#webserviceUrl#"
    	method="GetDetails"
    	returnVariable="GetDetailsResult">
    		<cfinvokeargument name="Username" value="#MyUsername#"/>
    		<cfinvokeargument name="Password" value="#MyPassword#"/>
    		<cfinvokeargument name="Id" value="#MyResponseID#"/>
    </cfinvoke>
     
     
    <!---
    	status_code is the (positive) transaction ID if successful, or a (negative) error number if unsuccessful
    --->
    <cfoutput>
    <cfif GetDetailsResult.getResultCode() eq ResultCodeOK>
     
    	Transaction details for transactions <b>#MyResponseID#</b><br>
     
    	<cfset resultItems = GetDetailsResult.getDetails().getDetails()>
    	<cfloop from="1" to="#ArrayLen( resultItems )#" index="i">
    		<cfset currentItem = resultItems[i]>
     
    		ID:<b>#currentItem.getID()#</b><br>
    		Price:<b>#currentItem.getPrice()#</b><br>
    		NumOfSheets:<b>#currentItem.getNumOfSheets()#</b><br>
    		SubmitTime:<b>#currentItem.getSubmitTime()#</b><br>
    		CompletitonTime:<b>#currentItem.getCompletionTime()#</b><br>
    		Status:<b>#currentItem.getStatus()#</b><br>
    		StatusDescription:<b>#currentItem.getStatusDescription()#</b><br>
    		IsBatch:<b>#currentItem.isIsBatch()#</b><br>
    		MyDescription:<b>#currentItem.getMyDescription()#</b><br>
    		MailerType:<b>#currentItem.getMailerType()#</b><br>
    		WorkMode: <b>#currentItem.getWorkMode()#</b><br>
    		<br>
    	</cfloop>
    <cfelse>
    	GetDetails failed on error <a href="http://www.postalmethods.com/resources/reference/status-codes">#GetDetailsResult.getResultCode()#</a>
    </cfif>
    </cfoutput>