# Event handlers (IRPCEventHandlersAdmin)

Location: [gRPC API](https://developer.m-files.com/APIs/gRPC-API/index.md) > [Administration API](https://developer.m-files.com/APIs/gRPC-API/admin/index.md)

HTML version: https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/

Reads and replaces the event handlers of a vault or of the server: VBScript code that the server
runs when an event occurs.

MFAdmin uses this interface to admininistrate event handlers.

- **gRPC service:** `MFiles.IRPCEventHandlersAdmin`
- **Book and level:** [Administration API](https://developer.m-files.com/APIs/gRPC-API/admin/index.md), specialized
- **Methods:** 4
- **Proto file:** [`mfiles/IRPCEventHandlersAdmin.proto`](https://developer.m-files.com/APIs/gRPC-API/downloads/proto/mfiles/IRPCEventHandlersAdmin.proto)

<a id="overview"></a>

## Overview

M-Files Admin uses this service for its event handler editor, and vault applications use it to
register their own handlers. An event handler is an
[InternalEventHandler](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.InternalEventHandler/index.md): the event it reacts to
(`event_type`), its position among the handlers of the same event (`sort_index`), `is_active`, a
`description`, and the `code` that the server runs.

- **Vault event handlers** run in one vault:
  [GetVaultEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/GetVaultEventHandlers/index.md),
  [SetVaultEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/SetVaultEventHandlers/index.md). They need
  a vault session.
- **Server event handlers** are stored once for the whole server:
  [GetServerEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/GetServerEventHandlers/index.md),
  [SetServerEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/SetServerEventHandlers/index.md). A
  server-level session is enough.

The `Set` methods replace the whole list: read it, change it, and write all handlers back. To
keep a handler, send it back with its `guid`; a handler left out is removed.

**Rights.** Handler code runs on the server, so writing it needs the right to run code there:

- Server right `run_code` (message `ServerAccess`). Logins with the system administrator server
  role have it. Users with full control of the vault have it only when the server is configured
  to let vault administrators run code. Without it, writing fails with "Editing vault
  application bindings or VBScript code requires system administrator rights.".
- When the server is configured to accept signed scripts, a vault administrator can write vault
  event handlers without `run_code`: each new or changed `code` must then carry a valid digital
  signature, and the caller needs the vault right `run_signed_code` (part of full control).
- Reading vault handlers, including their code, needs only the vault right
  `change_metadata_structure`. Reading server handlers needs `run_code`.

<a id="methods"></a>

## Methods

| Method | Summary | Facts |
|---|---|---|
| [GetServerEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/GetServerEventHandlers/index.md) | Gets all server-level event handlers, with their code. | `admin` `session` `idempotent` |
| [GetVaultEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/GetVaultEventHandlers/index.md) | Gets all event handlers of the vault, with their code. | `admin` `session` `idempotent` |
| [SetServerEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/SetServerEventHandlers/index.md) | Replaces all server-level event handlers with the given list. | `admin` `session` `idempotent` |
| [SetVaultEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/SetVaultEventHandlers/index.md) | Replaces all event handlers of the vault with the given list. | `admin` `session` `idempotent` |
