JavaScript
Publish and manage content from Node or the browser
The JavaScript SDK works in Node 18+ and modern browsers. It ships with TypeScript types out of the box.
Install
npm install @firmreader/sdkInitialize the client
import { Firmreader } from "@firmreader/sdk";
const client = new Firmreader({
apiKey: process.env.FIRMREADER_API_KEY, // fr_live_...
});
Create a post
const post = await client.posts.create({
channelId: "ch_company_news",
title: "Welcome to Firmreader",
body: "We're excited to announce our new internal communications platform.",
priority: "normal",
});
console.log(`Published post ${post.id}`);
List posts
const { data: posts } = await client.posts.list({
channelId: "ch_company_news",
limit: 20,
});
for (const post of posts) {
console.log(post.title);
}
Handle errors
The client throws FirmreaderError for non-2xx responses. Inspect status and code to branch on the failure.
import { FirmreaderError } from "@firmreader/sdk";
try {
await client.posts.create({ channelId: "ch_invalid", title: "Hi", body: "..." });
} catch (err) {
if (err instanceof FirmreaderError) {
console.error(`${err.status}: ${err.code}`);
}
}
All write methods are idempotent when you pass an idempotencyKey option, so retries won't create duplicate posts.
