Pagination

In this guide, we will look at how to work with paginated responses when querying the BlogHunch API. By default, all responses limit results to ten. However, you can go as high as 100 by adding a limit parameter to your requests. If you are using one of the official BlogHunch API client libraries, you don't need to worry about pagination, as it's all being taken care of behind the scenes.

Example using cursors

In this example, we request the page that starts from the 11th record. As a result, we get a list of 10 posts starting from 11 to ending at 20 and can tell by the total attribute that we have reached the end of the resultset.

  • Name
    page
    Type
    integer
    Description

    The page number for the paginated data.

  • Name
    limit
    Type
    integer
    Description

    Limit the number of items returned.

Manual pagination using cURL

curl -G https://api.bloghunch.com/app/{subdomain}/posts \
  -H "Authorization: Bearer {token}" \
  -d page=2 \
  -d limit=10

Paginated response

{
  "posts": {
    "meta": {
      "total": 23,
      "per_page": 10,
      "current_page": 2,
      "last_page": 3,
      "first_page": 1,
      "first_page_url": "/?page=1",
      "last_page_url": "/?page=3",
      "next_page_url": "/?page=3",
      "previous_page_url": null
    },
    "data": [
      {
        "id": 406856,
        "author_id": 1,
        "publication_id": 3696,
        "title": "Post test 1",
        "excerpt": null,
        "slug": "post-test-1",
        "content": "<p>test 1</p>",
        "content_text": "test 1",
        "featured_image": null,
        "status": "publish",
        "canonical_url": null,
        "post_type": "post",
        "meta_title": null,
        "meta_description": null,
        "featured": 0,
        "toc": 1,
        "published_at": "2023-03-07T22:44:29.000+05:30",
        "deleted_at": null,
        "created_at": "2023-03-07T22:44:20.000+05:30",
        "updated_at": "2023-03-07T22:44:29.000+05:30",
        "reading_time": 1,
        "author": {
          "id": 1,
          "name": "Subham Mitra",
          "tagline": "Full stack javascript developer",
          "avatar": "VQZOo1GnjkAdsqaW.webp"
        },
        "tags": [
          {
            "id": 66,
            "name": "faq",
            "slug": "faq"
          }
        ]
      }
    ]
  }
}