cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1148
Views
0
Helpful
2
Replies
Highlighted
Beginner

ACS - REST API, Filtered Result

Hello!,

I'm trying to use the REST API on a ACS 5.5 server to:

  1. retrieve a list of all the Network Devices

  2. Retrieve a list of all the Network devices that belong to a specific Network Device Group.

At this moment I have tried the REST Client add-on for Firefox, when I  do a GET operation on the server with the URL https://10.254.4.68/Rest/NetworkDevice/Device  It retrieves all the Network Devices (which is great!)

The problem is when I try to filter:

I do a PUT operation with the URL: https://10.254.4.68/Rest/NetworkDevice/Device/op/query

I add the following in the body field:

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

      <ns2:query xmlns:ns2="query.rest.mgmt.acs.nm.cisco.com">

             <criteria xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:type="ns2:AndFilter">

                    <simpleFilters>

                          <propertyName>name</propertyName>

                          <operation>NOT_EQUALS</operation>

                          <value>X</value>

                    </simpleFilters>

                    <simpleFilters>

                          <propertyName>name</propertyName>

                          <operation>CONTAINS</operation>

                          <value>T</value>

                    </simpleFilters>

             </criteria>

             <numberOfItemsInPage>100</numberOfItemsInPage>

             <startPageNumber>1</startPageNumber>

     </ns2:query>


And from the response headers I get:

  1. Status Code: 415 Unsupported Media Type
  2. Cache-Control: no-cache
  3. Content-Type: text/xml
  4. Date: Mon, 29 Sep 2014 21:03:24 GMT
  5. Expires: Wed, 31 Dec 1969 19:00:00 EST
  6. Pragma: No-cache
  7. Server: ACS 5.4
  8. Transfer-Encoding: chunked

Any ideas, could it be the XML format I'm passing to the server?

Thanks

2 REPLIES 2
Highlighted
Cisco Employee

Hi Angel,

  I think XML format is correct. Can you try HTTP GET

HTTP PUT—Update an existing object. PUT is also used to invoke extrinsic methods (other than CRUD).

When HTTP PUT method is used for operations other than CRUD, the URL specifies the required operation. This is also used to distinguish the message from PUT method for update. The keyword "op" is included in the URL as follows:

Rest/{package}/{ObjectType}/op/{operation}

For example, /Rest/Identity/IdentityGroup/op/query

Reference - HTTP Methods

Thanks and Regards,

Geevarghese

Highlighted
Beginner

For posterity sake and to help other poor SOB's like me trying to figure it out here is the solution:

The real issue is your XML is searching the "name" field, not a network device group. In my example I have a custom NDG called "Primary OU". The below will match all devices in Primary OU:MARS

URL: https://<Device name or IP>/Rest/NetworkDevice/Device/op/query

Header: Content-type:application/xml

Method: PUT

Body:

<ns2:query xmlns:ns2="query.rest.mgmt.acs.nm.cisco.com">

<criteria xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:AndFilter">

<simpleFilters>

<propertyName>Primary OU</propertyName>

<operation>CONTAINS</operation>

<value>MARS</value>

</simpleFilters>

</criteria>

<numberofItemsInPage>100</numberofItemsInPage>

<startPageNumber>1</startPageNumber>

</ns2:query>

Content for Community-Ad
Cisco Community October 2020 Spotlight Award Winners
This widget could not be displayed.