First time here? Check out the FAQ!
0

Unauthorized Query in PhRETS

date_default_timezone_set('America/New_York');

require_once("vendor/autoload.php");

$config = new \PHRETS\Configuration; $config->setLoginUrl("http://rebrae.retsiq.com/contact/rets/login";) ->setUsername("eroomvie") ->setPassword("*") ->setUserAgent("RoomView/1.0") ->setUserAgentpassword("****") ->setRetsVersion('1.7.2');

$rets = new \PHRETS\Session($config);

$connect = $rets->Login();

$system = $rets->GetSystemMetadata(); var_dump($system);

$results = $rets->Search('Property', 'RESIDENTIAL', '(L_Status=1_0)', ['Limit' => 20, "offset" => 1]); foreach ($results as $r) { var_dump($r); }

?>

———————————— Code End —————————————

the output of this code with error is as follows —

————————— Ouput Start —————————————— /Users/vivek/Sites/temp/rets/test.php:36: class PHRETS\Models\Metadata\System#29 (4) { protected $elements => array(5) { [0] => string(8) "SystemID" [1] => string(17) "SystemDescription" [2] => string(14) "TimeZoneOffset" [3] => string(8) "Comments" [4] => string(7) "Version" } protected $session => class PHRETS\Session#2 (8) { protected $configuration => class PHRETS\Configuration#3 (9) { protected $username => string(8) "eroomvie" protected $password => string(8) "*" protected $login_url => string(43) "http://rebrae.retsiq.com/contact/rets/login"; protected $user_agent => string(12) "RoomView/1.0" protected $user_agent_password => string(17) "*****" protected $rets_version => class PHRETS\Versions\RETSVersion#4 (2) { ... } protected $http_authentication => string(6) "digest" protected $strategy => class PHRETS\Strategies\StandardStrategy#34 (2) { ... } protected $options => array(0) { ... } } protected $capabilities => class PHRETS\Capabilities#19 (1) { protected $capabilities => array(6) { ... } } protected $client => class GuzzleHttp\Client#5 (1) { private $config => array(7) { ... } } protected $logger => NULL protected $rets_session_id => string(38) "-f5b85d52-54b8-4e7e-b154-f84ddcb1045c-" protected $cookie_jar => class GuzzleHttp\Cookie\CookieJar#18 (2) { private $cookies => array(0) { ... } private $strictMode => bool(false) } protected $last_request_url => string(98) "http://rebrae.retsiq.com:80/contact/rets/getmetadata?Type=METADATA-SYSTEM&ID=0&Format=STANDARD-XML"; protected $last_response => class PHRETS\Http\Response#57 (1) { protected $response => class GuzzleHttp\Psr7\Response#54 (6) { ... } } } protected $attributes => array(0) { } protected $values => array(5) { 'SystemID' => string(3) "RAE" 'SystemDescription' => string(34) "REALTORS® Association of Edmonton" 'TimeZoneOffset' => string(1) "Z" 'Comments' => string(0) "" 'Version' => string(10) "19.6.37528" } } PHP Fatal error: Uncaught PHRETS\Exceptions\RETSException: Unauthorized Query in /Users/vivek/Sites/temp/rets/vendor/troydavisson/phrets/src/Session.php:426 Stack trace:

0 /Users/vivek/Sites/temp/rets/vendor/troydavisson/phrets/src/Session.php(280): PHRETS\Session->request('Search', Array)

1 /Users/vivek/Sites/temp/rets/test.php(51): PHRETS\Session->Search('Property', 'RESIDENTIAL', '(L_Status=1_0)', Array)

2 {main}

thrown in /Users/vivek/Sites/temp/rets/vendor/troydavisson/phrets/src/Session.php on line 426

Fatal error: Uncaught PHRETS\Exceptions\RETSException: Unauthorized Query in /Users/vivek/Sites/temp/rets/vendor/troydavisson/phrets/src/Session.php on line 426

PHRETS\Exceptions\RETSException: Unauthorized Query in /Users/vivek/Sites/temp/rets/vendor/troydavisson/phrets/src/Session.php on line 426

Call Stack: 0.0008 359448 1. {main}() /Users/vivek/Sites/temp/rets/test.php:0 0.7909 2204640 2. PHRETS\Session->Search() /Users/vivek/Sites/temp/rets/test.php:51 0.7917 2207992 3. PHRETS\Session->request() /Users/vivek/Sites/temp/rets/vendor/troydavisson/phrets/src/Session.php:280 ————————— Output End ———————————————

vanderbleeka's avatar
vanderbleeka
asked 2019-07-15 12:18:59 -0500
bwolven's avatar
bwolven
updated 2019-07-16 13:51:05 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

2 Answers

0

Remove the semicolon in setLoginUrl() call
Add: $config->setOption('use_post_method', true); after config setting.
Change the class in the search from "RESIDENTIAL" to "RE_1".
For some reason it doesn't seem to like it unless post is set.

Wrapping the search request like this seems to work correctly.
$config->setOption('use_post_method', true);
$results = $rets->Search('Property', 'RESIDENTIAL', '(L_Status=1_0)', ['Limit' => 20, "offset" => 1]);
$config->setOption('use_post_method', false);

The reason this happens is that even though the search isn't passing a 'Select' parameter, the RETSIQ proxy does pass one with the fields you are allowed access to.
The RETSIQ Select causes it to exceed the maximum Query string length unless it is sent using POST.
Which is why it succeeds if you pass your own, shorter Select parameter in.

Make sure to logout of the session when you are finished using it too.

It is done like this in PHRETS:
$rets->Disconnect();

bwolven's avatar
bwolven
answered 2019-07-15 15:56:25 -0500, updated 2019-07-16 13:56:38 -0500
edit flag offensive 0 remove flag delete link

Comments

add a comment see more comments

Your Answer

Login/Signup to Answer