Froren / realtorca

API wrapper for realtor.ca MLS website
199 stars 76 forks source link

Any authorization required to use this API? #34

Open gajen007 opened 2 years ago

gajen007 commented 2 years ago

Hi, I used the same CURL request what I did this on 2019/2020 as it was worked those times, however, today I got this response. { "ErrorCode": { "Id":400, "Description":"The request was invalid. - Request is not authorized", "LogId":"", "ProductName":"Realtor API 7 (Git) | 20220128.2 | 4054540f0e50864b57025e27f6781cffdc59242c | Friday, January 28, 2022 12:08:03 PM", "Version":"1.0.8063.30858"}, } Is there any authorization required for this? Thanks in advance.

mcgeddes11 commented 2 years ago

From what I can tell they updated the API domain and added some very easily spoofable headers. I think the new domain is: api2.realtor.ca instead of api37.realtor.ca.

The headers that I used for the search request are: {"Referer": "https://www.realtor.ca/", "Origin": "https://www.realtor.ca/", "Host": "api2.realtor.ca"}

I haven't tested the listing details endpoint, but this seems to work for me

gajen007 commented 2 years ago

Thanks @mcgeddes11 I'm using PHP curl request for that API Call. Could you show a sample API call you are using regardless the language? Thanks in advance.

mcgeddes11 commented 2 years ago

Python sample below

import requests, json
form = {
"LongitudeMin": -123.524944,
"LongitudeMax": -123.332315,
"LatitudeMin": 48.424997,
"LatitudeMax": 48.488415,
"PriceMin": 0,
"PriceMax": 3000000,
"RecordsPerPage": 500,
"CultureId": 1,
"ApplicationId": 1}
url = "https://api2.realtor.ca/Listing.svc/PropertySearch_Post"
headers = {"Referer": "https://www.realtor.ca/",
           "Origin": "https://www.realtor.ca/",
           "Host": "api2.realtor.ca"}
response = requests.post(url=url, headers=headers, data=form)
response.raise_for_status()
print(json.dumps(response.json(), indent=2))
gajen007 commented 2 years ago

@mcgeddes11 : IT IS WORKING..! Thanks a lot my friend..! Here my PHP Code...! $API_URL = 'https://api2.realtor.ca/Listing.svc/PropertySearch_Post'; $ch = curl_init(); $dataArray = array( 'CultureId'=>1, 'ApplicationId'=>1, 'PropertySearchTypeId'=>'1', 'TransactionTypeId'=>'1', 'RecordsPerPage'=>'200', 'SortBy'=>'6', 'SortOrder'=>'D', 'LatitudeMax'=>$maxLatitude, 'LongitudeMax'=>$maxLongitude, 'LatitudeMin'=>$minLatitude, 'LongitudeMin'=>$minLongitude, 'PriceMin'=>'0', 'PriceMax'=>'3000000' ); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Referer:https://www.realtor.ca/','Origin:https://www.realtor.ca/','Host:api2.realtor.ca')); $data=http_build_query($dataArray); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_URL, $API_URL); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, true); $serverResponse=curl_exec($ch); curl_close($ch); $jsonObject=json_decode($serverResponse);