Quickstart - Paragraph

Getting started

Follow these steps to install & use the Paragraph typescript SDK.

Prerequisites:

  1. Install the Paragraph SDK
   npm i @paragraph-com/sdk
  1. Instantiate the class
    Instantiate the ParagraphAPI class.
   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" })
  1. 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)}`)