> For the complete documentation index, see [llms.txt](https://cde-inc.gitbook.io/cde-cad-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cde-inc.gitbook.io/cde-cad-documentation/fivem-developer-integration/getting-started.md). Agents can also search and read this documentation through its [MCP server](https://cde-inc.gitbook.io/cde-cad-documentation/~gitbook/mcp).

# Getting Started

## Generate Your API Key

Navigate to **Admin Panel > FiveM Settings** in your CDE CAD dashboard. Click **Generate API Key** to create a new key for your server.

{% hint style="info" %}
Your API key will follow this format:
{% endhint %}

```
fvm_a1b2c3d4e5f6...  (fvm_ prefix + 64 hexadecimal characters)
```

### Authenticate Requests

Send your API key **and** your community's Discord guild ID on every authenticated request. The guild ID is a second factor: it must belong to the community that owns the key, so a leaked key on its own is not enough to talk to your CAD.

{% hint style="warning" %}
Send both on every authenticated request:
{% endhint %}

```
x-api-key: fvm_your_api_key_here
x-community-id: your-discord-guild-id
```

{% hint style="info" %}
`x-community-id` is your `CDE_CAD_COMMUNITY_ID` convar (the Discord guild ID; the Mongo community `_id` is also accepted). It can instead go in a `communityId` body/query field, but the header is preferred: it works on `GET` requests and survives proxies that strip `POST` bodies from non-browser clients.

**Roll-out:** the guild-ID requirement is phased in behind a per-CAD switch. Until your CAD enables it, a key-only request is still accepted and a warning is logged; once enabled, a request with no guild ID is rejected. Send the header now so the switch is a no-op for you.
{% endhint %}

## Configure Your Resource

{% hint style="danger" %}
**Security Warning**

* **Never** expose your API key in client-side scripts. Keep it in server-side files only.
* **Never** commit your API key to public repositories.
* If your key is ever leaked or you suspect abuse, regenerate it immediately from **Admin Panel > FiveM Settings**.
* Always use HTTPS. Never send your API key over plain HTTP.
  {% endhint %}

#### API Settings

For security reasons, CDE CAD credentials are stored in `server.cfg` as convars rather than in resource files. Add the following block to your `server.cfg`:

```
##CDECAD
set CDE_CAD_API_URL "https://your-cdecad-instance.com"
set CDE_CAD_API_KEY "your-fivem-api-key"
set CDE_CAD_COMMUNITY_ID "your-discord-guild-id"
set CDE_CAD_SERVER_NAME "Your Server Name"
```

{% hint style="info" %}
Users will most likely already have those values set as instructed by CDE Support. You will just need to pull/reference them in your server script. See the Wraith ARS example below for how to read convars:
{% endhint %}

```lua
-- server/config.lua
Config = {}
Config.CadUrl     = GetConvar('CDE_CAD_API_URL', 'https://cdecad.com')
Config.ApiKey     = GetConvar('CDE_CAD_API_KEY', '')
Config.CommunityID = GetConvar('CDE_CAD_COMMUNITY_ID', '')
Config.ServerName = GetConvar('CDE_CAD_SERVER_NAME', 'My RP Server')
```

{% hint style="warning" %}
**Base URL**

Set `CDE_CAD_API_URL` to your CAD instance root, with no trailing `/api` and no trailing slash: `https://cdecad.com`, not `https://cdecad.com/` or `https://cdecad.com/api`. Every endpoint path in this documentation already starts with `/api/`, so the prefix is included for you. Putting `/api` on the convar too gives you `/api/api/...`, and a trailing slash gives you a double slash in every request. If you use a custom domain, point the convar at that instead (e.g. `https://cad.yourdomain.com`).
{% endhint %}

## Heartbeat

```
POST /api/fivem/heartbeat
```

Periodic ping that keeps your server's `lastSeen` timestamp fresh and updates player count. Call this on a sensible interval from your server-side script (roughly once a minute is typical).

### Request Body

```json
{
  "playerCount": 45,
  "serverInfo": {  }
}
```

### Response

```json
{ "success": true }
```

## Common Response Codes

| Code          | Meaning                                                                                                             |
| ------------- | ------------------------------------------------------------------------------------------------------------------- |
| `200` / `201` | Success                                                                                                             |
| `400`         | Bad request (missing/invalid fields; or guild ID required but not sent, once your CAD enables guild-ID enforcement) |
| `401`         | Unauthorized (missing or invalid API key)                                                                           |
| `403`         | Forbidden (community deactivated, cross-community attempt, or feature disabled)                                     |
| `404`         | Resource not found                                                                                                  |
| `429`         | Rate limit exceeded; check `Retry-After` header                                                                     |
| `500`         | Server error                                                                                                        |
