> For the complete documentation index, see [llms.txt](https://dfend.gitbook.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfend.gitbook.io/documentation/developer-api/setup.md).

# Setup

Using our API and/or partner connections, you will:

* Create an [**Identity**](/documentation/developer-api/types/identity.md) for each user of your application or service.&#x20;
* Configure a data source to send us [**Signals**](/documentation/developer-api/types/signal.md)**.**
  * A data source can be your application or service, or partner integration.
* Configure a [**webhook**](/documentation/developer-api/webhook.md) to handle [**Events**](/documentation/developer-api/types/event.md). When we detect suspicious behavior or handle user responses, we will send Events to your webhook.

{% hint style="info" %}
Identities can be created on the fly if you include secondary [Identifiers](/documentation/developer-api/types/identifiers.md) in a Signal. We will only trust this data if it is sent from a server environment using your secret API key.
{% endhint %}

## Connections

You can leverage our integration with Google Workspace to protect your internal team. Upon setup, DFend will ingest and analyze signals from Google Workspace audit logs.

{% hint style="info" %}
Found in **Dashboard** under [Setup > Connections](https://dashboard.dfend.app/dashboard/setup/connections).
{% endhint %}

## Quick Start

<details>

<summary>Node.js</summary>

### Set up a webhook

For example, at `yourdomain.com` using [Express](https://expressjs.com), accepting the POST method. You would additionally need to configure this to accept HTTPS requests. We recommend using a cloud function that provides this for you automatically.

```typescript
import express from 'express';
import cors from 'cors';

const app = express();
app.use(cors());
app.use(express.json());

app.post('/', (req, res) => {
  const { event } = req.body;
  console.log('Event received from DFend:', event);
  // TODO: Switch on `event.type` and handle the event.
  res.status(200).json({ message: 'ok' });
});

app.listen(process.env.PORT, () =>
  console.log(`DFend webhook listening on port ${process.env.PORT}!`),
);
```

Add the URL and method of your webhook in **Dashboard** under [Setup > Routing](https://dashboard.dfend.app/dashboard/setup/routing).

### Try the DFend API

#### Server code

The following example uses the [DFend Boilerplate for Node.js](/documentation/developer-api/boilerplates/node.js.md).

```typescript
// Import the DFend Boilerplate for Node.js.
import { identity, signal } from 'dfend.js';

try {
  // Create an Identity.
  const { id, created, merged } = await identity.post({
    userId: 'PU4ME2B68N8K6xz0Ku0BQ',
    name: 'Jane Doe',
    email: 'jane@yourdomain.com',
    phone: '+15435551234',
    merge: true,
    metadata: {
      test: true
    }
  });
  console.log('[DFend] identity created:', id);
  // You can now send signals to DFend with the Identity ID or user ID.
} catch (e) {
  console.error(e);
}
```

#### Client code (web browser)

<pre class="language-html"><code class="lang-html">&#x3C;!DOCTYPE html>
&#x3C;html>
  &#x3C;head>
    &#x3C;title>DFend Test&#x3C;/title>
    &#x3C;script src="https://js.dfend.app/sdk/v0/client.js">&#x3C;/script>
    &#x3C;script>
      const dfend = DFend('&#x3C;Publishable API Key>');
      const userId = 'PU4ME2B68N8K6xz0Ku0BQ';
      (async () => {
<strong>        const data = await dfend.push({
</strong>          type: 'PageLoad',
          identifiers: {
            userId
          }
        });
        // View in the browser console.
        console.log('[DFend] signal push response:', data);
      })();
    &#x3C;/script>
  &#x3C;/head>
  &#x3C;body>
  &#x3C;/body>
&#x3C;/html>

</code></pre>

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dfend.gitbook.io/documentation/developer-api/setup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
