I finally started thinking about what I was really trying to do with this
USPS EMR label. I was looking the answer in the face. I send USPS an xml
request, retrieve an xml answer with the mailing label enclosed as a base64
encoded pdf format. So, extract the pdf string, tostring() to unpack it,
write it to a file as a binary. Pretty simple once you think of the answer.
lol.

In case anyone requires a starting place for this sort of thing in the
future:


<!----------- start of example code to request, retrieve and write an
Electronic Merchandise Return mailing label from USPS  Web Tool Kit
services------------------------>
<!---- this is one of their canned requests with barcode ----->

<cfscript>
request="<EMRSV2.0Request USERID='USERID' PASSWORD='PASSWORD'>";
request=request & "<CustomerName>John Smith</CustomerName>";
request=request & "<CustomerAddress>6406 Ivy Lane</CustomerAddress>";
request=request & "<CustomerCity>Greenbelt</CustomerCity>";
request=request & "<CustomerState>MD</CustomerState>";
request=request & "<CustomerZip5>20770</CustomerZip5>";
request=request & "<RetailerName>XYZ Corp.</RetailerName>";
request=request & "<RetailerAddress>1125 5th Avenue</RetailerAddress>";
request=request & "<PermitNumber>987654321</PermitNumber>";
request=request & "<PermitIssuingPOCity>New York</PermitIssuingPOCity>";
request=request & "<PermitIssuingPOState>NY</PermitIssuingPOState>";
request=request & "<PermitIssuingPOZip5>10128</PermitIssuingPOZip5>";
request=request & "<PDUPOBox>48374</PDUPOBox>";
request=request & "<PDUCity>New York</PDUCity>";
request=request & "<PDUState>NY</PDUState>";
request=request & "<PDUZip5>10128</PDUZip5>";
request=request & "<PDUZip4>0143</PDUZip4>";
request=request & "<ServiceType>Parcel Post</ServiceType>";
request=request & "<DeliveryConfirmation>False</DeliveryConfirmation>";
request=request & "<InsuranceValue>50</InsuranceValue>";
request=request & "<MailingAckPackageID>1234</MailingAckPackageID>";
request=request & "<WeightInPounds>10</WeightInPounds>";
request=request & "<WeightInOunces>8</WeightInOunces>";
request=request & "<RMA>987654321</RMA>";
request=request & "<ImageType>PDF</ImageType>";
request=request & "<RMABarcode>TRUE</RMABarcode>";
request=request & "</EMRSV2.0Request>";
</cfscript>

<!--- send the request ----->
<cfhttp
url="http://testing.shippingapis.com/ShippingAPITest.dll?API=MerchandiseRetu
rnV2&XML=#urlencodedformat(request)#" method="get" resolveurl="false"
timeout="45">
</cfhttp>

<!--- dissect out the encoded pdf data. this is crude, but it works. ---->
<cfset startstr = "<MerchandiseReturnLabel>">
<cfset endstr = "</MerchandiseReturnLabel>">
<cfset pos1 = #FindNoCase(startstr,cfhttp.filecontent)# + 24><!--- add in
length of tag ---->
<cfset pos2 = #FindNoCase(endstr,cfhttp.filecontent)#>
<!--- grab our label, base64 encoded ---->
<cfset pdfile = #Mid(cfhttp.filecontent,pos1,pos2-pos1)#>

<!---- unpack the label ---->
<cfset spdfile=#tostring(pdfile)#>

<!---- write the label to a file as a binary ----->
<cffile
        action="write"
        file="/home/httpd/html/wherever/pdf1.pdf"
        output="#tobinary(spdfile)#"
        mode="777">

<a href="http://yoursite.com/wherever/pdf1.pdf";>View label</a>

<!----------- end of example------------------------>
______________________________________________________________________
Get Your Own Dedicated Windows 2000 Server
  PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER
  Instant Activation � $99/Month � Free Setup
  http://www.pennyhost.com/redirect.cfm?adcode=coldfusionb
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to