> ## Documentation Index
> Fetch the complete documentation index at: https://docs.thewo.io/llms.txt
> Use this file to discover all available pages before exploring further.

# TypeScript example

> Call the Trade Document extraction endpoint from a trusted server.

# TypeScript example

This example uses Node.js `fetch` from a trusted server. Keep `THE_WO_API_KEY`
in a secret manager or server environment variable. Do not call this protected
endpoint directly from public browser or mobile code.

```ts theme={"theme":"github-dark-default"}
const apiBaseUrl = process.env.THE_WO_API_BASE_URL ?? "https://api.thewo.io";
const apiKey = process.env.THE_WO_API_KEY;

if (!apiKey) {
  throw new Error("THE_WO_API_KEY is required");
}

const response = await fetch(`${apiBaseUrl}/v1/documents/extract`, {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": apiKey,
    "idempotency-key": "invoice-import-2026-10-19-104",
  },
  body: JSON.stringify({
    documentUrl: "https://example.com/documents/sample-invoice.pdf",
    expectedType: "invoice",
    language: "en",
  }),
});

const result: unknown = await response.json();

if (!response.ok) {
  console.error("Trade Document request failed", {
    status: response.status,
    result,
  });
  throw new Error("Document extraction failed");
}

console.log(result);
```

The API returns `201 Created` for a completed extraction. Inspect `documentType`,
`extracted`, `missingFields`, `riskFlags`, `confidence`, and `usage` in the
response. See the [document contract](https://docs.thewo.io/trade-document/guides/document-contract.md)
for response fields and [Errors](https://docs.thewo.io/trade-document/guides/errors.md) for error
handling. The example URL is fictional; replace it with an authorized,
retrievable document URL.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.