DX NetOps

 View Only
Expand all | Collapse all

Spectrum REST API - Getting a Device List

  • 1.  Spectrum REST API - Getting a Device List

    Posted Apr 07, 2014 04:27 PM

    Hi All,

    I am hoping someone can help me.  I am trying to get a list of device using the Spectrum REST API.  I need all device that meet a specific security string.

    I am able to get back a list of all devices using this:

    http://ourspectrumserver:8080/spectrum/restful/devices?attr=0x1006e&attr=0x12d7f&attr=0x10000&attr=0x10009

    But the documentation doesn't seem to indicate a way to filter the list.  Does anyone know how to do it?  I would prefer not to pull a full list of devices and instead just pull a subset.


    Thanks

    Susan

     



  • 2.  RE: Spectrum REST API - Getting a Device List

    Posted Apr 08, 2014 04:09 AM

    Susan

    You need to look at the section titled "POST models (GET Tunneling)" In here it says "Use POST models to get all model handles and requested attributes. POSTing a models request lets you provide an XML document that specifies the models to retrieve. The document contains a list of model handles, XML search criteria, or a reference to existing search criteria on the OneClick server."

    In summary you use an XML file with the search criteria you need and reference that in the POST models.

    Regards, John



  • 3.  RE: Spectrum REST API - Getting a Device List

    Posted Apr 09, 2014 09:16 AM

    John,

    OK. That makes sense.  I looked through the XML examples, and I found one that might work for getting a device list and filtering on the attribute for Security String.  (I've included it below).  I am unsure what I need to modify to get it to work.  I have modified it to return the correct attributes I would like to see but  I would like to filer on attribute 0x10009 to search for the security string "test".

    Any guidance would be appreciated. 

    Thanks.

    Susan

    <?xml version="1.0" encoding="UTF-8"?>

    <!--

     

     

       CA Technologies, Inc.

       One CA Plaza

       Islandia, NY 11749 USA

     

       Copyright (c) 2012 CA Technologies, Inc.

       All rights reserved.

     

       IN NO EVENT SHALL CA TECHNOLOGIES INCORPORATED BE LIABLE FOR

       ANY INCIDENTAL, INDIRECT, SPECIAL, OR CONSEQUENTIAL DAMAGES

       WHATSOEVER (INCLUDING BUT NOT LIMITED TO LOST PROFITS) ARISING OUT

       OF OR RELATED TO THIS SOFTWARE, EVEN IF CA TECHNOLOGIES INCORPORATED

       HAS BEEN ADVISED OF, KNOWN, OR SHOULD HAVE KNOWN, THE POSSIBILITY OF

       SUCH DAMAGES.

     

     

    -->

     

    <rs:model-request throttlesize="10"

      xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"

      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

      xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">

     

     

        <rs:target-models>

          <rs:models-search>

            <rs:search-criteria-file>

              topo/config/search-devices-criteria.xml

            </rs:search-criteria-file>

          </rs:models-search>

        </rs:target-models>

     

        <rs:requested-attribute id="0x1006e" />

        <rs:requested-attribute id="0x12d7f" />

        <rs:requested-attribute id="0x10000" />

        <rs:requested-attribute id="0x10009" />

     

    </rs:model-request>



  • 4.  RE: Spectrum REST API - Getting a Device List
    Best Answer

    Posted Apr 09, 2014 11:58 AM

    Susan,

       The <rs:requested-attribute ... /> lines don't actually work with the search.  These lines are to identify what attributes you want the query to return.

    The following may help you:

    <?xml version="1.0" encoding="UTF-8"?>
    <rs:model-request
      xmlns:rs="http://www.ca.com/spectrum/restful/schema/request"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.ca.com/spectrum/restful/schema/request ../../../xsd/Request.xsd ">
     <rs:target-models>
      <rs:models-search>
       <rs:search-criteria xmlns="http://www.ca.com/spectrum/restful/schema/filter">
         <devices-only-search />
         <filtered-models>
           <has-substring-ignore-case>
            <attribute id="0x10009">
             <value>{enter your string here}</value>
            </attribute>
          </has-substring-ignore-case>
         </filtered-models>
       </rs:search-criteria>
      </rs:models-search>
     </rs:target-models>
     <rs:requested-attribute id="0x1006e" />
     <rs:requested-attribute id="0x12d7f" />
     <rs:requested-attribute id="0x10009" />
     <rs:requested-attribute id="0x10000" />
    </rs:model-request>

    Some things to note - notice the "<devices-only-search />".  That will return the devices, if you want you can remove this to get other models returned.  Also I used "<has-substring-ignore-case>".  This way if you have security strings with multiple strings in them, you should match.  Otherwise, if you do an "<equals>", you have to have an exact match.  You can also do it with or without the "-ignore-case".

    For testing out your queries, I recommend getting a REST Client.  I use Firefox with the "RESTClient" add on.  It works great.  Some things to know when using it, is that you need to define the Headers for your request (pull down Header->Custom header and enter "Content-Type: application/xml"), provide your Authorization(pull down), Method=POST, and then your URL: http://{whatever server}:{whatever port}/spectrum/restful/models.

    The examples in the docs and the OneClick servers are great in that they help you get started.  The REST interface is very powerful and I'm opening up new avenues for Spectrum data all the time with this.



  • 5.  RE: Spectrum REST API - Getting a Device List

    Posted Apr 11, 2014 04:50 PM

    Bill,

    Thank you. The firefox REST Client works great, and this script works well.  For anyone else who uses it, the security string value won't have quotes around it.

    Susan

     



  • 6.  RE: [.CA Spectrum] RE: Spectrum REST API - Getting a Device List

    Posted Apr 11, 2014 06:22 PM
    Bill,

    Thanks for the posted information, I too was able to use the information to get some data via the API that I previously struggled to do. Now If I could figure out how to format the data into a table on a HTML webpage I would really be happy :)

    Troy


  • 7.  Re: RE: Spectrum REST API - Getting a Device List

    Posted Nov 27, 2015 08:03 AM

    The REST API is really badly documented and has very basic example which don't explain anything. At CAW 2015 Kiran did mention that this will get improved upon in the future.



  • 8.  Re: Spectrum REST API - Getting a Device List

    Posted Feb 15, 2017 10:58 AM

    We're now in the future, has it been better documented?

    I just checked the SDK folder for Spectrum 10.2, it still says Spectrum 9.2 at the top. And I have yet to see any good documentation or guide on how to begin working with the API for someone who isn't well versed in API.



  • 9.  RE: Spectrum REST API - Getting a Device List

    Posted Mar 05, 2020 04:36 PM
    hey I get this 

    <model-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" total-models="42028" throttle="1000">

    so i only get the 1st 1000  how do i change the throttle to dump all?


  • 10.  RE: Spectrum REST API - Getting a Device List

    Posted Mar 06, 2020 02:20 AM
    Change to throttle to 100.000 or whatever value is greater than the total number of devices that you have.

    ------------------------------
    Senior Consultant
    SolvIT Networks
    ------------------------------



  • 11.  RE: Spectrum REST API - Getting a Device List

    Posted Apr 14, 2021 06:23 PM
    how do you do that???


  • 12.  RE: Spectrum REST API - Getting a Device List

    Posted Apr 21, 2021 10:06 AM
    <model-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" total-models="42028" throttle="100000">

    ------------------------------
    Senior Consultant
    SolvIT Networks
    ------------------------------



  • 13.  RE: Spectrum REST API - Getting a Device List

    Posted Apr 21, 2021 10:07 AM

    In OPs query string you would only add throttlesize, like this:

    http://ourspectrumserver:8080/spectrum/restful/devices?throttlesize=100000&attr=0x1006e&attr=0x12d7f&attr=0x10000&attr=0x10009

    I good way to test out different queries, and see what params are available, is using the Swagger API documentation in Spectrum which is available at http://ourspectrumserver:8080/spectrum/restful/api-docs?url=/spectrum/restful/swagger.json




  • 14.  RE: Spectrum REST API - Getting a Device List

    Posted Apr 21, 2021 10:07 AM
    <model-response-list xmlns="http://www.ca.com/spectrum/restful/schema/response" total-models="42028" throttle="100000">

    ------------------------------
    Senior Consultant
    SolvIT Networks
    ------------------------------