1 Reply Latest reply on Mar 20, 2014 6:31 AM by bergerle

    How can I get authorization to accomplish a request?




      How can I get authorization to accomplish this post request? The red statement didn't work. Any other solution to accomplish the authorization?


         var jsonData = {
                                "type": "text/html",
                                "text": "<body><p>Some interesting text</p></body>"
                     "subject": "My First Wave Document",
                     "type": "document",
                     "status": "published",
                     "authorship": "open",
                     "visibility": "all",

        function createDoc() {
                beforeSend: function(xhr) {
                 xhr.setRequestHeader("Authorization", "Basic " + "username:password");
               url : 'https://wave.aia.com/api/core/v3/contents',
                        data: jsonData,
                        dataType : 'jsonp',
                        success : function(data) {
                         _data = _data.replace(/^throw [^;]*;/,'');
                         _data = data.responseText;  
                         _data = $j.parseJSON(_data);            



      Thank you



        • Re: How can I get authorization to accomplish a request?

          there are at least 2 problems here, one of which I just found out about. First: the basic authentication header needs your username:password kombination as a base64 encoded string (of course you have to insert your real username and password).

          But then there is another problem, that's a bit harder to fix: same origin policy. You already tried to work aroud that one by using "jsonp" as dataType, but that causes the ajax function to work differently, so that the function defined in "beforeSend" isn't called and thus no header is added.
          The "clean" way to solve this is to proxy the call through the server your javascript comes from. So you will have to Implement your own service that gets the ajax request, passes it on to jive and passes the response pack to your javascript.


          apart from that, with this call you would still send the data as form-data, which jive will not accept. You have to send a JSON-string in the Post Body. do this by setting "data: JSON.stringify(jsonData)"