Sunday, September 28, 2008

Coldfusion RETS Authentication

As I mentioned in an earlier post, when my client signed up for RETS access the MLS sent them essentially only three bits of information, the username, password and login url. This is just about all we need. I setup application vars for the username and password. Here is the rather simple login code.


        <cfhttpparam name="Accept" type="header" value="text/xml,text/plain;q=0.5">
        <cfhttpparam name="User-Agent" type="header" value="Mozilla/4.0">
        <cfhttpparam name="RETS-Version" type="header" value="RETS/1.5">
<cfset application.RetsCookie = cfhttp.Responseheader["Set-Cookie"]> 

Nothing to fancy here, as per the RETS 1.5 Specification I set the required ACCEPT value to allow for xml or text, and the the q=0.5 is a response quality value between 0 and 1. Don't really know much about that yet, but seems to be the accepted value to pass. User-Agent is for server logging, but required. RETS-Version was a little tricky, seems different servers like that in different format, this one works for me (I have seen other comments using the format "RETS_1_5"). Note that I am setting the returned cookie to the application (maybe set to the session for a production application), this is critical, you will need to pass that value with all of your requests to maintain you session on the server. Dumping the cfhttp.filecontent should get you something like this...
Note that the filecontent contains the path to the other resources on the server such as Search, GetMetadata, Logout and GetObject. The returned Set-Cookie struct has a JSESSIONID, we will pass that entire string back with each future request. Well, we are logged in, now it is time to find out what we can do and what the schema is. For this, we need the MetaData...


Anonymous said...

The RETS_1_5 is a constant in libRETS. The person you saw posting that was a bit confused about what they are doing.

Per the RETS spec, what must be the version is very clear.

jones said...

Nice blog...
visit also coldfusion example