private void SearchMembersGetUsage(IProvisioningModel model) { string UserAccessToken = ApplicationResource.DefaultAccessToken; if (!string.IsNullOrEmpty(UserAccessToken)) { MemberServices serviceUsage = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); serviceUsage.GetUsageUrl = ApplicationResource.ActionGetUsage; List<string[]> members = new List<string[]>(); MemberServices service = new MemberServices(ApplicationResource.BaseUrl, ApplicationResource.ApiVersion); service.ListMembersUrl = ApplicationResource.ActionListMembers; service.UserAgentVersion = ApplicationResource.UserAgent; IDataResponse response = service.ListMembers(new MemberData() { SearchLimit = ApplicationResource.SearchDefaultLimit }, UserAccessToken); if (response.StatusCode == HttpStatusCode.OK) { if (response.Data != null) { string data = response.Data.ToString(); dynamic jsonData = JsonConvert.DeserializeObject<dynamic>(data); // clear existing data first model.Members.Clear(); int resultCount = jsonData["members"].Count; for (int i = 0; i < resultCount; i++) { dynamic emailObj = jsonData["members"][i]["profile"]["email"]; dynamic firstNameObj = jsonData["members"][i]["profile"]["name"]["given_name"]; dynamic lastNameObj = jsonData["members"][i]["profile"]["name"]["surname"]; dynamic idObj = jsonData["members"][i]["profile"]["team_member_id"]; string teamId = idObj.Value as string; string email = emailObj.Value as string; string firstName = firstNameObj.Value as string; string lastName = lastNameObj.Value as string; IDataResponse responseUsage = serviceUsage.GetUsage(new MemberData() { MemberId = teamId }, UserAccessToken); UInt64 used = 0; if (responseUsage.StatusCode == HttpStatusCode.OK) { if (responseUsage.Data != null) { string dataUsage = responseUsage.Data.ToString(); dynamic jsonDataUsage = JsonConvert.DeserializeObject<dynamic>(dataUsage); used = jsonDataUsage["used"]; } } // update model MemberListViewItemModel lvItem = new MemberListViewItemModel() { Email = email, MemberId = teamId, FirstName = firstName, LastName = lastName, Usage = FileUtil.FormatFileSizeMB(used) }; model.Members.Add(lvItem); } //if the memberID count is above limit - default 1000 we need to grab the cursor and call continue bool hasMore = jsonData["has_more"]; string cursor = jsonData["cursor"]; while (hasMore) { service.ListMembersContinuationUrl = ApplicationResource.ActionListMembersContinuation; IDataResponse responseCont = service.ListMembersContinuation(new MemberData() { Cursor = cursor }, UserAccessToken); string dataCont = responseCont.Data.ToString(); dynamic jsonDataCont = JsonConvert.DeserializeObject<dynamic>(dataCont); int resultContCount = jsonDataCont["members"].Count; for (int i = 0; i < resultContCount; i++) { dynamic emailObj = jsonDataCont["members"][i]["profile"]["email"]; dynamic firstNameObj = jsonDataCont["members"][i]["profile"]["name"]["given_name"]; dynamic lastNameObj = jsonDataCont["members"][i]["profile"]["name"]["surname"]; dynamic idObj = jsonData["members"][i]["profile"]["team_member_id"]; string teamId = idObj.Value as string; string email = emailObj.Value as string; string firstName = firstNameObj.Value as string; string lastName = lastNameObj.Value as string; IDataResponse responseUsage = serviceUsage.GetUsage(new MemberData() { MemberId = teamId }, UserAccessToken); decimal used = 0; if (responseUsage.StatusCode == HttpStatusCode.OK) { if (responseUsage.Data != null) { string dataUsage = responseUsage.Data.ToString(); dynamic jsonDataUsage = JsonConvert.DeserializeObject<dynamic>(dataUsage); used = jsonDataUsage["used"]; } } // update model MemberListViewItemModel lvItem = new MemberListViewItemModel() { Email = email, MemberId = teamId, FirstName = firstName, LastName = lastName, Usage = FileUtil.FormatFileSizeMB(used) }; model.Members.Add(lvItem); } hasMore = jsonDataCont["has_more"]; cursor = jsonDataCont["cursor"]; } } } } }