10 Replies Latest reply on Aug 31, 2016 3:45 AM by gopi.gorantala

    Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI

    gopi.gorantala

      Hi Ryan Rutan, Nils HeuerPawan Shah

       

      I have an OSAPI call which pulls users from REST API. Below code snippet gives me first 25results. How can I get the next successive 25 results ?

       

      osapi.jive.core.get({

         v: "v3",
         href: "/people?filter=department("+departmentName+")"
      }).execute(function (response) {

      }

       

      1. I am trying to get the next 25 results with the "next" link. But I am not able to get results through $.getJSON. probably I need to pass an authentication mechanism when i'm hitting the below link using $.getJSON.  Can you let me know how can I get next 25 results ?

       

      "links" : {

        "next" : "https://XXX.XXXXXXXXXXXXXXX.XXX/api/core/v3/people?sort=firstNameAsc&fields=%40summary&origin=unknown&count=25&startIndex=25"

        },

       

      Thanks,

      -Gopi.

        • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
          gopi.gorantala

          I found a way to get all results, but not sure if this is the best way. Can anyone take a look at this and suggest me ?

           

          https://XXX.XXXXXXXXXXXXXXX.XXX/api/core/v3/people?filter=department(departmentNameHere)&count=100&startIndex=0

           

          The above query, gives me 100 users list starting with 0th index till 99. Reference idea

           

          Thanks,

          -Gopi.

          • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
            Scott A Johnson

            Hi Gopi,

             

            To get the next page using OSAPI apis, you can use something like this:

             

            osapi.jive.corev3.people.get({
              count:100,
              ...
            }).execute(function(response) {
              if(response.getNextPage) {
                var nextPageRequest = response.getNextPage();
                nextPageRequest.execute(function(nextPageResponse) {
                  // this should be recursive
                }
              }  
            });
            

             

            The getNextPage function will return a request object which can then be executed.

             

            You'll want to build that request->response->nextPageRequest logic into a recursive function which will stop when getNextPage doesn't exist for the response object.

             

            Hope this helps.

             

            Scott

              • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
                gopi.gorantala

                I tried this approach already and it was not working. getNextPage() function is not working for me to get the next 100 people.

                 

                Thanks,

                -Gopi.

                  • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
                    gopi.gorantala

                    Hi Scott A Johnson, Ryan Rutan

                     

                    osapi.jive.core.get({

                       v: "v3",
                       href: "/people?filter=department(" + departmentName + ")&count=100&startIndex=0"
                    }).execute(function (response) {

                     

                    Above Javascript call gives me a list of people belonging to same department, but it wont display the basic attributes such as location,phonenumber etc..  Now, to get profile fields, I am looping each user and making another javascript call as below. I know this call is expensive and I see "Server is busy" in the console(intermittent behavior). Is there a way to get all users profile values within a single server hit instead of below?

                     

                     

                    osapi.jive.corev3.people.get({id: userID}).execute(function (person) {

                       console.log(person);

                    }

                     

                     

                     

                    Console ERROR#

                    1. Object {id: "jive.core.get", error: Object}
                      1. error:Object
                        1. code:503
                        2. message:"Server Too Busy"
                        3. __proto__:Object
                      2. id:"jive.core.get"
                      3. __proto__:Object

                     

                     

                    The above console error is not consistent, its intermittent. My code displays a page with user values properly sometimes and at sometimes it gives me the error in console which is uncertain.

                        • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
                          Scott A Johnson

                          Hi Gopi,

                           

                          You should be able to pass in the fields=@all parameter which will retrieve all available fields for the person. This should allow you to avoid making multiple calls to the service to retrieve the needed data.

                           

                          You should also be able to use the corev3 people get call for the first call instead of the generic core.get. Its possible that the getNextPage function may only be available on corev3 function calls. You should be able to construct a request json payload for the corev3.people.get function which replicates the filter and count parameters you're using in your original call.

                           

                          Hope this helps,

                          Scott

                            • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
                              gopi.gorantala

                              Hi Scott A Johnson

                               

                              If I use fields=@all in the osapi.jive.corev3.people.get(), then it gives me all the users and I can iterate them through getNextPage().

                               

                              But, my requirement is to get full user profile values based on department. When I use the below OSAPI, then I get all users part of the department but with limited values and this is the reason I am again hitting the server with osapi.jive.corev3.people.get({id: userID}) as follows -

                               

                              osapi.jive.core.get({

                                 v: "v3",
                                 href: "/people?filter=department(" + departmentName + ")&count=100&startIndex=0"
                              }).execute(function (response) { //This gives me all users, but with limited values and this is the reason I get the userID's from here, then I pass the userID to the below query to get more profile fields such as location, phonenumber and Custom-profile-fields.

                              }

                               

                              osapi.jive.corev3.people.get({id: userID}).execute(function (person) {

                                 console.log(person); // this brings me the custom profile fields too.

                              }

                               

                              I am getting all user details based on department and its working fine, but the problem is that the results are intemittent, because of the following servere busy issue.

                              1. Object {id: "jive.core.get", error: Object}
                                1. error:Object
                                  1. code:503
                                  2. message:"Server Too Busy"
                                  3. __proto__:Object
                                2. id:"jive.core.get"
                                3. __proto__:Object

                               

                              Now, please suggest me how can I pass array of users at one go using OSAPI OR tell me how can I make sure I get all profile fields including custom using the first query OSAPI.jive.core.get({   })

                                • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
                                  gopi.gorantala

                                  Well, I found a way to grab the custom profile fields using the first OSAPI call itself. I am posting here so if anyone running into same issues then they can make use of this -

                                   

                                     href: "/people?filter=department(" + departmentName + ")&count=100&startIndex=0&fields=jive,phoneNumber"

                                   

                                  All custom created profile fields comes under jive.profile, so now, I inlcuded the &fields=jive which pulls me the JSON response with fields=jive, if you dont want any then youcan mention it as &fields=jive,-location,  here location is excluded in the results.

                                   

                                  Now I have only one OSAPI hit to server, I can't see the 503-Server too busy error now.

                                   

                                  -Gopi.

                                  1 person found this helpful
                                    • Re: Iterate Rest API /api/core/v3/people... for the next 25 results using OSAPI
                                      gopi.gorantala

                                      If someone would like to know, here is what I did, It iterates through the nextPage untilthe nextPage is empty or has no list init.

                                       

                                      var getUsersFromDepartment = function (departmentName) {
                                          var url = "/people?filter=department(" + departmentName + ")&count=100&startIndex=0&fields=jive,phoneNumbers,name";
                                          getOsapiRequestFromDepartment(url);
                                      }
                                      
                                      
                                      function getOsapiRequestFromDepartment(url) {
                                          var departMemberRequest = osapi.jive.core.get({
                                              v: "v3",
                                              href: url
                                          });
                                          processDepartmentListByPage(departMemberRequest);
                                      }
                                      
                                      
                                      function processDepartmentListByPage(request) {
                                          var deferred = Q.defer();
                                          request.execute(function (response) {
                                              if (response.error) {
                                                  var errorCode = response.error.code;
                                                  var errorMessage = response.error.message;
                                                  console.error('Error occured with Errod Code: ['+errorCode+']; and error message as ['+errorMessage+']');
                                              } else if (!response.content.list) {
                                                  console.error('No Users present in the list');
                                              } else {
                                                  var userListArray = response.content.list;
                                                ....
                                                ....
                                                ....
                                                  var userListArray = response.content.links;
                                      
                                      
                                                  if (typeof userListArray !== 'undefined') {
                                                      var nextPage = (userListArray.next).substr(49);
                                                      getOsapiRequestFromDepartment(nextPage);
                                                  }
                                      
                                      
                                              }
                                          })
                                          return deferred.promise;
                                      };
                                      
                                      
                                      
                                      
                                      
                                      3 people found this helpful