Hi,<div><br></div><div>I've been playing with the Nova APIs from Javascript, and I've run into a problem.</div><div><br></div><div>The very first thing one needs to do to use the APIs is to get a token. </div><div>
<br></div><div>That requires a POST to the API endpoint. Using curl & trystack that looks like this:</div><div><br></div><div><div>$ curl -k -X 'POST' -v <a href="https://nova-api.trystack.org:5443/v2.0/tokens">https://nova-api.trystack.org:5443/v2.0/tokens</a> -d '{"auth":{"passwordCredentials":{"username": "<username>", "password":"<password>"}}}' -H 'Content-type: application/json'</div>
</div><div><br></div><div><br></div><div>The Javascript equivalent (using JQuery) is:</div><div><br></div><div><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">    $.ajax({</span><br style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">
<span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">        url: "<a href="https://nova-api">https://nova-api</a>.</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">trystack.</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">org:5443/</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">v2.0/tokens"</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">,</span><br style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">
<span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">        type: 'POST',</span><br style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">
<span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">        headers: {"Content-Type": "application/</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">json"},</span><br style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">
<span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">        data: </span>
<span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">{"auth"</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">:{"passwordCred</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">entials"</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">:{"username"</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">:"<username></span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">", "password"</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">:"<password></span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">"}}}</span><span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">,</span><br style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">
<span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">        success: function(data) { alert(data); }</span><br style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">
<span style="color:rgb(51,51,51);font-family:'Ubuntu Mono',monospace;font-size:12px;line-height:18px;text-align:left;background-color:rgb(255,255,255)">    });</span>
</div><div><br></div><div>That fails because the call is cross-domain, and Nova doesn't support CORS (<a href="http://en.wikipedia.org/wiki/Cross-origin_resource_sharing">http://en.wikipedia.org/wiki/Cross-origin_resource_sharing</a>). <script> based cross-domain requests only supports GET requests, so that doesn't work either. </div>
<div><br></div><div>I have raised a bug: <a href="https://bugs.launchpad.net/nova/+bug/987044">https://bugs.launchpad.net/nova/+bug/987044</a>, but I'm really hoping someone can point out something obvious I'm missing here. </div>
<div><br></div><div>Regards</div><div>  Nick Lothian</div>