<?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: PUT Bulk Import in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436487#M1169</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Woohoo, I'm on a ROLL now...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As it says in the API doc, the device data structure can be a list - like this:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14411246372337825" jivemacro_uid="_14411246372337825"&gt;
&lt;P&gt;device = {'device' : [d1, d2] }&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 01 Sep 2015 16:25:17 GMT</pubDate>
    <dc:creator>smp</dc:creator>
    <dc:date>2015-09-01T16:25:17Z</dc:date>
    <item>
      <title>PUT Bulk Import</title>
      <link>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436482#M1164</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anyone have a snippet of how to build Python data structure needed to add a device? Also, when we are using this API, should I be using the Python Response GET or POST method, or PUT verb? The documentation uses the term "PUT", but isn't clear about whether this really is.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Aug 2015 13:49:05 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436482#M1164</guid>
      <dc:creator>smp</dc:creator>
      <dc:date>2015-08-25T13:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: PUT Bulk Import</title>
      <link>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436483#M1165</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I noticed the Resource information table on the left side of the API documentation page states "HTTP Method: PUT", which clearly addresses my second point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm still hoping someone can provide me with a snippet of python code that creates the JSON payload?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Aug 2015 20:03:35 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436483#M1165</guid>
      <dc:creator>smp</dc:creator>
      <dc:date>2015-08-25T20:03:35Z</dc:date>
    </item>
    <item>
      <title>Re: PUT Bulk Import</title>
      <link>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436484#M1166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Bumping this question. I can't believe I am the only person who has ever attempted to add devices into PI with the API...I have not been able to figure out the right JSON data structure.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 12:32:51 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436484#M1166</guid>
      <dc:creator>smp</dc:creator>
      <dc:date>2015-08-31T12:32:51Z</dc:date>
    </item>
    <item>
      <title>Re: PUT Bulk Import</title>
      <link>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436485#M1167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was finally able to successfully create an import job with this API call. There were three important things for me to note:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Use the HTTP &lt;STRONG&gt;PUT&lt;/STRONG&gt; method (as opposed to GET or POST). This is clearly stated in the Resource Information table of the API documentation.&lt;/LI&gt;&lt;LI&gt;I had to add the &lt;STRONG&gt;Content-Type: application/json&lt;/STRONG&gt; header.&lt;/LI&gt;&lt;LI&gt;My data structure looks like this, which is also explicitly shown near the bottom of the API documentation.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;{&lt;/P&gt;&lt;P&gt;&amp;nbsp; "devicesImport" : {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; "devices" : {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "device" : {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "networkMask": "255.255.255.0", &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "udfs": [], &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ipAddress": "192.168.1.100"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I just guessed at the &lt;STRONG&gt;Content-Type&lt;/STRONG&gt; header, but this changed the error message enough for me to figure out the data structure.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 31 Aug 2015 20:31:21 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436485#M1167</guid>
      <dc:creator>smp</dc:creator>
      <dc:date>2015-08-31T20:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: PUT Bulk Import</title>
      <link>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436486#M1168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One final note...since I'm learning Python at the same time I'm learning both PI and the API, it took me some work to figure out how to create the right Python data structure to actually import a device successfully. But, I did it. Below is a sanitized, minimal version of the python script I developed. I have some work to do to modify the data structure so I can import more than one with single call, but this was the minimum that that was required to import a single device. Having this to reference when I started would have saved me a /bunch/ of time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm sure this is terrible python, but cut me some slack - I'm just starting out.&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="_jivemacro_uid_1441122586186454 jive_text_macro jive_macro_code" jivemacro_uid="_1441122586186454"&gt;
&lt;P&gt;#!/usr/bin/python&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;import requests&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;import json&lt;/P&gt;
&lt;P&gt;from requests.auth import HTTPBasicAuth&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;basic = HTTPBasicAuth('&lt;SPAN style="color: #ff0000;"&gt;&amp;lt;username&amp;gt;&lt;/SPAN&gt;', '&lt;SPAN style="color: #ff0000;"&gt;&amp;lt;password&amp;gt;&lt;/SPAN&gt;')&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;host = '&lt;/SPAN&gt;&lt;A _jive_internal="true" href="https://community.cisco.com/" rel="nofollow" target="_blank"&gt;https://&lt;/A&gt;&lt;SPAN&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;lt;PI_DNS_name&amp;gt;&lt;/SPAN&gt;'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;uri = '/webacs/api/v1/op/devices/bulkImport.json'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;url = host + uri&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;d = {&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "ipAddress": "&lt;SPAN style="color: #ff0000;"&gt;192.168.1.100&lt;/SPAN&gt;",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "snmpCommunity": "&lt;SPAN style="color: #ff0000;"&gt;public&lt;/SPAN&gt;",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "snmpVersion": "&lt;SPAN style="color: #ff0000;"&gt;2c&lt;/SPAN&gt;",&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;device = {'device' : d }&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;devices = { 'devices' : device }&lt;/P&gt;
&lt;P&gt;devicesImport = { 'devicesImport' : devices }&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;headers = {'Content-Type' : 'application/json; charset=utf8'}&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;response = requests.put(url, verify=False, auth=basic, headers=headers, data=json.dumps(devicesImport))&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 9pt; line-height: 12pt;"&gt;if response.status_code != 200:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; print response.status_code&lt;/P&gt;
&lt;P&gt;&amp;nbsp; print response.text&lt;/P&gt;
&lt;P&gt;else:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; json_data = json.loads(response.text)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; jobname = json_data['mgmtResponse']['bulkImportResult']['jobName']&lt;/P&gt;
&lt;P&gt;&amp;nbsp; print jobname&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;sys.exit(0)&lt;/P&gt;

&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2015 15:49:20 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436486#M1168</guid>
      <dc:creator>smp</dc:creator>
      <dc:date>2015-09-01T15:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: PUT Bulk Import</title>
      <link>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436487#M1169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Woohoo, I'm on a ROLL now...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As it says in the API doc, the device data structure can be a list - like this:&lt;/P&gt;&lt;PRE __default_attr="python" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14411246372337825" jivemacro_uid="_14411246372337825"&gt;
&lt;P&gt;device = {'device' : [d1, d2] }&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 Sep 2015 16:25:17 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/put-bulk-import/m-p/3436487#M1169</guid>
      <dc:creator>smp</dc:creator>
      <dc:date>2015-09-01T16:25:17Z</dc:date>
    </item>
  </channel>
</rss>

