---
title: JavaScript
description: >-
  Scopri come installare e usare l’SDK JavaScript di Firmreader in Node 18+ e nei browser moderni, con supporto completo a TypeScript già incluso.
lastUpdated: "2026-08-17"
---

> **For AI agents:** the complete documentation index is at [llms.txt](/llms.txt). Append `.md` to any page URL for its markdown version.

L’SDK JavaScript funziona in Node 18+ e nei browser moderni. Include i tipi TypeScript già pronti all’uso.

## Installazione

<CodeGroup>
```bash npm
npm install @firmreader/sdk
```

```bash yarn
yarn add @firmreader/sdk
```

```bash pnpm
pnpm add @firmreader/sdk
```
</CodeGroup>

## Inizializzare il client

```javascript
import { Firmreader } from "@firmreader/sdk";

const client = new Firmreader({
  apiKey: process.env.FIRMREADER_API_KEY, // fr_live_...
});
```

## Creare un post

```javascript
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}`);
```

## Elencare i post

```javascript
const { data: posts } = await client.posts.list({
  channelId: "ch_company_news",
  limit: 20,
});

for (const post of posts) {
  console.log(post.title);
}
```

## Gestire gli errori

Il client genera `FirmreaderError` per le risposte non-2xx. Controlla `status` e `code` per gestire il tipo di errore.

```javascript
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}`);
  }
}
```

<Note>
Tutti i metodi di scrittura sono idempotenti quando passi un’opzione `idempotencyKey`, quindi i tentativi ripetuti non creeranno post duplicati.
</Note>
