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

# External Modifications to Access Codes

> How Seam handles an access code that someone changes or removes outside Seam, for example in the lock manufacturer app.

Device owners can change or remove an access code outside Seam, for example in the lock manufacturer's app or on the lock itself. What Seam does next depends on `allow_external_modifications` on the access code.

Seam treats these changes as external modifications:

* The PIN changed.
* The schedule changed.
* The code was removed.
* The code was deactivated: it is still on the device but disabled or suspended. Only some lock providers support this.

A changed name is not an external modification. Lock providers often shorten or change names, so Seam cannot tell a change made outside Seam from one the provider made.

To allow external modifications, set `allow_external_modifications` to `true` when you [create](https://www.seam.co/docs/api/access_codes/create.md) or [update](https://www.seam.co/docs/api/access_codes/update.md) an access code, or when you [convert an unmanaged access code to managed](https://www.seam.co/docs/api/access_codes/unmanaged/convert_to_managed.md). For an example request, see [Managing Access Codes in Manufacturer Apps](https://www.seam.co/docs/low-level-apis/smart-locks/access-codes/accommodating-manufacturer-mobile-apps.md#allow-for-access-code-modification).

## Codes That Do Not Allow External Modifications

By default, Seam keeps the access code on the device the way it is on Seam, and undoes changes made outside Seam.

1. When Seam detects that the PIN or schedule was changed, or that the code was removed or deactivated, it adds a `conflicting_external_modifications` error to the access code and sets the code on the device back to the way it is on Seam. Seam sends no event at this point, and the access code itself does not change.
2. Once the device has the code the way it is on Seam again, the error clears.
3. If the device still does not match one hour after the error was added, Seam emits `access_code.failed_to_revert_external_modifications`. Seam keeps trying, and the error stays until the device matches.

`access_code.failed_to_revert_external_modifications` describes what is still different on the device:

* For a changed PIN or schedule, `modified_from` holds the values Seam set, which should be on the device, and `modified_to` holds the values found on the device. Both are keyed by property: `code`, or `starts_at` and `ends_at`.
* For a removed code, `is_access_code_deleted_externally` is `true`.
* For a deactivated code, `is_access_code_deactivated_externally` is `true`.

```json theme={"dark"}
{
  "event_type": "access_code.failed_to_revert_external_modifications",
  "access_code_id": "...",
  "device_id": "...",
  "modified_from": {
    "code": "1234"
  },
  "modified_to": {
    "code": "5678"
  }
}
```

Some device owners don't expect their changes to be undone, so let them know that Seam resets codes changed or removed outside Seam, or allow external modifications.

## Codes That Allow External Modifications

When a code allows external modifications, Seam follows what the device has.

| Change made outside Seam | What Seam does |
| - | - |
| PIN or schedule changed | Updates the access code on Seam to the new PIN or schedule, and emits `access_code.code_changed` or `access_code.time_frame_changed`. |
| Code removed | Waits to confirm the removal, then deletes the access code and emits `access_code.deleted`. |
| Code deactivated | Leaves the code deactivated. The access code gets the `access_code_inactive` error and the `external_modification_in_effect` warning. If the code is later removed, Seam handles it as a removed code. |

### Confirming a Removal

A code missing from the list a lock provider returns is not proof that it was deleted. Some providers briefly return an incomplete list while the codes are still on the lock. So when a code that allows external modifications goes missing, Seam waits up to one hour before treating it as removed:

* While Seam waits, the access code is unchanged: it still reads as set on the device, with no errors, warnings or events. Seam does not program it onto the device again.
* If the provider lists the code again, nothing changes.
* If the code is still missing after the wait, Seam deletes it as described above.

## Display Status

While an external modification is in effect, the access code's `display_status` shows it:

| `display_status` | When |
| - | - |
| `Reverting external modifications` | A code that does not allow external modifications has the `conflicting_external_modifications` error, and Seam is setting it back. |
| `Deactivated` | A code that allows external modifications was deactivated outside Seam. |
| `Externally modified` | A code that allows external modifications was changed outside Seam and is not set on the device. |

`display_status` is for showing to a person only. Do not build logic on it.

## Events

| Event | When |
| - | - |
| `access_code.failed_to_revert_external_modifications` | Seam could not set a code that does not allow external modifications back to the way it is on Seam within one hour of detecting the change. |
| `access_code.code_changed`, `access_code.time_frame_changed` | The PIN or schedule of a code that allows external modifications was changed outside Seam, and Seam updated the access code to match. |
| `access_code.deleted` | A code that allows external modifications was removed outside Seam, and Seam deleted the access code. |

If you are moving from `access_code.modified_external_to_seam`, `access_code.deleted_external_to_seam`, the `external_modification_in_effect` warning, or `allow_external_modification`, see [Migrating to Access Code Lifecycle Events](https://www.seam.co/docs/low-level-apis/smart-locks/access-codes/migrating-to-access-code-lifecycle-events.md#external-modifications).

See also [Lifecycle of Access Codes](https://www.seam.co/docs/low-level-apis/smart-locks/access-codes/lifecycle-of-access-codes.md) and [Troubleshooting Access Code Issues](https://www.seam.co/docs/low-level-apis/smart-locks/access-codes/troubleshooting-access-code-issues.md).


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