4 Replies Latest reply on Dec 22, 2016 12:19 PM by matt.hill

    batch operations with REST API

    nehamathur

      Hi,

       

      I am trying to make the REST calls in a batch on Jive 8, using the code below -

       

      var batchRequest = osapi.jive.core.post({

            v: "v3",

            href:"/api/core/v3/executeBatch",

            type:"application/json",

            "body":[{

              "key": "featured",

              "request":{

                  "method": "GET",

                  "endpoint": "/contents?filter=type(post)&includeBlogs=true&sort=dateCreatedDesc&count=2&filter=tag(_featured)"

              }

            }, {

                "key": "regular",

              "request":{

                  "method": "GET",

                  "endpoint": "/contents?filter=type(post)&includeBlogs=true&sort=dateCreatedDesc&count=2&filter=tag(_news)"

              }

            }],   

          }).execute(function(response){

            console.log("batch response: " +JSON.stringify(response));

       

       

      I am getting an error -  Unexpected token , 

       

      Is there anything wrong in the above syntax?

       

      Thanks

      Neha

        • Re: batch operations with REST API
          nehamathur

          I tried the below-

          var inputRequest = [ {

                 "key" : "featured",

                  "request" : {

                    "method" : "GET",

                    "endpoint" : "/contents?filter=type(post)&includeBlogs=true&sort=dateCreatedDesc&count=2&filter=tag(_featured)"     

                  }

                }, {

                "key" : "featured",

                  "request" : {

                    "method" : "GET",

                    "endpoint": "/contents?filter=type(post)&includeBlogs=true&sort=dateCreatedDesc&count=2&filter=tag(_homepage_news-highlights)"           }

             } ];

           

             var batch = osapi.jive.core.post({

                "v": "v3",

                "href":"executeBatch",

                "body" : {

                  "content":{

                    "type":"application/json",

                    "text":inputRequest

                  }

                }

             });

             batch.execute(function(response){

              if (response.error){

                console.log("*** error");

                console.log(response.error.message);

              } else {

                console.log("*** response %o", response);

              }

             });

          }

           

           

          For the above, i get an error, saying "Not Found". Please let me know if there is anything wrong in the above syntax.

           

          Thanks

          Neha

            • Re: batch operations with REST API

              Hi Neha,

               

              I happened upon this post while helping out with a batch request API call.

               

              In your code above, I believe you have some of the parameters in the incorrect order, please see below:

               

                 var batch = osapi.jive.core.post({

                    "v": "v3",

                    "href":"executeBatch",

                    "body" : {

                      "content":{

                        "type":"application/json",

                        "text":inputRequest

                      }

                    }

                 });

               

              should be

               

                 var batch = osapi.jive.core.post({

                    "v": "v3",

                   "href":"/executeBatch",

                    "type":"application/json",

                    "body" : inputRequest

                 });

               

              The body parameter for the executeBatch post should be the list of key/request pairs from above, stored in your inputRequest parameter declared above the batch variable

              1 person found this helpful