<?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 Re: DNAC API - get device IDs by list of hostnames with /network-devic in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/dnac-api-get-device-ids-by-list-of-hostnames-with-network-device/m-p/4925039#M3207</link>
    <description>&lt;P&gt;If you query the endpoint without the hostname parameter, you'll get all devices. With this info you can build for example a hostname to ID dict (assuming the hostname is unique):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests
requests.packages.urllib3.disable_warnings()
import json

dnac = "sandboxdnac.cisco.com"
user = "devnetuser"
password = "Cisco123!"

r = requests.post(f"https://{dnac}/dna/system/api/v1/auth/token", auth=(user, password), verify=False)
if r.ok:
    token = r.json().get("Token")
    r = requests.get(f"https://{dnac}/dna/intent/api/v1/network-device", headers={"X-Auth-Token": token}, verify=False)
    if r.ok:
        hostname2id = {}
        for dev in r.json().get("response"):
            print(f"hostname: {dev.get('hostname')} ==&amp;gt; ID: {dev.get('id')}")
            hostname2id[dev.get("hostname")] = dev.get("id")

        # print all
        print(json.dumps(hostname2id, indent=1))

        # get id for specific hostname
        print(f"id for sw3 is {hostname2id.get('sw3')}")

else:
    print("Error while getting infos from DNAC API")
    exit(1)&lt;/LI-CODE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;{
 "sw1": "32446e0a-032b-4724-93e9-acbbab47371b",
 "sw2": "c069bc2c-bfa3-47ef-a37e-35e2f8ed3f01",
 "sw3": "5f03d9a9-33df-450e-b0c3-6bcb5f721688",
 "sw4": "826bc2f3-bf3f-465b-ad2e-e5701ff7a46c"
}
id for sw3 is 5f03d9a9-33df-450e-b0c3-6bcb5f721688&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Sep 2023 14:13:41 GMT</pubDate>
    <dc:creator>Marcel Zehnder</dc:creator>
    <dc:date>2023-09-18T14:13:41Z</dc:date>
    <item>
      <title>DNAC API - get device IDs by list of hostnames with /network-device</title>
      <link>https://community.cisco.com/t5/controllers/dnac-api-get-device-ids-by-list-of-hostnames-with-network-device/m-p/4925008#M3206</link>
      <description>&lt;DIV&gt;&lt;SPAN&gt;Hi all,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;I'm trying to receive a list of network IDs with a single python query:&amp;nbsp;&lt;SPAN&gt;dna/intent/api/v1/network-&lt;/SPAN&gt;&lt;SPAN&gt;device based on a list of approx. 300+ hostnames.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;SPAN&gt;So far I tried to use a single array or a single string:&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;'hostname'&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;','&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;join&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;hostnames&lt;/SPAN&gt;&lt;SPAN&gt;).&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Is the API capable of processing multiple hostsnames? If yes, How is the Syntax? I want to prevent a solution, which needs to process a query for every single host.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 18 Sep 2023 13:29:45 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/dnac-api-get-device-ids-by-list-of-hostnames-with-network-device/m-p/4925008#M3206</guid>
      <dc:creator>vbui6</dc:creator>
      <dc:date>2023-09-18T13:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: DNAC API - get device IDs by list of hostnames with /network-devic</title>
      <link>https://community.cisco.com/t5/controllers/dnac-api-get-device-ids-by-list-of-hostnames-with-network-device/m-p/4925039#M3207</link>
      <description>&lt;P&gt;If you query the endpoint without the hostname parameter, you'll get all devices. With this info you can build for example a hostname to ID dict (assuming the hostname is unique):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;import requests
requests.packages.urllib3.disable_warnings()
import json

dnac = "sandboxdnac.cisco.com"
user = "devnetuser"
password = "Cisco123!"

r = requests.post(f"https://{dnac}/dna/system/api/v1/auth/token", auth=(user, password), verify=False)
if r.ok:
    token = r.json().get("Token")
    r = requests.get(f"https://{dnac}/dna/intent/api/v1/network-device", headers={"X-Auth-Token": token}, verify=False)
    if r.ok:
        hostname2id = {}
        for dev in r.json().get("response"):
            print(f"hostname: {dev.get('hostname')} ==&amp;gt; ID: {dev.get('id')}")
            hostname2id[dev.get("hostname")] = dev.get("id")

        # print all
        print(json.dumps(hostname2id, indent=1))

        # get id for specific hostname
        print(f"id for sw3 is {hostname2id.get('sw3')}")

else:
    print("Error while getting infos from DNAC API")
    exit(1)&lt;/LI-CODE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;{
 "sw1": "32446e0a-032b-4724-93e9-acbbab47371b",
 "sw2": "c069bc2c-bfa3-47ef-a37e-35e2f8ed3f01",
 "sw3": "5f03d9a9-33df-450e-b0c3-6bcb5f721688",
 "sw4": "826bc2f3-bf3f-465b-ad2e-e5701ff7a46c"
}
id for sw3 is 5f03d9a9-33df-450e-b0c3-6bcb5f721688&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Sep 2023 14:13:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/dnac-api-get-device-ids-by-list-of-hostnames-with-network-device/m-p/4925039#M3207</guid>
      <dc:creator>Marcel Zehnder</dc:creator>
      <dc:date>2023-09-18T14:13:41Z</dc:date>
    </item>
  </channel>
</rss>

