Before running any examples, make sure you have the SDK installed and initialized:
import { ParagraphAPI } from "@paragraph-com/sdk"// For public endpoints (no API key required)const api = new ParagraphAPI()// For protected endpoints (API key required)const apiWithAuth = new ParagraphAPI({ apiKey: "your-api-key" })
Retrieve posts from a publication with pagination support. This example demonstrates how to fetch multiple pages of posts using the cursor-based pagination.
/** * Given a Paragraph publication slug, fetch the first two * pages of posts. */async function fetchParagraphPosts(slug: string) { const publication = await api.publications.get({ slug }).single() console.log("Publication:", publication) const posts = [] const firstBatch = await api.posts.get({ publicationId: publication.id }) posts.push(...firstBatch.items) console.log("Posts:", firstBatch.items) if (firstBatch.pagination.hasMore && firstBatch.pagination.cursor) { const secondBatch = await api.posts.get({ publicationId: publication.id, cursor: firstBatch.pagination.cursor }) posts.push(...secondBatch.items) } console.log(`Last ${posts.length} posts from ${slug}, out of ${firstBatch.pagination.total} posts: ${JSON.stringify(firstBatch.items)}`)}
Example response
Last 2 posts from @blog, out of 39 posts: [ { "id": "jBY6aEvHXTneYkxnHQ9k", "title": "What We're Learning from Coins on Paragraph", "slug": "what-were-learning-from-coins-on-paragraph", "staticHtml": "<h3>Why coins?</h3><p>It's been a little over a month since we...[truncated]", "json": "{\"type\":\"doc\",\"content\":[{\"type\":\"heading\",\"attrs\":{\"textAlign\":\"left\",\"level\":3}...[truncated]", "markdown": "### Why coins?\n\nIt's been a little over a month since we [shipped]...[truncated]", "coinId": "MTmpnfHJWMTcd84d9kWB", "publishedAt": "2025-09-03T14:30:09.640Z", "updatedAt": "2025-09-04T20:33:28.966Z" },]Pagination: { "cursor": "eyJjcmVhdGVkQXQiOiIyMDI1LTA5LTA1VDEwOjE1OjMyLjAwMFoifQ", "hasMore": true, "total": 39}
Retrieve user profile information by wallet address, including any associated Farcaster profiles.
/** * Given a wallet address, fetch the user profile including * any associated Farcaster profile. */async function getUserProfileByWallet(walletAddress: string) { const user = await api.users.get({ wallet: walletAddress }).single() console.log("User profile:", user)}