<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to use REST API for Discovery in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522274#M2083</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a number of REST APIs for Discovery that take an {id}. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There does not appear to be an API, for example a GET for /discovery, that returns the configured Discoveries such that one could programatically extract a Discovery ID to use in the APIs that take that ID as an argument.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further, even if one were to guess that the Discovery ID were the name of the Discovery as created in the UI (and I do not know if this is the case), there does not appear to be an API that would allow one to use that Discovery ID to start the Discovery.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Specifically, then, having configured a Discovery via the UI, it is not clear how, using the APIs, one would be able to invoke it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nathan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 01 Mar 2019 12:29:38 GMT</pubDate>
    <dc:creator>Nathan Sowatskey</dc:creator>
    <dc:date>2019-03-01T12:29:38Z</dc:date>
    <item>
      <title>How to use REST API for Discovery</title>
      <link>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522274#M2083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a number of REST APIs for Discovery that take an {id}. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There does not appear to be an API, for example a GET for /discovery, that returns the configured Discoveries such that one could programatically extract a Discovery ID to use in the APIs that take that ID as an argument.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Further, even if one were to guess that the Discovery ID were the name of the Discovery as created in the UI (and I do not know if this is the case), there does not appear to be an API that would allow one to use that Discovery ID to start the Discovery.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Specifically, then, having configured a Discovery via the UI, it is not clear how, using the APIs, one would be able to invoke it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nathan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2019 12:29:38 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522274#M2083</guid>
      <dc:creator>Nathan Sowatskey</dc:creator>
      <dc:date>2019-03-01T12:29:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to use REST API for Discovery</title>
      <link>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522275#M2084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you use the /reachability-info (under the Network Discovery tree in swagger) API, you'll get back a list of discovery IDs (integers, really).&amp;nbsp; You can then feed those into the inventory/discovery.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14688801643717788" jivemacro_uid="_14688801643717788"&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "discoveryId": "1",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "mgmtIp": "192.168.1.46",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "reachabilityStatus": "UNREACHABLE",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "reachabilityFailureReason": "SNMP Timeout",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "discoveryStartTime": "2016-07-07 20:16:35.772"&lt;/P&gt;
&lt;P&gt;},&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I feed "1" into "GET /api/v1/discovery/1" and I get:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14688802339301476" jivemacro_uid="_14688802339301476"&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "response": {&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "name": "MarcusCom",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "discoveryType": "CDP",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ipAddressList": "192.168.1.36",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "cdpLevel": 16,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "deviceIds": "36d7d3d5-19c8-47fc-bc55-31fd14ad694a,fc422371-9e65-4e08-8e7c-5f57d3e63ade,1153fb76-06dd-4c61-9aa6-739e3d4ab80f",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "userNameList": "jclarke",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "passwordList": "",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ipFilterList": "",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "snmpRoCommunity": "",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "snmpRwCommunity": "",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "protocolOrder": "ssh",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "discoveryCondition": "Complete",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "discoveryStatus": "Inactive",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "timeOut": 5,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "numDevices": 3,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "retryCount": 3,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "isAutoCdp": true,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "id": "1"&lt;/P&gt;
&lt;P&gt;&amp;nbsp; },&lt;/P&gt;
&lt;P&gt;&amp;nbsp; "version": "1.0"&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2016 22:17:36 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522275#M2084</guid>
      <dc:creator>Joe Clarke</dc:creator>
      <dc:date>2016-07-18T22:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to use REST API for Discovery</title>
      <link>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522276#M2085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Joe&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for this. This was an important piece of the puzzle. What I have done is use the network monitor developer tool to see what the UI was doing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I specifically want to do, via the API, is:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;- Trigger a discovery&lt;/LI&gt;&lt;LI&gt;- Show that a number of devices have been discovered&lt;/LI&gt;&lt;LI&gt;- Show the devices in inventory&lt;/LI&gt;&lt;LI&gt;- Delete one of the devices&lt;/LI&gt;&lt;LI&gt;- Show that the deleted device is not in inventory&lt;/LI&gt;&lt;LI&gt;- Trigger a discovery&lt;/LI&gt;&lt;LI&gt;- Show that a number of devices have been discovered&lt;/LI&gt;&lt;LI&gt;- Show the devices in inventory&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The tricky part is 1 and 6. What the UI does is use the PUT /discovery with a JSON body setting the status to "active". The JSON body also contains the ID you explained above. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The above works in a sense, but does not do what I think the system should allow me to do. The specific issue with the API is that&lt;SPAN style="font-size: 10pt;"&gt; the initial request for /reachability-info does return IDs, but without any means to relate the ID to a discovery of a given title.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, I know I have a specific discovery that I want to set to active. I can do that with the POST /discovery. That POST needs a discovery ID. I can get discovery IDs, in general, with the GET &lt;SPAN style="color: #3d3d3d; font-family: arial; font-size: 12px;"&gt;/reachability-info&lt;/SPAN&gt;. What I can't see how to do is map from the discovery IDs that I can GET from &lt;SPAN style="color: #3d3d3d; font-family: arial; font-size: 12px;"&gt;/reachability-info&lt;/SPAN&gt; to the specific discovery I want, apart from trying every ID that I get in the first request and looking for the specific title I need with the second request.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am I missing something please?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nathan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2016 11:28:06 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522276#M2085</guid>
      <dc:creator>Nathan Sowatskey</dc:creator>
      <dc:date>2016-07-19T11:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to use REST API for Discovery</title>
      <link>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522277#M2086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Nathan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have the same situation and got stuck right now. Did you come up with any solution?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Mar 2017 11:32:42 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522277#M2086</guid>
      <dc:creator>Hasan Can Akca</dc:creator>
      <dc:date>2017-03-23T11:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to use REST API for Discovery</title>
      <link>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522278#M2087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The solution here is to use an undocumented API as illustrated in the code below. Once you have the ID for the name, then the other APIs can be used as advertised.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;base_url = "&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://apic-em:443/api/v1/" rel="nofollow" target="_blank"&gt;https://apic-em:443/api/v1/&lt;/A&gt;&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;discovery_url = base_url + 'discovery/'&lt;/P&gt;&lt;P&gt;verify = False&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;headers = {'x-auth-token': get_token(),'content-type': "application/json"}&lt;/P&gt;&lt;P&gt;result = requests.get(url=discovery_url, headers=headers, verify=verify)&lt;/P&gt;&lt;P&gt;result.raise_for_status()&lt;/P&gt;&lt;P&gt;for item in result.json()['response']:&lt;/P&gt;&lt;P&gt;&amp;nbsp; if item['name'] == discovery_name:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; discovery_id = item['id'] &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;print("ID of discovery is " + str(discovery_id) + ".\n")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;def get_token():&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ticket_url = base_url + 'ticket'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; payload = {'username': username, 'password': password}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; headers = {'content-type': "application/json"}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; response = requests.post(url=ticket_url, data=json.dumps(payload), headers=headers, verify=verify)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; token = response.json()['response']['serviceTicket']&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return token&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 Mar 2017 11:46:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/how-to-use-rest-api-for-discovery/m-p/3522278#M2087</guid>
      <dc:creator>Nathan Sowatskey</dc:creator>
      <dc:date>2017-03-23T11:46:41Z</dc:date>
    </item>
  </channel>
</rss>

