Skip to content
Peal
Esc
↑↓navigate↵open⌘Jpreview
On this page

Paging

How a list answers one page at a time, and how to ask for the next.

Paging

You read a list that can grow without end a page at a time, newest first:

  1. Send limit, the size of a page, in the query.
  2. Read the page’s items and its nextCursor in the answer.
  3. Pass nextCursor as cursor to read the next page, and stop when it’s null.

A cursor is an opaque string. It works for the list it came from, with the same filters. Anywhere else it answers 400 bad_request.

Each list has its own page size:

List A page holds At most
GET …/posts/drafts 20 50
GET …/media 30 100
GET …/webhooks/{endpointId}/deliveries 30 100
GET …/workspace/activity 30 100

Paths starting with … are under /api/v1.

Ask for the first page:

import { PealClient } from "@peal-social/sdk";

const peal = new PealClient({ token: process.env.PEAL_API_KEY });

const page = await peal.workspace.activity.list({ limit: "2" });
import os

from peal import Peal

peal = Peal(token=os.environ["PEAL_API_KEY"])

page = peal.workspace.activity.list(limit="2")
import (
	"context"
	"os"

	peal "github.com/peal-social/peal/packages/peal-sdk/go"
	"github.com/peal-social/peal/packages/peal-sdk/go/client"
	"github.com/peal-social/peal/packages/peal-sdk/go/option"
	"github.com/peal-social/peal/packages/peal-sdk/go/workspace"
)

// The client is named `client`, so that `peal` stays the package of the
// request types.
client := client.NewClient(option.WithToken(os.Getenv("PEAL_API_KEY")))
ctx := context.Background()

page, err := client.Workspace.Activity.List(ctx, &workspace.ListActivityRequest{
	Limit: peal.String("2"),
})
require "peal"

peal = Peal::Client.new(token: ENV.fetch("PEAL_API_KEY"))

page = peal.workspace.activity.list(limit: "2")
import social.peal.PealClient;
import social.peal.resources.workspace.activity.requests.ListActivityRequest;
import social.peal.types.ActivityPage;

PealClient peal = PealClient.builder()
    .token(System.getenv("PEAL_API_KEY"))
    .build();

ActivityPage page = peal.workspace().activity().list(ListActivityRequest.builder()
    .limit("2")
    .build());
<?php
use Peal\Workspace\Activity\Requests\ListActivityRequest;
use Peal\PealClient;

$peal = new PealClient(token: getenv('PEAL_API_KEY'));

$page = $peal->workspace->activity->list(new ListActivityRequest(['limit' => '2']));
using Peal;
using Peal.Workspace;

var peal = new PealClient(Environment.GetEnvironmentVariable("PEAL_API_KEY")!);

var page = await peal.Workspace.Activity.ListAsync(new ListActivityRequest
{
    Limit = "2",
});
use peal_sdk::prelude::*;

let peal = PealClient::new(ClientConfig {
    token: std::env::var("PEAL_API_KEY").ok(),
    ..Default::default()
})?;

let page = peal
    .workspace
    .activity
    .list(
        &WorkspaceActivityListQueryRequest {
            limit: Some("2".to_string()),
            ..Default::default()
        },
        None,
    )
    .await?;
curl "https://api.example.com/api/v1/workspace/activity?limit=2" \
  -H "Authorization: Bearer $PEAL_API_KEY"

The answer holds two entries and a cursor:

{
  "items": [
    {
      "id": "019a7b31-0d4e-7c22-b8a1-3f5e6d7c8b90",
      "occurredAt": "2026-11-16T08:00:02.412Z",
      "operation": "posts.create",
      "status": 201,
      "errorCode": null,
      "actor": { "_tag": "apiKey", "apiKeyId": "k7Qp2mXvT9aLw3ZsB4nE" },
      "via": "apiKey",
      "application": {
        "id": "k7Qp2mXvT9aLw3ZsB4nE",
        "name": "Newsletter script"
      },
      "impersonated": false,
      "objectIds": {},
      "requestId": "nightly-sync:2026-11-16:0042"
    },
    {
      "id": "019a7b30-6f18-7a95-9d07-1c2b3a4d5e6f",
      "occurredAt": "2026-11-16T07:58:47.036Z",
      "operation": "posts.drafts.delete",
      "status": 404,
      "errorCode": "post_not_found",
      "actor": { "_tag": "apiKey", "apiKeyId": "k7Qp2mXvT9aLw3ZsB4nE" },
      "via": "apiKey",
      "application": {
        "id": "k7Qp2mXvT9aLw3ZsB4nE",
        "name": "Newsletter script"
      },
      "impersonated": false,
      "objectIds": { "postId": "019a6c3f-1b72-7d3c-8e90-4f5a6b7c8d02" },
      "requestId": "019a7b30-6f17-7e02-b6a4-9f8e7d6c5b4a"
    }
  ],
  "nextCursor": "MDE5YTdiMzAtNmYxOC03YTk1LTlkMDctMWMyYjNhNGQ1ZTZm"
}

Pass the nextCursor above to get the next page. The SDKs have no helper that reads every page for you, so each one shows the loop:

let cursor: string | undefined;

do {
  const page = await peal.workspace.activity.list({ limit: "100", cursor });

  for (const entry of page.items) {
    console.log(entry.operation, entry.status);
  }

  cursor = page.nextCursor ?? undefined;
} while (cursor !== undefined);
cursor = None

while True:
    page = peal.workspace.activity.list(limit="100", cursor=cursor)

    for entry in page.items:
        print(entry.operation, entry.status)

    cursor = page.next_cursor
    if cursor is None:
        break
var cursor *string

for {
	page, err := client.Workspace.Activity.List(ctx, &workspace.ListActivityRequest{
		Limit:  peal.String("100"),
		Cursor: cursor,
	})
	if err != nil {
		return err
	}

	for _, entry := range page.Items {
		fmt.Println(entry.Operation)
	}

	if page.NextCursor == nil {
		break
	}
	cursor = page.NextCursor
}
cursor = nil

loop do
  # Send `cursor` only when there is one.
  query = { limit: "100" }
  query[:cursor] = cursor if cursor

  page = peal.workspace.activity.list(**query)

  page.items.each { |entry| puts "#{entry.operation} #{entry.status}" }

  cursor = page.next_cursor
  break if cursor.nil?
end
import java.util.Optional;
import social.peal.types.ActivityEvent;

Optional<String> cursor = Optional.empty();

do {
    ActivityPage page = peal.workspace().activity().list(ListActivityRequest.builder()
        .limit("100")
        .cursor(cursor)
        .build());

    for (ActivityEvent entry : page.getItems()) {
        System.out.println(entry.getOperation() + " " + entry.getStatus().orElse(null));
    }

    cursor = page.getNextCursor();
} while (cursor.isPresent());
$cursor = null;

do {
    $page = $peal->workspace->activity->list(new ListActivityRequest([
        'limit' => '100',
        'cursor' => $cursor,
    ]));

    foreach ($page->items as $entry) {
        echo $entry->operation, ' ', $entry->status, PHP_EOL;
    }

    $cursor = $page->nextCursor;
} while ($cursor !== null);
string? cursor = null;

do
{
    var page = await peal.Workspace.Activity.ListAsync(new ListActivityRequest
    {
        Limit = "100",
        Cursor = cursor,
    });

    foreach (var entry in page.Items)
    {
        Console.WriteLine($"{entry.Operation} {entry.Status}");
    }

    cursor = page.NextCursor;
} while (cursor != null);
let mut cursor: Option<String> = None;

loop {
    let page = peal
        .workspace
        .activity
        .list(
            &WorkspaceActivityListQueryRequest {
                limit: Some("100".to_string()),
                cursor: cursor.clone(),
                ..Default::default()
            },
            None,
        )
        .await?;

    for entry in &page.items {
        println!("{} {:?}", entry.operation, entry.status);
    }

    cursor = page.next_cursor;
    if cursor.is_none() {
        break;
    }
}
curl "https://api.example.com/api/v1/workspace/activity?limit=2&cursor=MDE5YTdiMzAtNmYxOC03YTk1LTlkMDctMWMyYjNhNGQ1ZTZm" \
  -H "Authorization: Bearer $PEAL_API_KEY"

Lists that take a range

Two lists take a range instead, and answer everything in it at once:

List What it answers Range Otherwise
GET …/posts/calendar?from=…&to=… The posts scheduled between two instants, from included and to excluded At most 62 days apart invalid_time_range
GET …/analytics/summary?from=…&to=…&timeZone=… A sum of the posts published over a range of days, both included 366 days at most invalid_date_range

The lists a workspace keeps short come whole, as an array: its channels, members, pending invitations, API keys and webhook endpoints.

Was this page helpful?