Error Logs & Triggers

Talk with others about developing applications for Switchvox

Moderators: bmdhacks, dpodolsky, tristand, jwitt, joshuas

Error Logs & Triggers

Postby KKiernan » Tue May 15, 2012 8:59 am

When using triggers, I am seeing these errors in the switchvox errors logs. Any ideas what this could be? I've included my PHP code, which is interacting with other APIs as well so it may seem a bit convoluted.

Error in XML from remote url (process_xml_response): [http://192.168.0.80/switchboard/prototype/php/build_current_calls_xml.php] line Fatal Error XMLin err=junk after document element at line 2, column 0, byte 7 , column %4.


My PHP file:

Code: Select all
<?php

/*   ###################################
   #
   #   B U I L D    X M L    F I L E
   #
   ################################### */
   
   // Include required files
   include('xml_template.php');
   include('autotask_connect.php');
   
   // Format phone number to match Autotask (XXX) XXX-XXXX
   function formatNumber($num)
   {
      if (strlen($num) > 3)
      {
         $a = '(' .  substr($num,0,3) . ') ';
         $b = substr($num,3,3) . '-';
         $c = substr($num,6,4);
         $formatted = $a . $b . $c;
         return $formatted;
      }
      else
      {
         return $num;
      }
   }

   // XML request
   $request = '
      <request method="switchvox.currentCalls.getList">
         <parameters>
         </parameters>
      </request>
   ';
   
   // Create a new cURL resource
   $ch = curl_init();
   
   // Set options
   curl_setopt($ch, CURLOPT_URL, 'https://switchboard.orbissolutions.com/xml');
   curl_setopt($ch, CURLOPT_HEADER, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
   curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_DIGEST );
   curl_setopt($ch, CURLOPT_USERPWD, 'admin:orbis!234');
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/xml'));
   curl_setopt($ch, CURLOPT_POST, TRUE);
   curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
   
   // Grab URL and pass it to the browser
   // Store in simple XML element for parsing
   $response = new SimpleXMLElement(curl_exec($ch));
   
   // XML starting point
   $xml = new SimpleXMLElement($xmlstr);
   
   // Build XML file
   foreach ($response->result->current_calls->current_call as $call)
   {   
      // Create current call element
      $currentCall = $xml->addChild('current_call');
      
      // Add properties to current call element
      foreach ($call->attributes() as $attr => $value)
      {
         $currentCall->addChild($attr,$value);
         
                        // Add autotask account id if it exits
         if (($attr == 'to_caller_id_number' && !isset($currentCall->autotask_account_id))  || ($attr == 'from_caller_id_number' && !isset($currentCall->autotask_account_id)))
         {            
            // Format number
            $formattedNumber = formatNumber($value);
               
            // Autotask query for account ID
            $accnt = array('sXML' => "
               <queryxml>
                  <entity>Account</entity>
                     <query>
                        <field>Phone
                           <expression op='equals'>" . $formattedNumber .  "</expression>
                        </field>
                     </query>
               </queryxml>
            ");
            
            // Autotask response
            $response = $client->query($accnt);
            
            // Add phone number to XML         
            if ($response->queryResult->EntityResults->Entity->id)
            {
               $currentCall->addChild('autotask_account_id',$response->queryResult->EntityResults->Entity->id);
            }

         }
      }
      
      // If the autotask_account_id field wasn't created, create it now with an undefined value
      if (!isset($currentCall->autotask_account_id))
      {
         $currentCall->addChild('autotask_account_id');
      }
   }

   // Write response to file
   $xmlDoc = 'xml_response.xml';
   $a = fopen($xmlDoc, 'w');
   fwrite($a, $xml->asXML());
   fclose($a);
   
?>
KKiernan
Newsterisk
 
Posts: 7
Joined: Fri May 04, 2012 7:39 am

Re: Error Logs & Triggers

Postby dpodolsky » Thu May 17, 2012 10:29 am

Usually that error means you have additional/unknown characters in your XML document you are passing back from the trigger. You can probably ignore these if your application is working correctly or you can try printing out the XML to a file and look at line 2 column 0. Probably a trailing newline.
dpodolsky
Oldsterisk
 
Posts: 325
Joined: Thu Apr 23, 2009 2:35 pm


Return to Switchvox Developers

Who is online

Users browsing this forum: No registered users and 2 guests