Quickstart - Paragraph
Getting started
Follow these steps to install & use the Paragraph typescript SDK.
Prerequisites:
- Node.js version 18 or higher
- Install the Paragraph SDK
npm i @paragraph-com/sdk
- Instantiate the class
Instantiate theParagraphAPIclass.
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" })
- Query data
Query Paragraph data. All calls can be found in the SDK repo or on our API reference.
// Fetch a publication by slug (use .single() for single object)
const publication = await api.publications.get({ slug: "@blog" }).single()
console.log(`Fetched publication: ${publication}`)
// Fetch posts (paginated list)
const { items: posts, pagination } = await api.posts.get({ publicationId: publication.id })
console.log(`Fetched ${posts.length} posts from @blog, out of ${pagination.total} posts: ${JSON.stringify(posts)}`)