---
title: Send a document for signature from TypeScript
description: Send a document for signature from TypeScript, with a program that was run against Docustay before it was put here.
---

# Send a document for signature from TypeScript

npm install @docustay/sdk

The types ship inside the package: SendRequest describes what you send and the answer is typed too, so a wrong field name fails in your editor and not at 2 a.m. The program runs as it stands on Node 22 and newer with --experimental-strip-types; elsewhere compile it with tsc as usual.

```js
import { Docustay, type SendRequest } from "@docustay/sdk";

const docustay = new Docustay(process.env.DOCUSTAY_API_KEY!, process.env.DOCUSTAY_URL ? { baseUrl: process.env.DOCUSTAY_URL } : {});
const request: SendRequest = {
  templateId: process.env.DOCUSTAY_TEMPLATE_ID!,
  parties: [{ seat: "signer_1", name: "Pat Example", email: "pat@example.com" }],
};
const doc = await docustay.sendDocument(request);
console.log(doc.id, doc.state);
```

It reads DOCUSTAY_API_KEY and DOCUSTAY_TEMPLATE_ID from the environment. Use a test key first: it sends nothing real and bills nothing.

## Types come with the package

Install the same npm package as for JavaScript; the type declarations ship inside it, so there is no separate types package to add. Parties, templates, documents and webhook events are typed, which means the editor tells you that a party needs a seat and an email before the program ever runs. Compile with tsc or run it directly with a loader such as tsx.

## Configuration in the program

Read DOCUSTAY_KEY and TEMPLATE_ID from process.env and fail early if either is missing; the compiler cannot know they are set. Keep the key out of source control, and use a test key while you are building: a test key can only create TEST documents that email you, so a mistake in a loop costs nothing and reaches nobody.

## Narrowing the answer

The state of a document is a union of strings, so a switch over it is checked for completeness: add a case for declined and expired, or the compiler points at the gap. The same goes for the webhook event type. That is the main reason to prefer this page to the JavaScript one when you write more than a few lines.

## Questions people ask

**Does a test key send real email?**

No. A test key emails only you, stamps the document TEST and is never counted against your plan.

**Do I need a tsconfig?**

Only the usual one for your project. The package works with module resolution set to node16, nodenext or bundler.

**Where do I see the result?**

In Documents in the app, and in the API log under Developers.

## Keep reading

- [Quick start](/docs/quickstart)
- [API reference](/docs/api-reference)
- [Webhooks](/docs/webhooks)
- [SDKs](/developers/sdks)
- [Test mode](/docs/test-mode)
- [Sending](/product/sending)
