Listing event invitees with email addresses

:bookmark: This is a Data Explorer SQL query that retrieves a list of all users who have RSVP’d to a specific event, along with their primary email addresses. It’s useful for event coordinators who need attendee contact information for follow-ups, reminders, or external communications.

:person_raising_hand: Required user level: Administrator

:discourse2: This query requires the Calendar (and Event) plugin to be enabled.

What this query does

If you run events on your Discourse site using the Calendar (and Event) plugin, you may need a way to get a full attendee list with email addresses — for example, to send a pre-event briefing, share logistics, or follow up after the event.

The built-in “Export event” feature in the event menu downloads a list of RSVPs, but it’s delivered as a zipped file via personal message. This Data Explorer query gives you a faster, on-screen alternative that includes each attendee’s primary email address, and allows you to export the results directly to CSV or JSON.

The query returns all users who have responded to a given event (regardless of whether they chose “Going”, “Interested”, or “Not Going”), sorted alphabetically by username.

SQL query

-- [params]
-- integer :event_topic_id = 23338

SELECT 
  u.id AS user_id,
  u.username,
  u.name,
  e.email
FROM users u
JOIN user_emails e ON u.id = e.user_id
JOIN discourse_post_event_invitees invitees ON u.id = invitees.user_id
JOIN posts p ON p.id = invitees.post_id
WHERE e.primary = true
AND p.topic_id = :event_topic_id
ORDER BY u.username

Parameter

Parameter Type Description
:event_topic_id Integer The topic ID of the event you want to pull invitees from. You can find this in the URL of the event topic — for example, in discourse.example.com/t/my-event-topic/23338, the topic ID is 23338.

How the query works

This query pulls data from four database tables and combines them to produce a single list:

  1. users — Contains basic user profile information such as username and display name.
  2. user_emails — Stores email addresses associated with each user. A user can have multiple email addresses, so the query filters to only the primary email using e.primary = true.
  3. discourse_post_event_invitees — Records every user who has responded to an event (by clicking “Going”, “Interested”, or “Not Going”). Each record links a user to the post that contains the event.
  4. posts — Connects the event’s post to its parent topic, allowing you to look up invitees by topic ID rather than needing to know the internal post ID.

The JOIN statements link these tables together so that only users who appear in the invitees list for the specified event topic are included. Results are sorted alphabetically by username.

Example results

user_id username name email
42 alice_m Alice Martinez alice@example.com
87 bob_jones Bob Jones bob@example.com
15 carol_w Carol Wu carol@example.com
63 david_k David Kim david@example.com

Filtering by RSVP status

The query above returns all invitees regardless of their RSVP status. If you only want users who marked themselves as “Going”, you can add a status filter to the WHERE clause. The status column in the discourse_post_event_invitees table uses these values:

Status code Meaning
0 Going
1 Interested
2 Not Going

For example, to return only users who are “Going”, add AND invitees.status = 0 to the WHERE clause:

-- [params]
-- integer :event_topic_id = 23338

SELECT 
  u.id AS user_id,
  u.username,
  u.name,
  e.email
FROM users u
JOIN user_emails e ON u.id = e.user_id
JOIN discourse_post_event_invitees invitees ON u.id = invitees.user_id
JOIN posts p ON p.id = invitees.post_id
WHERE e.primary = true
AND p.topic_id = :event_topic_id
AND invitees.status = 0
ORDER BY u.username

You can also display the RSVP status as a readable label instead of a number by adding a CASE expression:

CASE 
  WHEN invitees.status = 0 THEN 'Going'
  WHEN invitees.status = 1 THEN 'Interested'
  WHEN invitees.status = 2 THEN 'Not Going'
END AS rsvp_status

Running the query

  1. Go to Admin > Plugins > Data Explorer (or navigate to /admin/plugins/discourse-data-explorer).
  2. Click the + button to create a new query.
  3. Give the query a name (e.g., “Event invitees with emails”).
  4. Paste the SQL into the query editor.
  5. Click Run, then enter the topic ID of your event when prompted.
  6. To download the results, click the CSV or JSON button after the query has finished running.

:information_source: The email column contains sensitive personal data. Take care when exporting or sharing the results, and make sure your use of this data complies with your community’s privacy policy and any applicable data protection regulations.

Common issues and solutions

Issue Solution
The query returns zero results Double-check that the topic ID is correct and that users have actually RSVP’d to the event. You can verify by visiting the event topic and checking the attendee list.
“relation discourse_post_event_invitees does not exist” error The Calendar (and Event) plugin is not installed or not enabled. This query requires the plugin to be active.
Duplicate rows appear in results If a user has multiple email records flagged as primary (uncommon, but possible), you may see duplicates. Adding DISTINCT after SELECT can resolve this.