Device info for a particular user

Version 1
    This document was generated from CDN thread

    Created by: Tom Barrand on 02-09-2009 01:24:12 PM
    Hi,
     
    I need to be able to query CUCM to find out which device a particular user is logged in to/associated to. This needs to handle both extension mobility or a phone being associated to a user directly.
     
    I will then need to get the following info.
     
    Device Name, e.g. SEPXXXXX
    IP Address of the phone, e.g. 10.10.0.53
    Extension Number, e.g. 3128
     
    Thanks inadvance
     
    Tom

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 02-09-2009 04:20:44 PM
    This information is available, via various web services on UCM.  I would suggest the following sequence:
     
    - Via Administrative AXL, use the <getUser> request, which will return a list of device names associated with the user in getUserResponse/return/user/associatedDevices.
    - Via the Extension Mobility web service, use <userDevicesQuery> to list all the device names into which the user is logged in
    - Via Admin AXL, perform a <getPhone> on each device name,
    obtaining the list of lines on the device, from which you can extract
    the DNs: getPhoneResponse/return/device/lines/line/dirn/pattern
    - Via the Serviceability Risport service, user <SelectCmDevice> query to obtain the IP address of all the device names gathered above
     
    All these web services are covered in the XML Developers Guide available here: http://developer.cisco.com/web/axl/docs

    Subject: RE: Device info for a particular user
    Replied by: Tom Barrand on 09-09-2009 03:35:20 PM
    Hi David,
     
    Thanks for the info.
     
    I have successfully called getUser and have attached the soap response. Which data do I then need to use from the repsonse to find out which devices the user is logged into?
     
    Also, if it is an extension mobility user then I need to use the Extension Mobility API if it is just a user associated to a phone what should I call?
     
    Many thanks
     
    Tom

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 09-09-2009 05:03:18 PM
    To find out what phone(s) an E/M user is logged into, you would use the E/M APIs.
     
    The provided AXL response shows that the user is not associated to any phones (<associatedDevices> is missing), but is associated to one E/M <phoneProfile> named 'bobt_7921'.  You can't tell from here whether the user is logged into the phone profile or not - you need to E/M API for that.

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 18-06-2013 12:00:41 PM
    That looks like the right response, but the <associatedDevices> element is not present - my guess would be because the user is not associated with any devices..?
    http://www.cisco.com/en/US/docs/voice_ip_comm/cucm/admin/7_1_2/ccmcfg/b08user.html#wp1020108
    I also note that the AXL schema version returned is 6.1 - check the AXL guide for details on specifying the correct schema version to use for your UCM (if it's not 6.1.)

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 18-06-2013 11:32:58 AM
    David Staudt:
    This information is available, via various web services on UCM.  I would suggest the following sequence:
     
    - Via Administrative AXL, use the <getUser> request, which will return a list of device names associated with the user in getUserResponse/return/user/associatedDevices.
    - Via the Extension Mobility web service, use <userDevicesQuery> to list all the device names into which the user is logged in
    - Via Admin AXL, perform a <getPhone> on each device name,
    obtaining the list of lines on the device, from which you can extract
    the DNs: getPhoneResponse/return/device/lines/line/dirn/pattern
    - Via the Serviceability Risport service, user <SelectCmDevice> query to obtain the IP address of all the device names gathered above
     
    All these web services are covered in the XML Developers Guide available here: http://developer.cisco.com/web/axl/docs

    Hi David,

    I am using AXL to getUser.  I get a successful response but I do not see a list of device names associated with the user (me in the case for testing).  Here is the XML in the response.  My goal is to find out each device the user is logged into  using their userid.

    - <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">  <SOAP-ENV:Header /> - <SOAP-ENV:Body>- <axl:getUserResponse sequence="?" xmlns:axl="http://www.cisco.com/AXL/API/6.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">- <return>- <user>  <firstname>Darrell</firstname>   <lastname>Breyer</lastname>   <userid>breyerd</userid>   <password />   <pin />   <telephoneNumber>2224806</telephoneNumber>   <department>IS Application Development</department>   <manager>kannern</manager>   <primaryExtension />   <associatedPC />   <associatedGroups />   <enableCTI>true</enableCTI>   <digestCredentials /> - <phoneProfiles>  <profileName>breyerd</profileName>   </phoneProfiles>  <enableMobility>false</enableMobility>   <enableMobileVoiceAccess>false</enableMobileVoiceAccess>   <maxDeskPickupWaitTime>10000</maxDeskPickupWaitTime>   <remoteDestinationLimit>4</remoteDestinationLimit> - <passwordCredentials>  <pwdCredPolicyName>Default Credential Policy</pwdCredPolicyName>   <pwdCredUserCantChange>false</pwdCredUserCantChange>   <pwdCredUserMustChange>true</pwdCredUserMustChange>   <pwdCredDoesNotExpire>false</pwdCredDoesNotExpire>   <pwdCredTimeChanged>November 21, 2012 13:51:45 EST</pwdCredTimeChanged>   <pwdCredTimeAdminLockout />   <pwdCredLockedByAdministrator>false</pwdCredLockedByAdministrator>   </passwordCredentials>- <pinCredentials>  <pinCredPolicyName>Default Credential Policy</pinCredPolicyName>   <pinCredUserCantChange>false</pinCredUserCantChange>   <pinCredUserMustChange>false</pinCredUserMustChange>   <pinCredDoesNotExpire>true</pinCredDoesNotExpire>   <pinCredTimeChanged>March 13, 2013 10:04:58 EDT</pinCredTimeChanged>   <pinCredTimeAdminLockout />   <pinCredLockedByAdministrator>false</pinCredLockedByAdministrator>   </pinCredentials>  </user>  </return>  </axl:getUserResponse>  </SOAP-ENV:Body>  </SOAP-ENV:Envelope>

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 18-06-2013 12:19:13 PM
    You are right, in dev we have limited users set up.  I can get someone who is logged in and it should return back associateddevices.

    Assuming thats it, how do I then find out the devices the user is logged into.  i read through the docs for Extension Mobility and there are no clear soap examples.  I'm much more comfortable with AXL is it possible to figure out if a user is logged in via AXL?  I just want to return all devices the user is logged into..

    Any suggestions are greatly appreciated. If I have to go the EM route are there clear examples I can follow?

    Thanks so much!

    Darrell

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 18-06-2013 01:16:23 PM
    Thanks for your quick response David.

    I'm assuming our service account's access will suffice.  When I paste the emservice/emserviceservlet into a browwser with our ip info i get an error 500.  This is a service that must be turned on I'm assuming.  

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 18-06-2013 01:00:20 PM
    The E/M API is not a full SOAP implementation, just a simple HTTP POST of a small piece of XML.  E.g. to query to see which devices a user is logged into, POST the following XML to https://<server>:8443/emservice/EMServiceServlet:
     1
     2<query>
     3<appInfo>
     4<appID>appid</appID>
     5<appCertificate>apppasswd</appCertificate>
     6</appInfo>
     7<userDevicesQuery>
     8<userID>john</userID>
     9</userDevicesQuery>
    10</query
    Where 'appid' is a UCM application user with E/M proxy rights permission.
    The data which keeps track of E/M logins is kept in the 'extensionmobilitydynamic' table, which you can query via a custom SQL statement and AXL's executeSqlQuery request; however this will mean understanding the fields in the table and how to construct the query.  It's important to note also that direct SQL access is supported, but that the DB schema does not maintain any backward compatibility and tables/fields can change with any UCM release.  Using the E/M API ensures that at minimum the usual UCM API backward compatibility policies apply (i.e. 2 major versions.)

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 18-06-2013 03:02:17 PM
    Making some progress but getting login unsuccessful error.  Here is what I am passing in and i know my creds are right...

    Im confused with the url I should be using?  You mentioned https://10.0.245.10:8443/emservice/EMServiceServlet but that doesn't work on our server.  I get responses back from  http://10.0.245.10:8080/emapp/EMAppServlet but when i post the xml I get login unsuccessful...I pasted the whole error after the script....


    -----------------------------
    // Create a request using a URL that can receive a post.        
    WebRequest request = WebRequest.Create("http://10.0.245.10:8080/emapp/EMAppServlet");   
       
    // Set the Method property of the request to POST.       
    request.Method = "POST";     

      // Create POST data and convert it to a byte array.     
      string postData = "<?xml?>xml=<query><appInfo><appID>user</appID><appCertificate>pass</appCertificate></appInfo><userDevicesQuery><userID>breyerd</userID></userDevicesQuery></query>";       

    byte[] byteArray = Encoding.UTF8.GetBytes(postData);       

    // Set the ContentType property of the WebRequest.       
    request.ContentType = "application/x-www-form-urlencoded";       

    // Set the ContentLength property of the WebRequest.       
    request.ContentLength = byteArray.Length;       

    // Get the request stream.       
    Stream dataStream = request.GetRequestStream();       

    // Write the data to the request stream.       
    dataStream.Write(byteArray, 0, byteArray.Length);       

    // Close the Stream object.       
    dataStream.Close();       

    // Get the response.       
    WebResponse response = request.GetResponse();       

    // Display the status.       
    Console.WriteLine(((HttpWebResponse)response).StatusDescription);       

    // Get the stream containing content returned by the server.       
    dataStream = response.GetResponseStream();       

    // Open the stream using a StreamReader for easy access.       
    StreamReader reader = new StreamReader(dataStream);       

    // Read the content.       
    string responseFromServer = reader.ReadToEnd(); 
         
    // Display the content.       
    Console.WriteLine(responseFromServer);       
    // Clean up the streams.       
    reader.Close();       
    dataStream.Close();       
    response.Close();

    ----------------------------

    error

      <?xml version="1.0" encoding="utf-8" ?> - <CiscoIPPhoneText>  <Title>Login response</Title>   <Text>Login Unsuccessful</Text>   <Prompt>Login is unavailable (207)</Prompt> - <SoftKeyItem>  <Name>Exit</Name>   <URL>SoftKey:Exit</URL>   <Position>1</Position>   </SoftKeyItem>  </CiscoIPPhoneText>


    -----------------

    Thanks in advance

    Darrell

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 18-06-2013 03:26:36 PM
    I changed the url to the one you specify and now I get

    ex = {"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."}

    Subject: Re: New Message from David Staudt in AXL Developer - Administration XML Que
    Replied by: Sascha Monteiro on 18-06-2013 03:37:19 PM
    according the uc9 xml developers guide, http to port 8080 is still
    supported,
    which I still do. SO it does not require https, though it is probably the
    recommended way

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 18-06-2013 03:47:57 PM
    So http://ipaddy:8080/emservice/EMServiceServlet  ??  

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 18-06-2013 03:01:35 PM
    A 500 message similar to:
    1java.lang.NullPointerException
    2    java.lang.String.<init>(String.java:147)
    3    com.cisco.emservice.EMServiceServlet.processRequest(EMServiceServlet.java:204)
    4    com.cisco.emservice.EMServiceServlet.doPost(EMServiceServlet.java:451)
    5    com.cisco.emservice.EMServiceServlet.doGet(EMServiceServlet.java:385)
    is expected if you just do a GET to the URL from a browser.  If the E/M service is not activated, the API will return a 404

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 18-06-2013 03:32:03 PM
    The E/M API requires HTTPS/SSL connection, so I would not expect a regular HTTP request to work.  From native code e.g. C#, you will either need to install the UCM's certificate on your server (manual process,) or cause your client-side code to ignore unknown certificates.  I believe the 'Could not establish trust relationship' error means that the client code could not verify the API services's cert (which is a self-signed.)

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 19-06-2013 01:13:31 PM
    You are correct, HTTP is still supported for this API.

    In testing on my system I was getting 500 as well (with unhelpful 'NullPointerException') message.  As it turns out, the request is supposed to be submitted in HTTP POST 'form' fashion, as 'xml=' followed by the actual XML request.  Unfortunately the documentation does not remind you that when POSTing an HTTP form, you need to specify the Content-Type header as 'application/x-www-form-urlencoded', e.g. instead of 'application/xml'.  After correcting this, request started working for me:
     1POST /emservice/EMServiceServlet HTTP/1.1
     2Host: 10.88.131.141:8080
     3User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:21.0) Gecko/20100101 Firefox/21.0
     4Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
     5Accept-Language: null
     6Accept-Encoding: gzip, deflate
     7DNT: 1
     8Content-Type: application/x-www-form-urlencoded; charset=utf-8
     9Content-Length: 161
    10Connection: keep-alive
    11Pragma: no-cache
    12Cache-Control: no-cache
    13
    14xml=<query><appInfo><appID>emuser</appID><appCertificate>password</appCertificate></appInfo><userDevicesQuery><userID>dstaudt</userID></userDevicesQuery></query>
    15--------------------------------
    16HTTP/1.1 200 OK
    17Content-Type: text/xml
    18Content-Length: 213
    19Date: Wed, 19 Jun 2013 18:06:32 GMT
    20Server: 
    21
    22<?xml version="1.0"?>
    23<!DOCTYPE response SYSTEM "http://10.88.131.141:8080/emservice/jsp/LoginQueryResults.dtd"><response>
    24<userDevicesResults>
    25<user id="dstaudt">
    26<none/>
    27</user>
    28</userDevicesResults>
    29</response>


    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 19-06-2013 02:27:14 PM
    Making some progress based on your example (thank you very much) I now get what you get, but shouldnt I get device name?   

    I need to get all the devices that the user is logged into.  Am i missing something in your response that indicates the devices you are logged into?

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 19-06-2013 02:39:12 PM
    You can then use the AXL <getPhone> request - specifying the device name - to get the phone configuration details (including description.)

    Subject: RE: Device info for a particular user
    Replied by: David Staudt on 19-06-2013 02:33:06 PM
    I wasn't logged into any devices so got <none/>.  You would see a list of device names if the user was logged in (the dev guide has examples.)

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 19-06-2013 02:36:01 PM
    Nevermind it would help if the user Im testing with was logged in.  Assuming this tells me the device, can i get all the description info about that phone?  EAch phone has description information that we would like to pull out...

    Thanks in advance

    Darrell

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 20-06-2013 09:35:39 AM
    HI David, so Im trying to now get the device info using getPhone.

    Of course no luck on the first time around  I get this error which I researched and its just a general error.  See error below:

    -<SOAP-ENV:Envelope
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Header/>-<SOAP-ENV:Body>-<SOAP-ENV:Fault><faultcode>SOAP-ENV:Client</faultcode><faultstring>Error</faultstring>-<detail>-<axl:Error xmlns:axl="http://www.cisco.com/AXL/API/1.0"><axl:code>5000</axl:code><axl:message>Error</axl:message><request>getPhone</request></axl:Error></detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>

    Here is my code:
    public void getPhoneInfo()   
    {          /
    /setting extension mobility       
    String axlRequestEnvelope = null;

    axlRequestEnvelope = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:ns=\"http://www.cisco.com/AXL/API/8.5\"> ";        axlRequestEnvelope += "<soapenv:Header/>";        axlRequestEnvelope += "<soapenv:Body>";        axlRequestEnvelope += "<ns:getPhone sequence=\"?\">";        axlRequestEnvelope += "<name>SEPD0C28243F963</name>";        axlRequestEnvelope += "</ns:getPhone>";        axlRequestEnvelope += "</soapenv:Body>";        axlRequestEnvelope += "</soapenv:Envelope>";
     
    //call manager       
    ServicePointManager.ServerCertificateValidationCallback += delegate { return true; };       
        
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://10.0.245.10:8443/axl/"));                   
    request.ProtocolVersion = System.Net.HttpVersion.Version10;       
    request.Credentials = new NetworkCredential("user", "pass");                   
    request.Timeout = 100000;       
    request.Method = "POST";       
    request.ContentType = "text/xml; charset=utf-8";       
    request.Accept = "text/xml";       
    request.ContentLength = axlRequestEnvelope.Length;

    Stream requestStream = request.GetRequestStream();
    requestStream.Write(System.Text.Encoding.ASCII.GetBytes(axlRequestEnvelope), 0, axlRequestEnvelope.Length);       
    requestStream.Close();

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();      
    Stream responseStream = response.GetResponseStream();       
    StreamReader readStream = new StreamReader(responseStream, Encoding.UTF8);
    Label1.Text = readStream.ReadToEnd();            
          
        }

    Anything you  can think of that would return that error?

    Subject: RE: Device info for a particular user
    Replied by: darrell breyer on 20-06-2013 09:54:47 AM
    Nevermind David I got a correct respone.

    Thanks for all your help.  Hopefully I am off and running now..

    d