<?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: APIC-EM API using javascript in Controllers</title>
    <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473262#M1365</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you get a sniffer capture of the request to see what headers and body the client is sending?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 May 2016 21:07:47 GMT</pubDate>
    <dc:creator>Joe Clarke</dc:creator>
    <dc:date>2016-05-02T21:07:47Z</dc:date>
    <item>
      <title>APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473258#M1361</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to access the always-on APIC-EM sandbox API using my webserver and javascript.&amp;nbsp; I have already done the python based learning labs and didn't have much issue with it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scenario:&lt;/P&gt;&lt;P&gt;I have a locally hosted nodejs server.&amp;nbsp; I am using xmlHttpRequest (the nodejs version xhr actually) and I can run a GET command no problem.&amp;nbsp; However, since V1 and the new ticketing system, I need to be able to POST the username/password so that I can get the ticket and run the GET commands that I want (network device discovery etc).&amp;nbsp; &lt;/P&gt;&lt;P&gt;Problem:&lt;/P&gt;&lt;P&gt;APIC-EM doesn't seem to recognize the header content type of 'application/json' when I POST (it does with GET, no problem).&amp;nbsp; It returns an error of:&lt;STRONG&gt; "error code": "unknown", "message": "Content-type: 'text/plain;charset=UTF-8' not supported"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;PRE __default_attr="javascript" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14622148023457647" jivemacro_uid="_14622148023457647" modifiedtitle="true"&gt;
&lt;P&gt;var json_text = '{ "username": "admin","password": "C!sc0123" }';&lt;/P&gt;
&lt;P&gt;var ticket_json = JSON.parse(json_text);&lt;/P&gt;
&lt;P&gt;var apicem_ip = "&lt;A data-saferedirecturl="https://www.google.com/url?q=http://sandboxapic.cisco.com:9443&amp;amp;source=gmail&amp;amp;ust=1462301721801000&amp;amp;usg=AFQjCNFDccw8mvMDbOZq36eJFM49JYjUQA" href="http://sandboxapic.cisco.com:9443/" target="_blank"&gt;sandboxapic.cisco.com:9443&lt;/A&gt;";&lt;/P&gt;
&lt;P dir="ltr"&gt;&lt;SPAN&gt;var apic_url = '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://'+apicem_ip+'/api/v1/ticket';" rel="nofollow" target="_blank"&gt;https://'+apicem_ip+'/api/v1/ticket';&lt;/A&gt;&lt;BR /&gt;//- var xmlHTTP = new XMLHttpRequest();&lt;BR /&gt;var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;&lt;BR /&gt;var xhr = new XMLHttpRequest();&lt;BR /&gt;xhr.open('POST',apic_url,false);&lt;BR /&gt;xhr.responseType = 'JSON';&lt;BR /&gt;xhr.setRequestHeader = ('content-type', 'application/json');&lt;BR /&gt;xhr.send(JSON.stringify(ticket_json));&lt;BR /&gt;app.locals.apic_nd = xhr.responseText;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lines 6 and 12 are nodejs specific as XMLHttpRequest doesn't exist natively in nodejs.&amp;nbsp; I don't think that is a problem because I can successfully use GET and receive a response from the sandbox controller.&amp;nbsp; Line 12 is just setting a global variable to be called in my HTML file (which is where I view the responses and errors from the sandbox controller).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Things I've tried, I tried to send just a plain JSON object on line 11 (without the stringify function which converts it into a string), but that doesn't work in Java Script and I believe that that is not how the python API works either (it is a string as well).&amp;nbsp; I also changed line 10 to 'text/json' as well, no luck.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Why am I trying to do this?&lt;/P&gt;&lt;P&gt;I already have a way to view the controller data via a shell using python, I would like to call the APIs and see the same data via a browser.&amp;nbsp; I figured JavaScript would be the easiest way but ran into the above issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2019 12:28:03 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473258#M1361</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2019-03-01T12:28:03Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473259#M1362</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think what might be happening is XMLHttpRequest is looking for a "Content-type" header with an uppercase 'C'.&amp;nbsp; Since it doesn't see one, it goes with its default.&amp;nbsp; Can you try setting the header Content-type and see if that helps?&amp;nbsp; While this shouldn't matter, there have been bugs with this in the past with XMLHttpRequest modules.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2016 19:17:44 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473259#M1362</guid>
      <dc:creator>Joe Clarke</dc:creator>
      <dc:date>2016-05-02T19:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473260#M1363</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If that doesn't work, the other thing it might be is complaining on the Accept header.&amp;nbsp; Try also adding:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;xhr.&lt;CODE&gt;&lt;SPAN class="pln"&gt;setRequestHeader&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;(&lt;/SPAN&gt;&lt;SPAN class="str"&gt;'Accept'&lt;/SPAN&gt;&lt;SPAN class="pun"&gt;,&lt;/SPAN&gt;&lt;SPAN class="str"&gt;'application/json');&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2016 19:29:47 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473260#M1363</guid>
      <dc:creator>Joe Clarke</dc:creator>
      <dc:date>2016-05-02T19:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473261#M1364</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried both your options and still got the same error message.&amp;nbsp; &lt;IMG src="https://community.cisco.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/P&gt;&lt;P&gt;Thanks for your input, any other ideas?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2016 20:58:11 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473261#M1364</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2016-05-02T20:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473262#M1365</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you get a sniffer capture of the request to see what headers and body the client is sending?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2016 21:07:47 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473262#M1365</guid>
      <dc:creator>Joe Clarke</dc:creator>
      <dc:date>2016-05-02T21:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473263#M1366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried yours and got&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="jive-image image-2" src="https://community.cisco.com/legacyfs/online/fusion/95020_pastedImage_1.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I modified my script to be the same as your then got &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var url = 'https:/sandboxapic.cisco.com:9443/api/v1/ticket';&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// provide username and password as body of request&lt;/P&gt;&lt;P&gt;var j_data = {&lt;/P&gt;&lt;P&gt;"username":"admin",&lt;/P&gt;&lt;P&gt;"password":"C!sc0123"};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var json_text = '{"username":"admin","password":"C!sc0123"}';&amp;nbsp; &lt;/P&gt;&lt;P&gt;var ticket_json = JSON.parse(json_text);&amp;nbsp; &lt;/P&gt;&lt;P&gt;var xmlHttp = new XMLHttpRequest();&lt;/P&gt;&lt;P&gt;alert("test1");&lt;/P&gt;&lt;P&gt;xmlHttp.open("POST", url, false);&lt;/P&gt;&lt;P&gt;xmlHttp.setRequestHeader("Content-type", "application/json");&lt;/P&gt;&lt;P&gt;alert("test2");&lt;/P&gt;&lt;P&gt;xmlHttp.responseType = "JSON";&lt;/P&gt;&lt;P&gt;alert("test3");&lt;/P&gt;&lt;P&gt;// xmlHttp.send(JSON.stringify(j_data));&lt;/P&gt;&lt;P&gt;xmlHttp.send(JSON.stringify(ticket_json)); &lt;/P&gt;&lt;P&gt;alert("test4");&lt;/P&gt;&lt;P&gt;alert(xmlHttp.response);&lt;/P&gt;&lt;P&gt;var data = JSON.parse(xmlHttp.response)&lt;/P&gt;&lt;P&gt;alert(data.version)&lt;/P&gt;&lt;P&gt;alert(data.response.serviceTicket);&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.cisco.com/legacyfs/online/fusion/95019_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect there may have hidden char in you script or I missed something.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BUT those are minor compare to what you can see from the&amp;nbsp; last image that we are facing CORS issue. How can you resole the CORS issue that's the challenge.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2016 21:36:40 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473263#M1366</guid>
      <dc:creator>yawming</dc:creator>
      <dc:date>2016-05-02T21:36:40Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473264#M1367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;xhr.setRequestHeader = (&lt;SPAN class="string"&gt;'content-type', &lt;SPAN class="string"&gt;'application/json'&lt;/SPAN&gt;);&amp;nbsp; ==&amp;gt; got error.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;vs&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;xhr.setRequestHeader(&lt;SPAN class="string"&gt;'content-type', &lt;SPAN class="string"&gt;'application/json'&lt;/SPAN&gt;);&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;Aslo we can just use&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="string"&gt;&lt;SPAN class="string"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;var json_text = { "username": "admin","password": "C!sc0123" };&lt;/P&gt;&lt;P&gt;......&lt;/P&gt;&lt;P&gt;......&lt;/P&gt;&lt;P&gt;xhr.send(JSON.stringify(json_text));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2016 22:11:28 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473264#M1367</guid>
      <dc:creator>yawming</dc:creator>
      <dc:date>2016-05-02T22:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473265#M1368</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Heh, I didn't catch that.&amp;nbsp; Yeah, it's a method.&amp;nbsp; It doesn't return a settable property.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 May 2016 22:15:23 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473265#M1368</guid>
      <dc:creator>Joe Clarke</dc:creator>
      <dc:date>2016-05-02T22:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473266#M1369</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hmm, nice catch!  I wonder why it worked with the GET requests.  I changed the code  but still a no go.  Looking at the xhr module I am using, there is a known bug for synchronous requests that mess up header data.  I changed the code to async which is supposed to fix it but still got the same error.  I think the problem might be with the module.  There is another one I can try and will post back tomorrow or tonight.  Thanks so far!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2016 00:25:32 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473266#M1369</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2016-05-03T00:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473267#M1370</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I got it working with a different module, not sure why I was using the old one...guess I am new to nodejs and restAPIs.&amp;nbsp; Here is the code (this website won't let me format code in replies...)&lt;/P&gt;&lt;P&gt;Thanks for y'alls help!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var apicem_ip = "sandboxapic.cisco.com:9443";&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var apic_url = '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://'+apicem_ip+'/api/v1/ticket';" rel="nofollow" target="_blank"&gt;https://'+apicem_ip+'/api/v1/ticket';&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var request = require('request');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var options = {&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; url: '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://'+apicem_ip+'/api/v1/ticket" rel="nofollow" target="_blank"&gt;https://'+apicem_ip+'/api/v1/ticket&lt;/A&gt;&lt;SPAN&gt;',&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; method: "POST",&lt;/P&gt;&lt;P&gt;&amp;nbsp; headers: {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Content-type': 'application/json'&lt;/P&gt;&lt;P&gt;&amp;nbsp; },&lt;/P&gt;&lt;P&gt;&amp;nbsp; //console.log("test1");&lt;/P&gt;&lt;P&gt;&amp;nbsp; body: '{ "username": "admin", "password": "C!sc0123"}'&lt;/P&gt;&lt;P&gt;//console.log("test2");&lt;/P&gt;&lt;P&gt;};&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function callback(error, response, body) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; console.log("callback function");&lt;/P&gt;&lt;P&gt;&amp;nbsp; //if (!error &amp;amp;&amp;amp; response.statusCode == 200) {&lt;/P&gt;&lt;P&gt;&amp;nbsp; if (!error) {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var info = (JSON.parse(body));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(info);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log("status 200");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; else {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //console.log(response.statusCode);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //console.log(JSON.parse(body));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; console.log(JSON.parse(body));&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;request.post(options, callback);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2016 20:16:30 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473267#M1370</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2016-05-03T20:16:30Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473268#M1371</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad to hear that, so you did not get any CORS issue ?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2016 20:24:06 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473268#M1371</guid>
      <dc:creator>yawming</dc:creator>
      <dc:date>2016-05-03T20:24:06Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473269#M1372</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what CORS is, but I was able to get a ticket number... so now it is on to the next where I use the ticket number as a header in my GET requests...like in the python modules.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2016 20:30:53 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473269#M1372</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2016-05-03T20:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473270#M1373</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wonder if you can share your whole javascript ? You use node.js right ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.w3.org/TR/cors/" title="https://www.w3.org/TR/cors/"&gt;https://www.w3.org/TR/cors/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2016 20:36:33 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473270#M1373</guid>
      <dc:creator>yawming</dc:creator>
      <dc:date>2016-05-03T20:36:33Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473271#M1374</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes.  Node.js with express.js as the webfrontend.  I am also using jade as the HTML template option.  I am all new to this, I just downloaded a template website (google hackathon-startup).&lt;/P&gt;&lt;P&gt;The code I posted above is the only real addition I've made to app.js.  However, I don't think that is where the code should live.  I am trying to figure out now how to incorporate the js code either directly into HTML via jade... or... directly into the controller js res handler.  Again, new to node in general so still trying to figure it out.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 May 2016 20:44:22 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473271#M1374</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2016-05-03T20:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473272#M1375</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Guys&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying this code JS as well&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;=================================&lt;/P&gt;&lt;P&gt;&amp;lt;html&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;lt;head&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;title&amp;gt;&lt;/P&gt;&lt;P&gt;Hello.com&lt;/P&gt;&lt;P&gt;&amp;lt;/title&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/head&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;script&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var url = '&lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="https://sandboxapic.cisco.com/api/v1/ticket';" rel="nofollow" target="_blank"&gt;https://sandboxapic.cisco.com/api/v1/ticket';&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;// provide username and password as body of request&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var json_text = {"username" : "devnetuser","password" : "Cisco123!"}; &lt;/P&gt;&lt;P&gt;var x = JSON.stringify(json_text);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//var ticket_json = JSON.parse(json_text); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var xmlHttp = new XMLHttpRequest();&lt;/P&gt;&lt;P&gt;xmlHttp.withCredentials = true;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;alert("test1");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;xmlHttp.open("POST", url, true);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;xmlHttp.setRequestHeader('X-PINGOTHER.com', 'pingpong');&lt;/P&gt;&lt;P&gt;xmlHttp.setRequestHeader("content-type", "application/json");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;alert("test2");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;xmlHttp.responseType = "json";&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;alert("test3");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;xmlHttp.send(x);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;//xmlHttp.send(json_text);&lt;/P&gt;&lt;P&gt;alert("test4");&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;var data = JSON.parse(xmlHttp.response);&lt;/P&gt;&lt;P&gt;//alert(data.version);&lt;/P&gt;&lt;P&gt;// alert(data.response.serviceTicket);&lt;/P&gt;&lt;P&gt;&amp;lt;/script&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;lt;/html&amp;gt;&lt;/P&gt;&lt;P&gt;=====================================&lt;/P&gt;&lt;P&gt;I think I am having an issue with CORs. cant figure out the problem&lt;/P&gt;&lt;P&gt;Here's what i get when I run chrome CTRL+Shift +J (devtools)&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.cisco.com/legacyfs/online/fusion/97727_pastedImage_2.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 16 Jul 2016 16:19:44 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473272#M1375</guid>
      <dc:creator>khorheesoo</dc:creator>
      <dc:date>2016-07-16T16:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473273#M1376</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My understanding is that cors prevents HTTP requests from running in browser.  I worked around this by sending info to nodejs server and sending request from there.  Not sure how else to do it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Jul 2016 13:13:02 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473273#M1376</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2016-07-17T13:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473274#M1377</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks Joshua. I think I have the same problem.&lt;/P&gt;&lt;P&gt;So basically you using a proxy in between to send the request on behalf and then return the response back.&lt;/P&gt;&lt;P&gt;Sounds like we are hacking our way through it.&lt;/P&gt;&lt;P&gt;I am using a local machine which runs the scripts and then passing it to my locally run IIS server and getting output.&lt;/P&gt;&lt;P&gt;I also noticed that some timeout needs to be set to get response. If I run the alerts too fast i dont get an output.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's how I'm setting a little timeout for the script to get the information from the server. Are you able to get the info immediately? So far I have been able to run some codes already using PUT and GET. But I am now learning how to create a Java Application to access this information instead of using Javascript.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;setTimeout(tst, 3000);&lt;/P&gt;&lt;P&gt;function tst () {&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; var data = JSON.parse(xmlHttp.responseText);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; document.getElementById("demo").innerHTML = "The Ticket number is " + data.response.serviceTicket;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; alert(data.version);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;IMG alt="" class="image-1 jive-image" src="https://community.cisco.com/legacyfs/online/fusion/97730_pastedImage_0.png" style="max-width: 1200px; max-height: 900px;" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Jul 2016 15:40:41 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473274#M1377</guid>
      <dc:creator>khorheesoo</dc:creator>
      <dc:date>2016-07-17T15:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473275#M1378</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nodejs is asynchronous so the timeouts and dealing with hangups are explicit in the architecture.  I.e., it will call the request, then move on to other code, and then come back to the request as soon as there is a response.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I agree that using a back end server for requests is a bit of a work around, but then again, I don't understand cors and the security issues that come with.  I doubt using a back end server is any more secure though.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Jul 2016 16:31:03 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473275#M1378</guid>
      <dc:creator>Joshua Leatham</dc:creator>
      <dc:date>2016-07-17T16:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: APIC-EM API using javascript</title>
      <link>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473276#M1379</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. I get it. Just tried with a Java Application and none of the cors issues. It seems to be a JS specific issue. Even the timeout is not necessary. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Jul 2016 20:44:09 GMT</pubDate>
      <guid>https://community.cisco.com/t5/controllers/apic-em-api-using-javascript/m-p/3473276#M1379</guid>
      <dc:creator>khorheesoo</dc:creator>
      <dc:date>2016-07-17T20:44:09Z</dc:date>
    </item>
  </channel>
</rss>

