mike.jackson

error when assigning alarm to user via SOAP

Discussion created by mike.jackson on Aug 19, 2009
Latest reply on Sep 24, 2009 by andrew.tranquada
I'm working on a web app using the web services API from PHP. It will pull in a list of alarms, show the ones that are unassigned, and allow you to assign the alarm. The alarm-pulling works fine, but I'm having issues setting the user. Here's the code I'm using:
<?php
        define('NIMBUS_USERNAME','');
        define('NIMBUS_PASSWORD','');

        $rightnow = time();
        $cookie= '';
        try {
                // Authenticate with NimBUS
                $client = new SoapClient('http://web1.web.dfw.mlsrvr.com/NimBUS/webservice/User.asmx?WSDL', array('trace' => true, 'exceptions' => true));
                $res = $client->Login(array('user' => NIMBUS_USERNAME, 'password' => NIMBUS_PASSWORD, 'encrypted' => '0'));
                if(preg_match("/Set-Cookie: ASP.NET_SessionId=(+);/s",$client->__getLastResponseHeaders(),$matches)) {
                        $cookie = $matches;
                        $client->__setCookie('ASP.NET_SessionId',$cookie);
                }
        } catch (Exception $e) {
                echo "<p><b class=\"error\">Could not authenticate with NimBUS.</b></p>\n<!-- " . htmlspecialchars($e) . " -->\n";
        }
        if(isset($cookie) && !empty($cookie)) {
                try {
                        $client = new SoapClient('http://web1.web.dfw.mlsrvr.com/NimBUS/webservice/Alarm.asmx?WSDL', array('trace' => true, 'exceptions' => true));
                        $client->__setCookie('ASP.NET_SessionId',$cookie);
                        $res = $client->AssignAlarmToUser('Working','VY43880997-69230');
                        print_r($res);
                } catch (Exception $e) {
                        echo "<p><b class=\"error\">There was an error pulling alarms from NimBUS</b></p>\n<!-- " . htmlspecialchars($e) . " -->\n";
                }
        }
?>

I get this error:

$ php nimbus.show
<p><b class="error">There was an error pulling alarms from NimBUS</b></p>
<!-- SoapFault exception:  Failed to assign alarm. ---> Object reference not set to an instance of an object. in /home/mjackson/nimbus.show:22
Stack trace:
#0 : SoapClient->__call('AssignAlarmToUs...', Array)
#1 /home/mjackson/nimbus.show(22): SoapClient->AssignAlarmToUser('Working', 'VY43880997-6923...')
#2 {main} -->
The "Working" user exists, and the alarm ID is a current alarm not assigned to a user. What am I doing wrong?

Also, is there a better way to authenticate? I found that way by trial and error, and it works, but it sure is ugly. The web services API could certainly use some better documentation!

Outcomes