Managing Views
Bookmark Pagination Overview
Throughout the BitBadges API, we use a bookmark-based pagination system for efficient data retrieval. This system is particularly useful when dealing with large datasets that need to be fetched in smaller chunks.
Some endpoints like the get accounts or get collections will use a generic viewsToFetch and views object which can maintain multiple paginated views. Some endpoints will request the bookmark directly. Refer to the documentation for each endpoint to see how it handles pagination.
How Bookmark Pagination Works
First Request: For your initial request, use an empty bookmark string (
""
).
Response Structure: Each paginated response includes:
The requested data
A
bookmark
string for the next pageA
hasMore
boolean indicating if more data exists
Subsequent Requests: To fetch the next page, use the bookmark from the previous response:
Completion: Continue this process until
hasMore
isfalse
.
Understanding the Views Object
The views object is a central concept in the BitBadges API, used to manage paginated data across different interfaces (BitBadgesCollection, BitBadgesAddressList, BitBadgesUserInfo, etc). It follows this structure:
Key Components
viewId: A unique identifier for the view
ids: Array of document IDs that correspond to full documents in the response
pagination: Contains the bookmark and hasMore flag
type: Indicates the type of view (e.g., 'owners', 'activity', etc.)
Document ID Mapping
Documents in the response are referenced by their _docId
field. To access the full document, you map the IDs from the view to the corresponding array in the response. For example, the activity view documents are stored in the activity
array, and the view IDs are stored in the views.activity.ids
array.
Common View Types
Different interfaces support different view types. See the corresponding documentation for each interface to see what views are supported.
Collections Interface
owners
: List of badge ownersactivity
: Transfer activityapprovalTrackers
: Approval tracking documents
See all at CollectionViewKey
Account Interface
transferActivity
: User's transfer historybadgesCollected
: Badges owned by the usercreatedBadges
: Collections created by the usermanagingBadges
: Collections being managedallLists
: Address lists the user is on
See all at AccountViewKey
Helper Functions
The BitBadges SDK provides several helper functions for managing views:
Best Practices
Consistent ViewIds: Use consistent viewIds when paginating through the same dataset
Error Handling: Always check for undefined views before accessing
Document Mapping: Use helper functions when available for mapping IDs to documents
Pagination State: Track both bookmark and hasMore status for proper pagination
Response Merging: Remember that each response is confined to its request - use helper functions or manually merge data as needed
Last updated