# IRPCEventHandlersAdmin.SetVaultEventHandlers

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) > [Event handlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/index.md)

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

Badges: `Administration API / specialized` `admin` `session` `idempotent`

Replaces all event handlers of the vault with the given list.

- **Service:** [Event handlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/index.md) `MFiles.IRPCEventHandlersAdmin`
- **gRPC method:** `/MFiles.IRPCEventHandlersAdmin/SetVaultEventHandlers`
- **HTTP (mf-http-grpc):** `POST /grpc/v1/set-vault-event-handlers`
- **Request:** [`SetVaultEventHandlersRequest`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/SetVaultEventHandlers/index.md#request)
- **Response:** [`SetVaultEventHandlersResponse`](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/SetVaultEventHandlers/index.md#response)
- **Book and level:** Administration API, specialized
- **Kind:** admin
- **Session:** Required: the session ID from LogIn in the mfiles-session-id-bin metadata.
- **Idempotent:** yes
- **Returns metadata structure version:** no
- **Streaming:** none (unary)

<a id="remarks"></a>

## Remarks

- **Replaces the whole list**: handlers that are not in `event_handlers` are removed. Get the
  current list with [GetVaultEventHandlers](https://developer.m-files.com/APIs/gRPC-API/Reference/MFiles.IRPCEventHandlersAdmin/GetVaultEventHandlers/index.md)
  first and send unchanged handlers back with their `guid`.
- Requires a vault session, the vault right `change_metadata_structure`, and the right to run
  code: `run_code`, or signed scripts and `run_signed_code` (see the service overview).
- Validation: every `event_type` must be a vault event, `description` must not be empty, the
  `code` of active handlers must compile ("The VBScript code for the event handler ... is
  invalid."), and the `sort_index` values of each event type must be 0, 1, 2, ... without gaps.
- The session language must be the vault's default language; a session in another vault
  language fails with "Not implemented.". Fails also when the server license does not include
  event handlers.
- Takes effect for the vault after the call commits; when full event logging is on, the server
  logs each added, changed and removed handler.

<a id="request"></a>

## Request: SetVaultEventHandlersRequest

> Nested message fields are expanded to depth 3; follow a type link for deeper levels and for the type's own page.

| Field | Type | Description |
|---|---|---|
| `event_handlers[]` | repeated [`InternalEventHandler`](https://developer.m-files.com/APIs/gRPC-API/Reference/Messages/MFiles.InternalEventHandler/index.md) | The complete new list of the vault's event handlers. Include existing handlers with their `guid`; leave `guid` empty for a new handler. |
| `event_handlers[].event_type` | [`InternalEventType`](https://developer.m-files.com/APIs/gRPC-API/Reference/Enums/MFiles.InternalEventType/index.md) | The event type the handler is associated with. |
| `event_handlers[].sort_index` | `int32` | The sort index defines the order in which the event handlers are executed in response to an event. |
| `event_handlers[].is_active` | `bool` | True when this handler is active and is executed in response to events. |
| `event_handlers[].description` | `string` | Description of the event handler. A user friendly identifier for the event handler. |
| `event_handlers[].code` | `string` | The actual code for the event handler that is executed in response an event.. |
| `event_handlers[].guid` | `string` | GUID for the event handler. |

<a id="response"></a>

## Response: SetVaultEventHandlersResponse

No fields.

<a id="related"></a>

## Related methods

- [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.
