Blocks (SDK)
Typed client for reusable content blocks.
Wraps the Blocks REST API with typed methods and a Blocks helper namespace for reading field values.
Methods
inventra.blocks.list(options?)
Lists all published blocks.
const blocks = await inventra.blocks.list();
// With a pages filter:
const homeBlocks = await inventra.blocks.list({ pages: ['home', 'pricing'] });Parameters
| Name | Type | Description |
|---|---|---|
options.pages |
string[] |
Limit to blocks assigned to these pages. |
Returns Promise<Block[]>
inventra.blocks.getBySlug(slug)
Returns a single block by its slug, or throws if not found.
const hero = await inventra.blocks.getBySlug('homepage-hero');Returns Promise<Block>
Block shape
interface Block {
id: string;
slug: string;
name: string;
status: 'published' | 'draft';
fields: BlockField[];
}
interface BlockField {
key: string;
type: 'text' | 'image' | 'video';
value: BlockFieldValue;
}
type BlockFieldValue =
| string
| { url: string; alt: string }
| { url: string; status: 'ready' | 'processing' | 'failed' }
| null;The Blocks helpers
Reading a field's value directly means narrowing the union type yourself. The Blocks static helpers do it for you:
import { Blocks } from 'inventra';
const hero = await inventra.blocks.getBySlug('homepage-hero');
const title = Blocks.getText(hero, 'title'); // string | null
const image = Blocks.getImage(hero, 'background'); // { url, alt } | null
const video = Blocks.getVideo(hero, 'demo'); // { url, status } | nullThese return null if the field doesn't exist or isn't of the expected type — safer than index-based access.
Example: rendering a hero block
import { Inventra, Blocks } from 'inventra';
const inventra = new Inventra({
apiKey: process.env.INVENTRA_API_KEY!,
orgId: process.env.INVENTRA_ORG_ID!
});
export async function HomeHero() {
const hero = await inventra.blocks.getBySlug('homepage-hero');
const title = Blocks.getText(hero, 'title');
const image = Blocks.getImage(hero, 'background');
return (
<section>
{image && <img src={image.url} alt={image.alt} />}
<h1>{title}</h1>
</section>
);
}