1 Reply Latest reply on Jun 11, 2014 5:14 AM by jasonnew

    How to create Blog by REST API and jQuery

    leedssheung

      Currently we've working on Jive 6.0.2.0.

       

      In HTML Widget, I created:

       

      $j(document).ready(function() {

        $j('a#test").click(function() {

          $j.ajax({

            type: "POST",

            url: "https://xxxxxx/api/core/v3/contents",

            dataType: "json",

            contentType: "application/json",

            data: {

              "name" : "Test by Me",

              "parent" : "https://xxxxxx/api/core/v3/places/123456",

              "displayName" : "test-by-me",

              "type": "blog"

            },

            error: function( xhr, status ) {

              alert("Error: " + xhr.responseText);

            },

            success: function(result) { alert(result); }

          });

          return false;

        });

      });

       

      <a href="#" id="test">Test</a>

       

      However, it returns:

       

      The request could not be validated as originating from within the sbs application. Code: 4026.

       

      It's an Intranet application, which has implemented Single Sign-on. Is there anything I've done wrong? Thanks!

       

      By the way, how can we get a PlaceID by REST API or any other approach? I could only find the way to get UserID by window.parent._jive_current_user.ID, but no idea for PlaceID.

        • Re: How to create Blog by REST API and jQuery

          Hi Leeds Sheung,

           

          You can do this but you need wrap it with the osapi like this;

          <script type="text/javascript">   
              $j(function() {   
                  require(['osapi'], function(osapi) {   
             
                      var sendPost = function() {   
                          osapi.jive.core.post({   
                              'v': 'v3',   
                              'href': '/contents',   
                              'body': JSON.stringify({   
                               "content":
                               {
                                    "type": "text/html",
                                    "text": "<p>I've got some interesting text</p>"
                               },
                               "subject": "Another New Post in Test Space",
                               "parent" : "http://localhost:8080/api/core/v3/places/1306",
                               "type": "post" 
                              })   
                          }).execute(function(res) {   
                              console.log('Received response', res);   
                          });   
             
                      };   
             
                      $j("#send-post").click(sendPost);   
                  });   
              });   
          </script>
          

           

          You can get the internal place id by calling the places API with filter=entityDescriptor(14,2007) but that assumes you know the container id.  If you want to do it by name then you'll need to do a search for the place like this "api/core/v3/places/?filter=type(space)&fields=id,name&filter=search(Getting%20Started)"