<?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: Postman API connection to DNAC in Application Networking</title>
    <link>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4989288#M51449</link>
    <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/139746"&gt;@DAVID&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably need to iterate the Token retrieve when you run a chain of requests and i'm don't think that you can change the default timer (60 seconds). The script below to retrieve the Token&lt;/P&gt;
&lt;P&gt;#!/usr/bin/python3&lt;/P&gt;
&lt;P&gt;import&amp;nbsp;requests&lt;/P&gt;
&lt;P&gt;import&amp;nbsp;json&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;from&amp;nbsp;prettytable&amp;nbsp;import&amp;nbsp;PrettyTable&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;print&amp;nbsp;("start");&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#&amp;nbsp;API&amp;nbsp;URL&amp;nbsp;to&amp;nbsp;get&amp;nbsp;a&amp;nbsp;List&amp;nbsp;of&amp;nbsp;Network&amp;nbsp;devices&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;requests.packages.urllib3.disable_warnings()&lt;/P&gt;
&lt;P&gt;url&amp;nbsp;=&amp;nbsp;"https://&amp;lt;IP Address&amp;gt;&lt;STRONG&gt;/dna/intent/api/v1/&lt;/STRONG&gt;network-device"&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;payload&amp;nbsp;=&amp;nbsp;{}&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;headers&amp;nbsp;=&amp;nbsp;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'X-Auth-Token':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;lt;Paste Token retrieved via Postman.'&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;response&amp;nbsp;=&amp;nbsp;requests.request("GET",&amp;nbsp;url,&amp;nbsp;verify=False,&amp;nbsp;headers=headers,&amp;nbsp;data&amp;nbsp;=&amp;nbsp;payload)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;#&amp;nbsp;Take&amp;nbsp;the&amp;nbsp;response&amp;nbsp;and&amp;nbsp;turn&amp;nbsp;it&amp;nbsp;into&amp;nbsp;Python&amp;nbsp;Objects&lt;/P&gt;
&lt;P&gt;raw_output&amp;nbsp;=&amp;nbsp;json.loads(response.text)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;#&amp;nbsp;raw_output&amp;nbsp;is&amp;nbsp;a&amp;nbsp;Dictionary.&amp;nbsp;Take&amp;nbsp;the&amp;nbsp;value&amp;nbsp;of&amp;nbsp;response&amp;nbsp;and&amp;nbsp;assign&amp;nbsp;to&amp;nbsp;devices&lt;/P&gt;
&lt;P&gt;devices&amp;nbsp;=&amp;nbsp;raw_output["response"]&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;#Iterate&amp;nbsp;through&amp;nbsp;the&amp;nbsp;list&amp;nbsp;to&amp;nbsp;print&amp;nbsp;out&amp;nbsp;hostnames&amp;nbsp;of&amp;nbsp;devices&lt;/P&gt;
&lt;P&gt;for&amp;nbsp;device&amp;nbsp;in&amp;nbsp;devices:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("Hostname:&amp;nbsp;{}".format(device["hostname"]))&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jan 2024 19:07:34 GMT</pubDate>
    <dc:creator>Ruben Cocheno</dc:creator>
    <dc:date>2024-01-03T19:07:34Z</dc:date>
    <item>
      <title>Postman API connection to DNAC</title>
      <link>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4989273#M51447</link>
      <description>&lt;P&gt;How can I overcome the DNAC token timing out when using Postman?&amp;nbsp; I have created an environment within Postman with the DNAC variables like host, username and password. Right now the current token will expire after a set length of time and I have to run another POST to get the new token.&amp;nbsp; I'm new to Postman and API's but I'm sure there's a better way of using Postman and DANC&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 18:39:43 GMT</pubDate>
      <guid>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4989273#M51447</guid>
      <dc:creator>DAVID</dc:creator>
      <dc:date>2024-01-03T18:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Postman API connection to DNAC</title>
      <link>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4989288#M51449</link>
      <description>&lt;P&gt;&lt;a href="https://community.cisco.com/t5/user/viewprofilepage/user-id/139746"&gt;@DAVID&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You probably need to iterate the Token retrieve when you run a chain of requests and i'm don't think that you can change the default timer (60 seconds). The script below to retrieve the Token&lt;/P&gt;
&lt;P&gt;#!/usr/bin/python3&lt;/P&gt;
&lt;P&gt;import&amp;nbsp;requests&lt;/P&gt;
&lt;P&gt;import&amp;nbsp;json&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;from&amp;nbsp;prettytable&amp;nbsp;import&amp;nbsp;PrettyTable&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;print&amp;nbsp;("start");&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#&amp;nbsp;API&amp;nbsp;URL&amp;nbsp;to&amp;nbsp;get&amp;nbsp;a&amp;nbsp;List&amp;nbsp;of&amp;nbsp;Network&amp;nbsp;devices&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;requests.packages.urllib3.disable_warnings()&lt;/P&gt;
&lt;P&gt;url&amp;nbsp;=&amp;nbsp;"https://&amp;lt;IP Address&amp;gt;&lt;STRONG&gt;/dna/intent/api/v1/&lt;/STRONG&gt;network-device"&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;payload&amp;nbsp;=&amp;nbsp;{}&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;headers&amp;nbsp;=&amp;nbsp;{&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'X-Auth-Token':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;'&amp;lt;Paste Token retrieved via Postman.'&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;
&lt;P&gt;response&amp;nbsp;=&amp;nbsp;requests.request("GET",&amp;nbsp;url,&amp;nbsp;verify=False,&amp;nbsp;headers=headers,&amp;nbsp;data&amp;nbsp;=&amp;nbsp;payload)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;#&amp;nbsp;Take&amp;nbsp;the&amp;nbsp;response&amp;nbsp;and&amp;nbsp;turn&amp;nbsp;it&amp;nbsp;into&amp;nbsp;Python&amp;nbsp;Objects&lt;/P&gt;
&lt;P&gt;raw_output&amp;nbsp;=&amp;nbsp;json.loads(response.text)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;#&amp;nbsp;raw_output&amp;nbsp;is&amp;nbsp;a&amp;nbsp;Dictionary.&amp;nbsp;Take&amp;nbsp;the&amp;nbsp;value&amp;nbsp;of&amp;nbsp;response&amp;nbsp;and&amp;nbsp;assign&amp;nbsp;to&amp;nbsp;devices&lt;/P&gt;
&lt;P&gt;devices&amp;nbsp;=&amp;nbsp;raw_output["response"]&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;#Iterate&amp;nbsp;through&amp;nbsp;the&amp;nbsp;list&amp;nbsp;to&amp;nbsp;print&amp;nbsp;out&amp;nbsp;hostnames&amp;nbsp;of&amp;nbsp;devices&lt;/P&gt;
&lt;P&gt;for&amp;nbsp;device&amp;nbsp;in&amp;nbsp;devices:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print("Hostname:&amp;nbsp;{}".format(device["hostname"]))&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 19:07:34 GMT</pubDate>
      <guid>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4989288#M51449</guid>
      <dc:creator>Ruben Cocheno</dc:creator>
      <dc:date>2024-01-03T19:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: Postman API connection to DNAC</title>
      <link>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4990314#M51450</link>
      <description>&lt;P&gt;So let me see if I have this correct.&amp;nbsp; The token from DNAC will expire at 60 seconds so any time I need to run a python script or postman API, I will first need to get the new token from DNAC to use it in a python script or postman requests and I'll have to do this ever time I make a new request to DNAC that is outside of the 60 second time limit??&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 21:21:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4990314#M51450</guid>
      <dc:creator>DAVID</dc:creator>
      <dc:date>2024-01-04T21:21:41Z</dc:date>
    </item>
    <item>
      <title>Re: Postman API connection to DNAC</title>
      <link>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4990319#M51451</link>
      <description>&lt;P&gt;You will typically want to fetch and renew the token using the API using basic auth in your scripts. The token does only last 60 seconds, but If you use the &lt;A href="https://github.com/cisco-en-programmability/dnacentersdk" target="_self"&gt;DNA Center SDK&lt;/A&gt; or similar it will handle the token renewal automatically. You can read more about this in the "getting started" portion of the API docs: &lt;A href="https://developer.cisco.com/docs/dna-center/#!getting-started" target="_blank" rel="noopener"&gt;https://developer.cisco.com/docs/dna-center/#!getting-started&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For Postman you can chain requests and use data from responses(like the token) in subsequent requests. This way you won't have to rush through fetching the token and executing your requests. The following blog article is a good place to start for this: &lt;A href="https://blog.postman.com/extracting-data-from-responses-and-chaining-requests/" target="_blank"&gt;https://blog.postman.com/extracting-data-from-responses-and-chaining-requests/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 21:44:31 GMT</pubDate>
      <guid>https://community.cisco.com/t5/application-networking/postman-api-connection-to-dnac/m-p/4990319#M51451</guid>
      <dc:creator>Torbjørn</dc:creator>
      <dc:date>2024-01-04T21:44:31Z</dc:date>
    </item>
  </channel>
</rss>

