While requesting pages with the new helix API, I keep getting an Invalid Cursor
error when I try and request successive pages. This occurs when I try and use after
or before
. Am I using the new paging wrong or is it just borked?
public static async Task<List<return_type>> GetAllPagesAsync<return_type, page_return_type, paging_parameters>(Func<Authentication, string, paging_parameters, Task<page_return_type>> GetPage, Authentication authentication, string token, paging_parameters parameters)
where paging_parameters : new()
{
List<return_type> result = new List<return_type>();
bool requesting = true;
do
{
// request the page
page_return_type page = await GetPage(authentication, token, parameters);
PropertyInfo page_data = page.GetType().GetProperty("data");
List<return_type> page_data_value = (List<return_type>)page_data.GetValue(page);
foreach (return_type element in page_data_value)
{
result.Add(element);
}
// check to see if there is a new page to request
PropertyInfo page_pagination = page.GetType().GetProperty("pagination");
Pagination pagination = (Pagination)page_pagination.GetValue(page);
if (pagination.cursor.isValid())
{
// TODO: (PagingUtil.GetAllPagesAsync) - Fix invalid cursor
// update the parameter's 'after' property to properly request the next page
PropertyInfo parameters_after = parameters.GetType().GetProperty("after");
parameters_after.SetValue(parameters, pagination.cursor);
}
else
{
requesting = false;
}
}
while (requesting);
return result;
}