# rechnungsapi-sdk

> Official TypeScript/JavaScript SDK for RechnungsAPI — create, validate, and analyze ZUGFeRD and X-Invoice e-invoices.

Latest version **0.1.1** (published 2026-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install rechnungsapi-sdk
pnpm add rechnungsapi-sdk
yarn add rechnungsapi-sdk
bun add rechnungsapi-sdk
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2026-09-24 |
| First published | 2026-09-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 68.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Finbc GmbH |
| Maintainers | rechnunsgapi_de |
| Keywords | rechnungsapi, zugferd, xinvoice, xrechnung, e-invoice, invoice |

## Links

- npm: https://www.npmjs.com/package/rechnungsapi-sdk
- Repository: https://github.com/Rechnungsapi/rechnungsapi-sdk
- Homepage: https://rechnungsapi.de
- Issues: https://github.com/Rechnungsapi/rechnungsapi-sdk/issues
- npm.io page: https://npm.io/package/rechnungsapi-sdk

## Recent versions

- 0.1.1 (latest) — 2026-09-24
- 0.1.0 — 2026-09-24

## README

# rechnungsapi-sdk

Official TypeScript/JavaScript SDK for [RechnungsAPI](https://rechnungsapi.de) — create, validate, and analyze ZUGFeRD (PDF/A-3) and X-Invoice (XRechnung/UBL) e-invoices.

## Install

```bash
npm install rechnungsapi-sdk
```

## Get an API token

Every request needs your own Bearer token — there's no shared or default token.

1. Sign in to the dashboard at [rechnungsapi.de](https://rechnungsapi.de) (sign up if you don't have an account yet).
2. Open your **Profile** page and copy the API token at the bottom.
3. Store it as an environment variable — never hardcode it or commit it to source control:
   ```bash
   # .env
   RECHNUNGSAPI_TOKEN=your-token-here
   ```

## Usage

```ts
import { RechnungsApiClient } from "rechnungsapi-sdk"

const client = new RechnungsApiClient({ apiToken: process.env.RECHNUNGSAPI_TOKEN! })

// Create a ZUGFeRD PDF from structured invoice JSON
const result = await client.createZugferdFromJson(
  { invoiceNumber: "RE-2026-001", /* ... */ },
  invoicePdfBase64,
)

// Validate an X-Invoice XML document
const validation = await client.validateXInvoiceXml(xmlString)
if (!validation.isValid) {
  console.log(validation.messages)
}

// Extract structured JSON from a scanned/PDF invoice
const extracted = await client.analyzePdfInvoiceV2(pdfBase64, /* withLineItems */ true)
```

By default the client talks to the production gateway. To test against a sandbox instead (if your account has one), pass `baseUrl`:

```ts
const client = new RechnungsApiClient({
  apiToken: process.env.RECHNUNGSAPI_TOKEN!,
  baseUrl: "https://sandbox.rechnungsapi.de",
})
```

## API

| Method | Description |
|---|---|
| `createZugferdFromJson(invoice, invoicePdf64, options?)` | Create a ZUGFeRD PDF/A-3 from structured invoice JSON |
| `createXInvoiceFromJson(invoice, options?)` | Create an X-Invoice (XRechnung/UBL) XML from structured invoice JSON |
| `createZugferdPdf(invoicePdf64, xInvoiceXml)` | Embed an existing X-Invoice XML into a visual PDF |
| `extractXInvoiceFromZugferd(zugferd64)` | Extract the embedded XRechnung XML from a ZUGFeRD PDF as JSON |
| `validateXInvoiceXml(xml)` | Validate an X-Invoice XML against schema and business rules |
| `validateZugferdPdf(zugferdFile64, options?)` | Validate a ZUGFeRD PDF's embedded XML |
| `analyzePdfInvoice(pdfBase64)` | Extract structured JSON from a PDF/scanned invoice (sync) |
| `analyzePdfInvoiceV2(pdfBase64, withLineItems?)` | High-accuracy analyzer, optional line-item extraction |
| `analyzePdfInvoiceAsync(pdfBase64, withLineItems?)` / `getAnalysisStatus(jobId)` | Async analysis for large files |
| `createZugferdFromPdf(pdfBase64, fileName?)` | Convert a PDF/scan directly into a validated ZUGFeRD PDF |

Errors are thrown as `RechnungsApiError` (with `.status` and `.body`), or `ValidationFailedError` for HTTP 412 responses (missing mandatory invoice fields).

## Development

```bash
yarn install
yarn test
yarn build
```

## License

MIT

---
_Source: https://npm.io/package/rechnungsapi-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
