11-09-2016 07:07 AM
Dear folks,
When trying to fetch device status via RisPort using PHP, I get the following error:
Error the cmSelectionCriteria is null
Interestingly, I have a working version written in python.
Both of them are as below:
PHP:
<body>
<div class="container-fluid">
<?php
include "utils.php";
$client = new SoapClient("rispost.wsdl",
array('trace'=>true,
'exceptions'=>true,
'location'=>"https://".$host.":8443/realtimeservice/services/RisPort",
'login'=>$username,
'password'=>$password,
'connection_timeout'=>60,
'stream_context' => $context,
'trace' => 1
));
try
{
$devices = $client->SelectCmDevice(
"",
array(
"SelectBy" => "Name",
"Status" => "Registered",
)
);
}
catch (SoapFault $e)
{
echo "Cannot call method: {$e->getMessage()}";
}
?>
</div>
</body>
</html>
--
Python:
from suds.client import Client
from suds.xsd.doctor import Import, ImportDoctor
import logging
import Basic
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
wsdl = 'https://172.16.4.200:8443/realtimeservice/services/RisPort?wsdl'
cmport = '8443'
#wsdl = 'http://172.17.1.30/AXLAPI.wsdl'
#location = 'https://' + cmserver + ':' + cmport + '/axl/'
import getpass
user = input('user:')
pwd = getpass.getpass('pwd:')
print ('Loading...')
imp = Import('http://schemas.xmlsoap.org/soap/encoding/')
doctor = ImportDoctor(imp)
print('Loading...\n')
client = Client(url=wsdl, username=user, password=pwd, doctor=doctor)
result = client.service.SelectCmDevice('',{'SelectBy':'Name', 'Status':'Registered', 'Class':'Phone', 'Model':'255'})
print('\tDevice\t\tIP Address\tDescription\n\n')
for node in result['SelectCmDeviceResult']['CmNodes']:
for device in node['CmDevices']:
print ('\t'+device['Name'] +'\t'+ device['IpAddress'] +'\t'+ device['Description'])
print('\n\n')
Any ideas?
Regards
Andre Castro
Solved! Go to Solution.
11-10-2016 02:21 PM
Attached is a complete project based on your code. This works for me against CUCM 10.5. Note, the WSDL file is the one retrieved from https://cucm-host:8443/realtimeservice/services/RisPort?wsdl
It looks like the WSDL is different (and requires changes to the PHP code) if you use the WSDL retrieved from https://cucm-host:8443/realtimeservice2/services/RISService70
11-09-2016 11:21 AM
Looks like the parameters to SelectCmDevice() need to be wrapped in an array(), i.e.:
try
{
$devices = $client->SelectCmDevice( array(
"",
array(
"SelectBy"=>"Name",
"Status"=>"Registered"
)
)
);
}
catch (SoapFault $e)
{
echo "Cannot call method: {$e->getMessage()}";
}
The above works fine on my 10.5 setup (using Risport70 WSDL and service)
11-09-2016 11:33 AM
Thanks dstaudt!
I think I tried that someday too.. Now it seems to complain about the missing first argument:
Cannot call method: SOAP-ERROR: Encoding: object has no 'StateInfo' property
Regards
Andre
11-09-2016 12:00 PM
Not sure how I tested the wrong code, but can you try this:
$devices = $client->SelectCmDevice( array(
"StateInfo"=>"",
"CmSelectionCriteria"=>array(
"Status"=>"Any",
"SelectBy"=>"Name",
"SelectItems"=>""
)
)
);
11-10-2016 04:42 AM
Thanks once again dstaudt..
It seems you´re right, we need to actually "declare" the attributes we want to pass on to the request.
Now I got another issue which I´m not able to solve (no info on Google =/)
Cannot call method: org.xml.sax.SAXException: Invalid element in com.cisco.ccm.serviceability.soap.risport.CmSelectionCriteria - DeviceClass
Thanks heaps once again
Cheers
Andre
11-10-2016 08:03 AM
Can you paste the code that's not working? (Ideally the full program file)
11-10-2016 08:22 AM
Yes, besides the code from the initial message, I include the following file:
utils.php:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Multirede UCAT</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<?php
// phpinfo();
$context = stream_context_create([
'ssl' => [
// set some SSL/TLS specific options
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
]);
$host="XXXXX";
$username="XXXX";
$password="XXXX";
?>
status.php:
<body>
<div class="container-fluid">
<?php
include "utils.php";
$client = new SoapClient("rispost.wsdl",
array('trace'=>true,
'exceptions'=>true,
'location'=>"https://".$host.":8443/realtimeservice/services/RisPort",
'login'=>$username,
'password'=>$password,
'connection_timeout'=>60,
'stream_context' => $context,
'trace' => 1
));
try
{
$devices = $client->SelectCmDevice(
"",
array(
"SelectBy" => "Name",
"Status" => "Registered",
)
);
}
catch (SoapFault $e)
{
echo "Cannot call method: {$e->getMessage()}";
}
?>
</div>
</body>
</html>
Cheers
Andre
11-10-2016 09:12 AM
Please try wrapping the arguments to $client->SelectCmDevice() in an (another) array, as below:
$devices = $client->SelectCmDevice( array(
"StateInfo"=>"",
"CmSelectionCriteria"=>array(
"Status"=>"Any",
"SelectBy"=>"Name",
"SelectItems"=>""
)
)
);
I also had to include the StateInfo and SelectItems empty values as placeholders to get mine to work.
11-10-2016 10:59 AM
I tried that as well, unsuccessfully.
I get the error from my previous post
Driving me mad!
Cheers
Andre
11-10-2016 02:21 PM
Attached is a complete project based on your code. This works for me against CUCM 10.5. Note, the WSDL file is the one retrieved from https://cucm-host:8443/realtimeservice/services/RisPort?wsdl
It looks like the WSDL is different (and requires changes to the PHP code) if you use the WSDL retrieved from https://cucm-host:8443/realtimeservice2/services/RISService70
11-11-2016 03:31 AM
Thank you dstaudt, your example works just fine! There must be something wrong with the WSDL provided in CUCM 11.5
The funny thing is that the same WSDL works fine in my Python script.
Cheers mate, thanks a lot for your help!
Andre Castro
07-18-2017 12:25 PM
Hello,
I have it working with CUCM 11.5 using your script status.php
<?php
include "utils.php";
$client = new SoapClient("risport.wsdl",
array('trace'=>true,
'exceptions'=>true,
'location'=>"https://".$host.":8443/realtimeservice2/services/RISService70?wsdl",
'login'=>$username,
'password'=>$password,
'connection_timeout'=>60,
'stream_context' => $context,
'trace' => 1
));
try
{
$devices = $client->SelectCmDevice( array(
"StateInfo"=>"",
"CmSelectionCriteria"=>array(
"Status"=>"Any",
"SelectBy"=>"Name",
"SelectItems"=>""
)
)
);
echo "<pre>";
print_r($devices);
echo "</pre>";
}
catch (SoapFault $e)
{
echo "Cannot call method: {$e->getMessage()}";
}
?>
only changed the location variable as described by dstaudt
02-05-2020 04:32 PM
02-06-2020 02:50 PM
Unfortunately the enforced limit is 1000 (or 2000 as you've observed, for later CUCM versions.)
For situations with more than the max allowable, it is recommended to compile a list of device names (e.g. using AXL <listPhone>) and use SelectCmDeviceExt passing in a chunk of phone names per request, in order to page through the list.
See 'Using RisPort70 With Bulk Requests': https://developer.cisco.com/docs/sxml/#!risport70-api-reference
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide