Speedygeek/ZendeskApi_v2

perPage on GetByPageUrlAsync overrides Url parameter and breaks result

Closed this issue · 2 comments

I'm querying Articles with GetArticlesAsync and I'm getting in the results a NextPage like 'https://xxxxx.zendesk.com/api/v2/help_center/en-us/articles.json?page=2&per_page=30

Then I use this URL to query the next page using the GetArticlesByUrlAsync method just like:
var response = await _zendeskService.GetArticlesByUrlAsync(response.NextPage);

This by default sets the perPage parameter to 100, when the value on the URL is 30, and the API breaks and doesn't return any items anymore. I reckon the method should check if the parameter already exists on the passed URL and mantain that value.

@skartknet Can you supply a test case to replicate this issue?

@skartknet Looked at the issue more. I think the following test is an example of what you are doing and you will notice the pageSize is a parameter to the GetByPageUrlAsync method the pageSize is optional and defaults to 100 as that is the max allowed.

closing "As Designed" but if you want to submit a PR with overload that using the original page size. I would happily accept it.

[Test]
public async Task CanGetSecondPageUisngGetByPageUrl()
{
var pageSize = 3;
var res = await Api.HelpCenter.Articles.GetArticlesAsync(perPage: pageSize);
Assert.That(res.PageSize, Is.EqualTo(pageSize));
var resp = await Api.HelpCenter.Articles.GetByPageUrlAsync<GroupArticleResponse>(res.NextPage, pageSize);
Assert.That(resp.Page, Is.EqualTo(2));
}