---
title: "Get events and state around the specified event."
method: GET
path: "/_matrix/client/v3/rooms/{roomId}/context/{eventId}"
tags: ["Room participation"]
---

# Get events and state around the specified event.

`GET /_matrix/client/v3/rooms/{roomId}/context/{eventId}`

## Request

- Base URL: `https://matrix.org`
- URL: `https://matrix.org/_matrix/client/v3/rooms/{roomId}/context/{eventId}`
- Auth: one of:
  - API key in query parameter `access_token`
  - HTTP bearer
- TypeScript: <https://skmtc.dev/matrix/apis/matrix-client-server-api/docs/_matrix/client/v3/rooms/:roomId/context/:eventId/get.ts> (a function with typed inputs; its response is checked against the schema)

This API returns a number of events that happened just before and
after the specified event. This allows clients to get the context
surrounding an event.

*Note*: This endpoint supports lazy-loading of room member events. See
[Lazy-loading room members](https://spec.matrix.org/v1.19/client-server-api/#lazy-loading-room-members) for more information.

## Path parameters

- `roomId` string, required
- `eventId` string, required

## Query parameters

- `limit` integer
- `filter` string

## Response `200`

The events and state surrounding the requested event.

- object: The events and state surrounding the requested event.
  - `end` string: A token that can be used to paginate forwards with using [`GET /messages`](https://spec.matrix.org/v1.19/client-server-api/#get_matrixclientv3roomsroomidmessages).
  - `event` object: The format used for events when they are returned from API endpoints such as `/sync`, where the `room_id` is implied elsewhere in the response.
    - `content` object, required: The body of this event, as created by the client which sent it.
    - `event_id` string, mx-event-id, required: The globally unique identifier for this event.
    - `origin_server_ts` integer, required: Timestamp (in milliseconds since the unix epoch) on originating homeserver when this event was sent.
    - `sender` string, mx-user-id, required: Contains the fully-qualified ID of the user who sent this event.
    - `state_key` string: Present if, and only if, this event is a *state* event. The key making this piece of state unique in the room. Note that it is often an empty string. State keys starting with an `@` are reserved for referencing user IDs, such as room members. With the exception of a few events, state events set with a given user's ID as the state key MUST only be set by that user.
    - `type` string, required: The type of the event.
    - `unsigned` object: Contains optional extra information about the event.
      - `age` integer: The time in milliseconds that has elapsed since the event was sent. This field is generated by the local homeserver, and may be incorrect if the local time on at least one of the two servers is out of sync, which can cause the age to either be negative or greater than it actually is.
      - `membership` string: The room membership of the user making the request, at the time of the event. This property is the value of the `membership` property of the requesting user's [`m.room.member`](https://spec.matrix.org/v1.19/client-server-api#mroommember) state at the point of the event, including any changes caused by the event. If the user had yet to join the room at the time of the event (i.e, they have no `m.room.member` state), this property is set to `leave`. Homeservers SHOULD populate this property wherever practical, but they MAY omit it if necessary (for example, if calculating the value is expensive, servers might choose to only implement it in encrypted rooms). The property is *not* normally populated in events pushed to application services via the application service transaction API (where there is no clear definition of "requesting user").
      - `prev_content` object: The `content` of the previous state event that was replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event, and the client has permission to see the previous event.
      - `redacted_because` object: The event that redacted this event, if any.
      - `replaces_state` string, mx-event-id: The event ID of the state event replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event. Unlike `prev_content`, this field is included regardless of history visibility.
      - `transaction_id` string: The client-supplied [transaction ID](https://spec.matrix.org/v1.19/client-server-api/#transaction-identifiers), for example, provided via `PUT /_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}`, if the client being given the event is the same one which sent it.
    - `room_id` string, mx-room-id, required: The ID of the room associated with this event.
  - `events_after` object[]: A list of room events that happened just after the requested event, in chronological order.
    - `content` object, required: The body of this event, as created by the client which sent it.
    - `event_id` string, mx-event-id, required: The globally unique identifier for this event.
    - `origin_server_ts` integer, required: Timestamp (in milliseconds since the unix epoch) on originating homeserver when this event was sent.
    - `sender` string, mx-user-id, required: Contains the fully-qualified ID of the user who sent this event.
    - `state_key` string: Present if, and only if, this event is a *state* event. The key making this piece of state unique in the room. Note that it is often an empty string. State keys starting with an `@` are reserved for referencing user IDs, such as room members. With the exception of a few events, state events set with a given user's ID as the state key MUST only be set by that user.
    - `type` string, required: The type of the event.
    - `unsigned` object: Contains optional extra information about the event.
      - `age` integer: The time in milliseconds that has elapsed since the event was sent. This field is generated by the local homeserver, and may be incorrect if the local time on at least one of the two servers is out of sync, which can cause the age to either be negative or greater than it actually is.
      - `membership` string: The room membership of the user making the request, at the time of the event. This property is the value of the `membership` property of the requesting user's [`m.room.member`](https://spec.matrix.org/v1.19/client-server-api#mroommember) state at the point of the event, including any changes caused by the event. If the user had yet to join the room at the time of the event (i.e, they have no `m.room.member` state), this property is set to `leave`. Homeservers SHOULD populate this property wherever practical, but they MAY omit it if necessary (for example, if calculating the value is expensive, servers might choose to only implement it in encrypted rooms). The property is *not* normally populated in events pushed to application services via the application service transaction API (where there is no clear definition of "requesting user").
      - `prev_content` object: The `content` of the previous state event that was replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event, and the client has permission to see the previous event.
      - `redacted_because` object: The event that redacted this event, if any.
      - `replaces_state` string, mx-event-id: The event ID of the state event replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event. Unlike `prev_content`, this field is included regardless of history visibility.
      - `transaction_id` string: The client-supplied [transaction ID](https://spec.matrix.org/v1.19/client-server-api/#transaction-identifiers), for example, provided via `PUT /_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}`, if the client being given the event is the same one which sent it.
    - `room_id` string, mx-room-id, required: The ID of the room associated with this event.
  - `events_before` object[]: A list of room events that happened just before the requested event, in reverse-chronological order.
    - `content` object, required: The body of this event, as created by the client which sent it.
    - `event_id` string, mx-event-id, required: The globally unique identifier for this event.
    - `origin_server_ts` integer, required: Timestamp (in milliseconds since the unix epoch) on originating homeserver when this event was sent.
    - `sender` string, mx-user-id, required: Contains the fully-qualified ID of the user who sent this event.
    - `state_key` string: Present if, and only if, this event is a *state* event. The key making this piece of state unique in the room. Note that it is often an empty string. State keys starting with an `@` are reserved for referencing user IDs, such as room members. With the exception of a few events, state events set with a given user's ID as the state key MUST only be set by that user.
    - `type` string, required: The type of the event.
    - `unsigned` object: Contains optional extra information about the event.
      - `age` integer: The time in milliseconds that has elapsed since the event was sent. This field is generated by the local homeserver, and may be incorrect if the local time on at least one of the two servers is out of sync, which can cause the age to either be negative or greater than it actually is.
      - `membership` string: The room membership of the user making the request, at the time of the event. This property is the value of the `membership` property of the requesting user's [`m.room.member`](https://spec.matrix.org/v1.19/client-server-api#mroommember) state at the point of the event, including any changes caused by the event. If the user had yet to join the room at the time of the event (i.e, they have no `m.room.member` state), this property is set to `leave`. Homeservers SHOULD populate this property wherever practical, but they MAY omit it if necessary (for example, if calculating the value is expensive, servers might choose to only implement it in encrypted rooms). The property is *not* normally populated in events pushed to application services via the application service transaction API (where there is no clear definition of "requesting user").
      - `prev_content` object: The `content` of the previous state event that was replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event, and the client has permission to see the previous event.
      - `redacted_because` object: The event that redacted this event, if any.
      - `replaces_state` string, mx-event-id: The event ID of the state event replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event. Unlike `prev_content`, this field is included regardless of history visibility.
      - `transaction_id` string: The client-supplied [transaction ID](https://spec.matrix.org/v1.19/client-server-api/#transaction-identifiers), for example, provided via `PUT /_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}`, if the client being given the event is the same one which sent it.
    - `room_id` string, mx-room-id, required: The ID of the room associated with this event.
  - `start` string: A token that can be used to paginate backwards with using [`GET /messages`](https://spec.matrix.org/v1.19/client-server-api/#get_matrixclientv3roomsroomidmessages).
  - `state` object[]: The state of the room at the last event returned.
    - `content` object, required: The body of this event, as created by the client which sent it.
    - `event_id` string, mx-event-id, required: The globally unique identifier for this event.
    - `origin_server_ts` integer, required: Timestamp (in milliseconds since the unix epoch) on originating homeserver when this event was sent.
    - `sender` string, mx-user-id, required: Contains the fully-qualified ID of the user who sent this event.
    - `state_key` string: Present if, and only if, this event is a *state* event. The key making this piece of state unique in the room. Note that it is often an empty string. State keys starting with an `@` are reserved for referencing user IDs, such as room members. With the exception of a few events, state events set with a given user's ID as the state key MUST only be set by that user.
    - `type` string, required: The type of the event.
    - `unsigned` object: Contains optional extra information about the event.
      - `age` integer: The time in milliseconds that has elapsed since the event was sent. This field is generated by the local homeserver, and may be incorrect if the local time on at least one of the two servers is out of sync, which can cause the age to either be negative or greater than it actually is.
      - `membership` string: The room membership of the user making the request, at the time of the event. This property is the value of the `membership` property of the requesting user's [`m.room.member`](https://spec.matrix.org/v1.19/client-server-api#mroommember) state at the point of the event, including any changes caused by the event. If the user had yet to join the room at the time of the event (i.e, they have no `m.room.member` state), this property is set to `leave`. Homeservers SHOULD populate this property wherever practical, but they MAY omit it if necessary (for example, if calculating the value is expensive, servers might choose to only implement it in encrypted rooms). The property is *not* normally populated in events pushed to application services via the application service transaction API (where there is no clear definition of "requesting user").
      - `prev_content` object: The `content` of the previous state event that was replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event, and the client has permission to see the previous event.
      - `redacted_because` object: The event that redacted this event, if any.
      - `replaces_state` string, mx-event-id: The event ID of the state event replaced by this event. This field is generated by the local homeserver, and is only returned if the event is a state event. Unlike `prev_content`, this field is included regardless of history visibility.
      - `transaction_id` string: The client-supplied [transaction ID](https://spec.matrix.org/v1.19/client-server-api/#transaction-identifiers), for example, provided via `PUT /_matrix/client/v3/rooms/{roomId}/send/{eventType}/{txnId}`, if the client being given the event is the same one which sent it.
    - `room_id` string, mx-room-id, required: The ID of the room associated with this event.

---

[API](https://skmtc.dev/matrix/apis/matrix-client-server-api.md) - [All operations](https://skmtc.dev/matrix/apis/matrix-client-server-api/llms.txt) - [OpenAPI document](https://skmtc.dev/matrix/apis/matrix-client-server-api/revisions/c7fe4072c681?raw)
