I'm new to the world of API and need to get a list of all of our users (400 in total). Initially I could only get 30 users but after reading the API notes I see that 30 is a default value. I set the page value to 100, which is the max and I can display 100 users in my data grid. However, I would like to get all 400 users. From what I understand I need to set up pagination to get the other 300, but have no idea how to achieve this. I'd appreciate it if somebody could look at my code and advise. The code below returns a list of contacts, which I display in a winforms datagrid.
public static async Task<List<Contact>> LoadContacts(string filter)
{
string apiPath = ApiHelper.ApiClient.BaseAddress.ToString();
switch (filter)
{
case "Deleted":
apiPath += "?state=deleted;per_page=100";
break;
default:
apiPath += "?per_page=100";
break;
}
using (HttpResponseMessage response = await ApiHelper.ApiClient.GetAsync(apiPath))
{
Console.WriteLine("Response StatusCode: " + (int)response.StatusCode);
if (response.IsSuccessStatusCode)
{
List<Contact> emp = await response.Content.ReadAsAsync<List<Contact>>();
return emp;
}
else
{
throw new Exception(response.ReasonPhrase);
}
}
}