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

> ## Agent Instructions
> Bridge exposes three integration surfaces: the REST Integrations API for pushing data into Bridge, webhooks for receiving events from Bridge, and the public Custom Connections endpoint that a tenant's landing page posts to.
> The Integrations API host is https://api-connect-us.bridge.new and every request to it must be authenticated with the x-api-key header. Bridge does not use bearer tokens or OAuth.
> The Custom Connections endpoint is different and the Integrations API rules do not apply to it: it has its own host, it takes no x-api-key and no authentication header of any kind, and it is called from a visitor's browser. It is identified by a workspace id and a capture key together with a reCAPTCHA token. Never tell a reader to authenticate it with an API key, and never tell them to keep its capture key out of frontend code - it is designed to live in the page.
> REST error catalog keys use BRIDGE_<DOMAIN>_<NNNN>, for example BRIDGE_CONVERSATION_0001. Some reviewed legacy handlers return a recognized code plus a symbolic suffix separated by |; preserve the complete received value and use the compatible catalog lookup on /error-codes. Custom Connections uses separate BRIDGE.CAMPAIGN_LEADS.<NAME> identifiers on its own error reference. Never invent an error code or confuse the two integration surfaces.
> This documentation covers the Integrations API, webhooks and Custom Connections only. It does not describe the Bridge web application or its internal APIs.
> Before generating an API request, read the relevant OpenAPI specification or the individual endpoint Markdown page. llms-full.txt collects guides and endpoint descriptions; it does not embed every request and response schema. The REST and Custom Connections contracts are separate.
> Preserve the published host, method, path, operationId, authentication, headers, parameter and field names, types, formats, required and nullable fields, enums, defaults, limits, and response codes. Do not invent identifiers, fields, retry rules, or delivery guarantees. When published sources conflict, identify the conflicting passages and ask Bridge support to confirm the current behavior before relying on it.
> Custom Connections is the current name of the landing-page feature previously documented as Lead Capture. The existing /lead-capture documentation URLs, captureKey field, campaign-leads endpoint, and BRIDGE.CAMPAIGN_LEADS error identifiers are unchanged. This is a naming change, not a change to authentication or the API contract.
> For a complete workflow, start with the task guides: /guides/first-conversation, /guides/send-attachments, /guides/send-template, /guides/agent-outbound, /guides/pagination, /guides/identifiers and /guides/responses. Read the endpoint contract as well as the recipe. Outbound requires an existing Contact, but does not require creating a separate Conversation first.
> forceSend=true permits reuse of an existing active conversation; it does not create a fresh one by ignoring it and it is not idempotency. Recovery of a released recoverable conversation can occur even with false. The LeadScout and Agents outbound routes have different line-selection and controller checks; use /guides/agent-outbound.
> For webhook HMAC, follow /webhooks/verifying-signatures exactly: the Python JSON serialization with sorted keys is signed; X-Bridge-Timestamp is not included in that signature. Do not claim a signed timestamp, raw-body signing, exactly-once delivery or a global event order. Use /webhooks/receive-events for durable acceptance and duplicates.
> A 201 message response, 202 handoff or 202 Custom Connections response is not a provider delivery receipt. Do not invent a polling endpoint from messageId, trackingId or requestId. REST validation parsing must tolerate the compatibility difference explained in /error-codes.
> The documentation is available in English (existing root URLs), Spanish (/es/) and Brazilian Portuguese (/pt-br/). Prefer the reader's language when a localized page exists, but preserve the API's exact field names, enums, routes, authentication and examples. Translations describe the same API; they do not introduce regional API hosts or behaviors.
> For coding-assistant setup, use /connect-your-agent, /es/connect-your-agent or /pt-br/connect-your-agent. The Bridge documentation MCP server reads published documentation and has a separate optional feedback tool. Connecting it does not connect the coding assistant to a customer workspace or authorize live business requests.
> For direct HTTP access without MCP, start at https://docs.bridge.new/llms.txt. It lists every published page in English, Spanish and Brazilian Portuguese. Choose /llms-en.json, /llms-es.json or /llms-pt-br.json for a language-specific index, and /llms-full-en.json, /llms-full-es.json or /llms-full-pt-br.json for collected content. /llms-full.txt contains the combined collection. Fetch the original OpenAPI specification for exact schemas.
> For HTTP page reads, follow the .md URLs from the index or request Accept: text/markdown at the canonical page URL. The MCP virtual filesystem uses .mdx page paths instead; .mdx is not the public HTTP export extension. With Search MCP, set language to en, es or pt-BR explicitly; its default is en.
> For integration capabilities and source-selection rules, read https://docs.bridge.new/skill.md. Documentation access does not authorize business API actions; use the actual user request, workspace, credentials and target identifiers for any live integration.

# Create a contact and send a message

> Follow a complete server-side flow from a Contact to a Conversation and a Message, preserving the returned identifiers.

This recipe creates a Contact, starts a Conversation with an internal Bridge User, and creates a Message. Run it on your server.

> [!WARNING]
>
> Use a test Contact you are authorized to message. Creating a Conversation can run the workspace's onboarding templates before the separate Message request. Review that configuration first; setting the later Message's broadcast flag to false does not disable Conversation onboarding.

## Before you start

* Get a server-side API Key from [Authentication](https://docs.bridge.new/credentials.md).
* Obtain your workspace ID, an active WhatsApp line's `providerChannelId`, and an internal Bridge User's email. See [Identifiers and concepts](https://docs.bridge.new/guides/identifiers.md).
* Use a new test phone number in international format. If the Contact already exists, use [contact lookup](https://docs.bridge.new/api-reference/contacts-api/retrieve-a-contact-by-an-identifier.md) instead of creating it again.
* Check any required custom attributes and the workspace's onboarding sequence. This minimal example does not supply custom attributes or override templates.
* Choose `enableExternalBroadcast` explicitly: `true` requests external delivery when conversation and recipient rules permit it; `false` still creates the Message but skips external broadcast. Neither value confirms provider delivery. This flag does not override visibility or permissions.

## The sequence

| Step | Request | Value to keep |
| - | - | - |
| Check access | `GET /bridge/api/health` | Successful HTTP response |
| Create Contact | `POST /bridge/api/v1/workspaces/{workspaceId}/contacts` | Contact `id` |
| Start Conversation | `POST /bridge/api/v1/workspaces/{workspaceId}/conversations` | Conversation `id` |
| Create Message | `POST /bridge/api/v1/workspaces/{workspaceId}/messages` | `messageId` |

The Contact's `id` becomes the external participant's `identifier` with `identifierType: "ID"`. The Conversation's `id` becomes the Message's `conversationId`.

## Run the example

Use Node.js with built-in `fetch`. Save this as `first-conversation.mjs`. Supply these environment variables through your server's secret and configuration settings:

| Variable | Value |
| - | - |
| `BRIDGE_API_KEY` | Your secret API Key |
| `BRIDGE_WORKSPACE_ID` | The intended workspace ID |
| `BRIDGE_PROVIDER_CHANNEL_ID` | The authorized WhatsApp line ID, not its phone number |
| `BRIDGE_USER_EMAIL` | An internal Bridge User in the same workspace |
| `TEST_CONTACT_PHONE` | A new, authorized test Contact's phone number |
| `ENABLE_EXTERNAL_BROADCAST` | Exactly `true` or `false`; no default is assumed |

The names and message below are examples. Replace them with your intended test content before running.

```javascript theme={null}
const BASE = "https://api-connect-us.bridge.new";

function required(name) {
  const value = process.env[name];
  if (!value) throw new Error(`Set ${name} before running this example.`);
  return value;
}

const apiKey = required("BRIDGE_API_KEY");
const workspaceId = required("BRIDGE_WORKSPACE_ID");
const providerChannelId = required("BRIDGE_PROVIDER_CHANNEL_ID");
const internalEmail = required("BRIDGE_USER_EMAIL");
const cellphone = required("TEST_CONTACT_PHONE");
const broadcast = required("ENABLE_EXTERNAL_BROADCAST");
if (!["true", "false"].includes(broadcast)) {
  throw new Error("ENABLE_EXTERNAL_BROADCAST must be true or false.");
}
const workspacePath = `/bridge/api/v1/workspaces/${encodeURIComponent(workspaceId)}`;

async function request(method, path, body, expectedStatus) {
  const response = await fetch(`${BASE}${path}`, {
    method,
    headers: {
      "x-api-key": apiKey,
      ...(body === undefined ? {} : { "Content-Type": "application/json" }),
    },
    ...(body === undefined ? {} : { body: JSON.stringify(body) }),
  });
  const result = await response.json().catch(() => null);
  if (response.status !== expectedStatus) {
    const code = result?.code ? ` (${result.code})` : "";
    throw new Error(`${method} ${path}: HTTP ${response.status}${code}`);
  }
  return result;
}

await request("GET", "/bridge/api/health", undefined, 200);

const contact = await request("POST", `${workspacePath}/contacts`, {
  firstName: "Alex",
  lastName: "Example",
  languageCode: "EN",
  cellphone,
}, 201);
if (!contact?.id || contact.workspaceId !== workspaceId) {
  throw new Error("The Contact response does not identify the intended workspace.");
}

const conversation = await request("POST", `${workspacePath}/conversations`, {
  participants: {
    externals: [{
      identifier: contact.id,
      identifierType: "ID",
      messageProviderType: "WHATSAPP",
      providerChannelId,
    }],
    internals: [{ identifier: internalEmail, identifierType: "EMAIL" }],
  },
  name: "Integration test",
  status: "ACTIVE",
}, 201);
if (!conversation?.id || conversation.workspaceId !== workspaceId) {
  throw new Error("The Conversation response does not identify the intended workspace.");
}

const message = await request("POST", `${workspacePath}/messages`, {
  conversationId: conversation.id,
  messageBody: "Hello from our authorized Bridge integration test.",
  enableExternalBroadcast: broadcast === "true",
}, 201);
if (!message?.messageId) throw new Error("The Message response has no messageId.");

console.log({
  contactId: contact.id,
  conversationId: conversation.id,
  messageId: message.messageId,
});
```

```bash theme={null}
node first-conversation.mjs
```

## Understand the result

* A `201` Contact response gives you the Contact's identity and workspace. Read `type` to see its actual `NORMAL` or `PARTIAL` classification.
* A `201` Conversation response gives you the ID to use next. When no line is free, Bridge can recover a released Conversation with exactly the requested participants. That keeps its ID and history; the requested `name` and `status` are not applied in that recovery case.
* A `201` Message response supplies `messageId`. It does not by itself prove that WhatsApp delivered the message to the Contact.

This recipe explicitly assigns an internal Bridge User. For a team assignment, use the documented `teamId` option instead of `participants.internals`; they are mutually exclusive.

## If a step fails

The example stops at the failed request and never retries a write automatically. A network failure can leave the outcome uncertain. Check the relevant resource before repeating a create or send operation.

| Situation | Next action |
| - | - |
| Contact already exists | Use contact lookup and its returned `id`; do not keep creating the same Contact. |
| Brand or line error | Confirm the authorized line or brand with your administrator; a line's phone number is not its ID. |
| Template `0604`–`0608` | Follow [WhatsApp template parameters](https://docs.bridge.new/templates-and-parameters.md), including workspace configuration errors. |
| Message rejected because the Conversation is released | Inspect the Conversation's state and the operation's error reference before taking another action. |
| `429` | Follow [Rate limits](https://docs.bridge.new/rate-limits.md), including `Retry-After`. |

See [Responses and errors](https://docs.bridge.new/guides/responses.md) for response shapes and recovery decisions.

## Next steps

* [Upload and send an attachment](https://docs.bridge.new/guides/send-attachments.md).
* [Choose and fill a WhatsApp template](https://docs.bridge.new/guides/send-template.md).
* [Create a Contact](https://docs.bridge.new/api-reference/contacts-api/create-a-new-contact.md), [create a Conversation](https://docs.bridge.new/api-reference/conversations-api/creates-a-new-conversation-with-flexible-user-identification.md), and [create a Message](https://docs.bridge.new/api-reference/messages-api/create-a-new-message.md) for the complete request and response contracts.


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