> Get an API key and use Node.js fetch to create a private Revdoku inbox. Complete JavaScript example, setup instructions, and next steps for incoming email.

# Connect to the Revdoku API with JavaScript

Create a private bucket with its own email address using Node.js 22+ and native `fetch`. No npm package is needed.

[API overview](/api/) · [Python example](/api-python/) · [C# (.NET) example](/api-dotnet/)

## 1. Get an API key

Sign in to Revdoku, then open Account → Access and choose Add connection → Create API key . Named API keys require a paid plan. For this example, choose bucket_admin permission and access to all buckets in the account where you want to create the inbox.

Set REVDOKU_API_KEY privately in the terminal where you will run the example, or through your secret manager. On macOS or Linux, enter the key at the hidden prompt:

printf 'Revdoku API key: '
read -r -s REVDOKU_API_KEY
export REVDOKU_API_KEY
printf '\n'
For PowerShell 7:

$env:REVDOKU_API_KEY = Read-Host "Revdoku API key" -MaskInput
Run the code on your machine or server. Keep the key out of browser code, shared files, and source control.

## 2. Create an inbox

Save this complete example as `inbox.mjs`. It sends one authenticated request and prints the bucket ID, email address, receiving state, and dashboard link.

const apiKey = process.env.REVDOKU_API_KEY; // Get a key at https://app.revdoku.com/account/access
if (!apiKey) throw new Error("Set REVDOKU_API_KEY first");

const response = await fetch(
"https://app.revdoku.com/api/v1/buckets", {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json"
},
body: JSON.stringify({ bucket: { title: "My agent inbox" } })
}
);
if (!response.ok) {
throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
const { data } = await response.json();
const inbox = data.bucket.inbound_email;
console.log("Bucket ID:", data.bucket.id);
console.log("Email:", inbox.address);
console.log("Ready:", inbox.ready);
console.log("Open:", data.bucket.dashboard_url);
if (!inbox.ready) console.log("Receiving:", inbox.blocked_reason);

Run it from the terminal where you set `REVDOKU_API_KEY`:

```sh
node inbox.mjs
```

Each run creates a new private bucket. Save the returned bucket ID and reuse it for later requests. The key’s default account is used; see [account selection](/api.md#agency-account-selection) when working across accounts.

## 3. Receive and read an email

When `Ready` is true, send a test email from your normal email account to the printed address. If it is false, check `Receiving` for the reason and inspect the existing bucket’s receiving state. New addresses can take up to five minutes to activate; rerunning this script creates another bucket.

Follow the [send and read walkthrough](/api/#send-a-test-email) using the bucket ID printed by this example. Incoming messages are stored as JSON and Markdown alongside their attachments. The dashboard link lets authorized people review them in Revdoku.

For authentication and permission failures, see [troubleshooting](/api/#if-a-request-fails). For all operations, see the [API reference](/api.md).

---

[View the canonical page](https://revdoku.com/api-javascript/) · [Browse llms.txt](https://revdoku.com/llms.txt)
