0 Replies Latest reply on Oct 26, 2015 1:46 PM by nwnerd

    Strange results when querying API for all members in a group

    nwnerd

      I am trying to query our Jive instance through the API for all members of a specific group. I am using C#/.NET with the Restsharp library. The group that I am working with contains about 1400 members. I understand that getting all members of the group in one shot is not possible, so I have built my query to return 100 at a time (using count=100), and then I loop through & bump the startindex each time by 100. This seems to work & the number of group members that I end up with matches the membercount for the group.

       

      Here's where it gets weird.

       

      Just on a hunch, I added some logic that would check for duplicates. As I loop & parse the results, I insert each member into a list. Before doing the insertion, I check to see if it already exists in the list. If it doesn't, I insert it as is. If it does exist, I mark it as a duplicate & then insert it. (Initially I did this just to see if there were any duplicates at all.) So here's the weird part. When I first wrote the script, I only returned 25 results at a time & I was getting over 500 duplicates out of that total of about 1400. I then bumped up the count to 100 results at a time and the number of duplicates dropped to a little under 400.

       

      Has anyone seen an issue like this before? The fact that the duplicates drop as I return more results seems suspicious to me, but other than that I'm at a loss at this point.

       

      Here is the important part of my code (yes it's sloppy, but it's just for testing right now.

       

              public static void Main()
              {
                  JiveController jiveController = new JiveController();
                  JObject jiveJson;
                  List<string> jiveids = new List<string>();
                  int next = 0;
                  int personArraySize;
      
      
                  do
                  {
                      string groupResource = resource + "members/places/537472?fields=person&startIndex=" + next.ToString() +
                                             "&count=100";
                      jiveJson = jiveController.GetJiveUser(groupResource);
                      JArray personArray = (JArray) jiveJson["list"];
                      personArraySize = personArray.Count();
      
      
                      if (personArraySize > 0)
                      {
                          for (int i = 0; i < personArraySize; i++)
                          {
                              string tempstr = (string) jiveJson["list"][i]["person"]["id"];
                              if (jiveids.Contains(tempstr))
                              {
                                  jiveids.Add(tempstr + " : DUPLICATE");
                              }
                              else
                              {
                                  jiveids.Add(tempstr);
                              }
                          }
                          next = next + personArraySize;
                      }
                  } while (personArraySize > 0);
              }
      
              public JObject GetJiveUser(string resource)
              {
                  var client = new RestClient
                  {
                      BaseUrl = new Uri(AuthInfo.JiveUri),
                      Authenticator = new HttpBasicAuthenticator(AuthInfo.JiveUsername,
                                                                 AuthInfo.JivePassword)
                  };
                  
                  var request = new RestRequest { Resource = resource };
                  IRestResponse response = client.Execute(request);
      
      
                  return JObject.Parse(response.Content.Replace("throw 'allowIllegalResourceCall is false.';", String.Empty));
              }