Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Options

Pagination through API (Kasper) or JSON

phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP

Hi all,

When retrieving the categories or discussions ... how does pagination work when retrieving JSON?

We found that if you go direct via the .json then multiple requests for the same URL seems to return subsequent pages. But only if you are logged in.

Is there a a way to determine how many pages there are? Is there a way to get a specific page?

Thanx, phreak

  • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
  • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
Tagged:

Comments

  • Options
    BleistivtBleistivt Moderator

    We found that if you go direct via the .json then multiple requests for the same URL seems to return subsequent pages. But only if you are logged in.

    If a discussion has 3 unread pages, you will be shown the first that contains a comment you have not read. Since it is then marked read, the next request will yield the next page until everything is marked read for the user.

    You can request a specific page by appending /p1, /p2 ... to the url

    The current page number is contained in the JSON ("Page"), but the total page count is not.
    You could calculate it using the "Discussion" -> "CountComments" property from the JSON data.

    Or you could add it to the API using a plugin:

    public function discussionController_render_before($sender) {
        $countComments = $sender->data('Discussion')->CountComments;
        $totalPages = calculateNumberOfPages($countComments, c('Vanilla.Comments.PerPage', 30));
        $sender->setData('TotalPages', $totalPages);
    }
    
  • Options
    phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited April 2016

    Thanx @Bleistivt! We geared towards the same way and found that this is a quiet untypical way to approach it via sole page requests on the same JSON url.

    But thanx we wil do it like you recommended just wondered if there is a smarter way to retrieve the page numbers.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
Sign In or Register to comment.