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

# Move a sender to a new door key

> Give a system a new door key without losing any of its events.

Do this when your own rules ask for new keys from time to time.
A new key does not turn off the old one, as the last section says.

## Before you start

* A role in Casefile that may make keys, such as admin.
* Access to where the sending system keeps its key, such as a secret store.

## Steps

**1. Make a new key**

In Casefile, open the organization menu, then Settings, then Sources and keys.
Enter the system's source name, choose Make a key, and copy the key.
It is shown only once.
A key works for every source in your organization, so the name only fills in the command on the screen.

**2. Try the new key**

Put the new key in `CASEFILE_KEY` and send one event.

```bash curl theme={null}
# Sends one event with your door key, which CASEFILE_KEY holds.
curl --fail-with-body --silent --show-error \
  -X POST "${CASEFILE_DOOR:-https://ingest.casefile.win}/events" \
  -H "authorization: Bearer $CASEFILE_KEY" \
  -H 'content-type: application/json' \
  -d '{"id":"first-event","source":"checkout","name":"hello","occurredAt":"'"$(date -u +%Y-%m-%dT%H:%M:%SZ)"'"}'
```

```javascript Node theme={null}
// Sends one event with your door key, which CASEFILE_KEY holds.
const door = process.env.CASEFILE_DOOR ?? 'https://ingest.casefile.win'

const response = await fetch(`${door}/events`, {
  method: 'POST',
  headers: {
    authorization: `Bearer ${process.env.CASEFILE_KEY}`,
    'content-type': 'application/json',
  },
  body: JSON.stringify({
    id: 'first-event-from-node',
    source: 'checkout',
    name: 'hello',
    occurredAt: new Date().toISOString(),
  }),
})
console.log(response.status, await response.json())
if (!response.ok) process.exitCode = 1
```

The door answers `202` with your event's ID in `accepted`.

The door can refuse a new key with `unknown key` for up to 5 seconds after it is made.
If it does, send the same event again.

**3. Give the system the new key**

Replace the old key where the system reads it, then restart or redeploy the system so it reads the new one.
Events it sends with the old key in the meantime are still accepted, so none are lost.

> [!TIP]
>
> The new key got `202` from the door, and Data health shows the system's events
> arriving after its restart.

## The old key

The app cannot turn off a door key, so the old key keeps working.
Keep it as secret as the new one.


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