question

Lev Rakhman avatar image
Lev Rakhman asked ·

API How to get all Directory entries

I am getting initial list of of entries:

var resp = await restClient.Restapi().Account("~").Directory().Entries().List(listDirectoryEntriesParameters);

return object has 2 properties: paging object and array of records.

How do I access all pages in response?

sdk
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Phong Vu avatar image
Phong Vu answered ·

You can read like this

read_company_directory(-1).Wait();

static private async Task read_company_directory(int pageNumber)
{
  pageNumber++;
  var listDirEntriesParams = new ListDirectoryEntriesParameters();
  listDirEntriesParams.perPage = 300;
  if (pageNumber > 0)
      listDirEntriesParams.page = pageNumber.ToString();
  var response = await rcsdk.Restapi().Account().Directory().Entries().List(listDirEntriesParams);
  Console.WriteLine("Directory");
  Console.WriteLine(JsonConvert.SerializeObject(response.paging));
  if (response.paging.totalPages >= pageNumber)
  {
      read_company_directory(pageNumber).Wait();
  }
}


Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Lev Rakhman avatar image
Lev Rakhman answered ·

Thanks, works perfectly.

One small error. It should be if (response.paging.totalPages >= pageNumber)

Otherwise entries from last page will not be read.

Share
1 |1000 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.