Managing Matrix users with the Synapse Admin API

The Synapse Admin API lets server administrators create, list, deactivate and adjust Matrix accounts from the command line or scripts. This page covers what it does, how to limit its exposure and what to confirm before relying on it.

On this page

Managing Matrix users with the Synapse Admin API: when teams need it

If you run a self-hosted Synapse homeserver and need to create, list, deactivate or adjust accounts across many users, the Synapse Admin API is the built-in HTTP interface for those tasks, and it is most useful while Synapse still handles its own account database. It is an admin-only API shipped with Synapse, so calls require an access token belonging to a server admin and should be made from the server host or a tightly restricted network location. Synapse is developed by Element and distributed under AGPL-3.0, and the current release line on GitHub, as of the researched facts, is v1.163.0, published October 14, 2026. Confirm the version you run against the Synapse documentation before scripting, because endpoint behavior can change between releases.

This page covers the account tasks you are most likely to script: creating and listing users, reviewing and changing user details, managing devices, deactivating accounts, and setting rate limit overrides. It also covers how to run these calls from the server host without exposing the admin listener to the internet. Treat the Admin API as a privileged path: every call changes state on production accounts, so decide early who holds admin tokens, where scripts run, and how each change is logged for your own review.

The key decision is timing. Once Matrix Authentication Service takes over login and account administration, the Synapse endpoints that create or change passwords and sessions stop working for those users, and account work moves to the MAS Admin API and CLI. Before you build scripts on the Synapse Admin API, confirm whether MAS is planned for your deployment and which identity provider will be the source of truth for accounts. If the answer is MAS, use this page for the Synapse-side tasks that remain and treat the scripts as temporary.

Which account task fits which Admin API approach

This table matches common account tasks to three access methods: direct HTTP calls from the server host, a wrapper script, or a deferred move to MAS. Read each row for when the method fits and what it costs you, then check the MAS row before you commit to a long-term account workflow.

Account taskDirect HTTP calls from the hostWrapper script run from the hostDeferred move to MAS
Creating and updating usersFits one-off accounts and quick fixes; each call must carry the admin token and body exactly rightFits repeatable onboarding batches; the script should log each request and result for auditFits when accounts come from your identity provider; account creation then follows the MAS model rather than Synapse calls
Listing and searching accountsFits ad hoc lookups; paging through large results by hand is slow and error-proneFits regular reports such as inactive or unexpected admins; confirm paging behavior in the current docsAccount browsing moves to the MAS admin tooling; confirm which Synapse endpoints stop working before you rely on them
Device managementFits removing a single stale or compromised device; verify the device ID before deletingFits scheduled cleanup of stale devices; a dry-run mode reduces the risk of removing active sessionsSession handling moves to MAS; confirm how device and session control maps after the switch
Rate limit overridesFits a short, documented exception for one account; record the reason and the revert dateFits applying a standard override profile to a named set of accounts; keep the list in version controlConfirm with the MAS and Synapse docs whether the same override applies after migration
Deactivation and erasureFits a single leaver with a clear ticket; check the erase option and its effect on shared rooms firstFits offboarding driven by an HR or identity feed; test on a non-production homeserver before schedulingPair with your identity provider so deactivation happens in one place; confirm the post-migration workflow first
Administrator flagsFits granting or removing admin on one account; a mistake here has wide effect, so review the changeFits periodic admin reviews where the script compares current flags to an approved listAdmin rights are managed through MAS tooling after migration; confirm the commands in the MAS docs
Access control of the script itselfNot applicable; the token sits in the shell history or environment unless you manage itRequires a dedicated admin account, a token stored with restricted file permissions and no token in logsRequires a reviewed MAS admin role and its own audit trail; confirm the model with your security team

Setting up the Admin API for scripted account tasks

This sequence prepares a Synapse homeserver so that account tasks can be scripted safely from the server host, with each step checked before the next begins.

  1. Confirm the Synapse version and upgrade notes

    Identify the Synapse version your homeserver runs and read the upgrade notes for every release between it and the version you plan to target. Confirm the Python and PostgreSQL versions it requires, since Synapse 1.143.0 and later require PostgreSQL 14 or newer and 1.142.0 and later require Python 3.10 or newer. Check the upgrade notes for any warning about rollback, because schema changes between releases can make rolling back difficult. You know this step is done when you have written down the running version, the target version, and the requirements that apply to both, and the platform meets them.

  2. Verify the homeserver is reachable on the intended listener

    Confirm that Synapse answers on the client listener and that your server_name resolves as expected through delegation. Check which listener serves the admin endpoints in your configuration, since the Admin API is served through the client listener and should not be exposed beyond what you intend. Run a simple version request from the server host and from an external network to see what is reachable. You know this step is done when the client endpoint responds from the host, and when external access shows only the paths you meant to publish.

  3. Confirm registration settings before creating users

    Review the registration settings in homeserver.yaml before you create any account, including whether open registration, registration tokens, and email verification are enabled. Decide who is allowed to create accounts and record that decision in your change log. Admin-created accounts are not affected by open registration, but a misconfigured setting can let outsiders create accounts later, so confirm the values in the configuration file, not from memory. You know this step is done when the settings you reviewed match a written registration policy.

  4. Create a dedicated admin account

    Create a separate account for scripting, distinct from any personal administrator account, and grant it the server admin flag through the register_new_matrix_user tool run on the server host with the shared secret or an admin-capable command. Use a name that makes its purpose clear, such as an automation account, and limit who knows its password. Avoid using this account for daily chat. You know this step is done when the account exists and shows as an admin in a read-only lookup on the server.

  5. Obtain and store the admin access token securely

    Log in as the dedicated account to obtain an access token, then store it in a file readable only by the user that runs your scripts, such as a root-owned environment file with restricted permissions, or in your secrets manager. Do not paste the token into shell history, tickets, or chat. Record where the token lives and who can read it. You know this step is done when the token works for a request from the script runner and the file permissions show that only the intended user can read it.

  6. Restrict the admin access path to the server host

    Limit access to the admin endpoints so that they are reachable only from the server host or a management network you control. Options include a reverse proxy rule that denies the admin paths for public requests, firewall rules, or a separate listener if your deployment supports one. Follow the Synapse configuration manual and your proxy's documentation to confirm the exact mechanism for your version. You know this step is done when the admin path returns a refusal from an external network and still answers from the server host.

  7. Run one read-only listing call as a check

    From the server host, call the Admin API endpoint that lists users, using the stored token and a small limit so the output stays readable. Confirm the response includes the accounts you expect, including the dedicated admin account, and that the total matches your records. Save the command and its output shape in your runbook without the token. You know this step is done when the listing returns the expected accounts and the call fails with an authorization error when the token is removed.

  8. Test one account change on a non-production homeserver

    Before running any write call against production, perform one account change on a non-production homeserver with the same Synapse version and configuration, such as creating a test user, changing its display name, and deactivating it. Check each result in the listing call and confirm the account state matches what you requested. Only then add the same change to your production runbook with its rollback notes. You know this step is done when the test change produces the expected state in both the response and a fresh listing, and the production runbook records the verified command.

How a server-host script reaches the Admin API

The request starts with an operator or script on the server host, which reads the admin token from a secrets store rather than a file in the repository. It passes through the reverse proxy, which should forward only the /_synapse/admin paths the team has allowed, and reaches the Synapse main process, which reads and writes the PostgreSQL database. The trust boundary sits between the host and any external network: public clients and federation traffic reach only the paths that must be open, and admin paths should stay off the public internet. Check that the proxy blocks admin paths from outside and that the token never appears in logs.

Admin requests from the host reach Synapse through a proxy that blocks admin paths externally.

Protecting admin tokens and the admin path

The Synapse Admin API can create accounts, reset passwords, deactivate users and change rate limits, so a leaked token or an exposed admin listener affects the whole homeserver. The cards below cover the main ways this access goes wrong and the controls that keep it contained. Check each one against your own reverse proxy, shell history, script runners and change records before you rely on it.

Token leakage in shell history and logs

An admin access token pasted into a command line can end up in shell history, process listings, CI logs or a ticket. Anyone who reads that output can act as an administrator until the token is revoked. Keep tokens in a file or secret store readable only by the account that runs the script, pass them through environment variables rather than inline arguments, and check your logging pipeline for Authorization headers before you enable request logging. Rotate any token that has appeared in a shared location.

Admin paths on the public proxy

The admin endpoints are served under the same hostname as client traffic unless you block them. If the reverse proxy forwards /_synapse/admin to the public internet, any attacker who obtains a token, or finds a weakness in the path, reaches the full API from anywhere. Restrict these paths at the proxy to a management network or VPN, and confirm the restriction from outside your network with a request that should fail. Record the test result with the change.

Over-privileged service accounts

A single admin account used by every script gives each script full rights, and it makes it impossible to tell which automation made a change. Create separate admin accounts for distinct jobs such as provisioning, offboarding and reporting, and grant admin status only to the accounts that need it. Confirm which accounts currently hold admin rights by listing them through the API, and remove rights from accounts that no longer have a documented purpose.

Unlogged bulk changes

Scripts that loop over many users can deactivate, reset or re-rate-limit accounts in minutes, and a mistake repeats across every match. Run bulk jobs from a reviewed script kept in version control, do a dry run that lists the affected user IDs, and write the list, operator, date and outcome to a change log. Ask your team to confirm that the log is stored outside the Synapse host so an attacker who gains that host cannot edit it.

Deactivation without a recorded reason

Deactivating an account removes access, but without a reason on record, an investigator later cannot tell a leaver offboarding from a suspected compromise or an abuse case. Require a ticket reference or case ID with every deactivation, and store the reason alongside the user ID in your change log. This also helps when a user asks why access was removed, and it gives your compliance team evidence of who authorized each change.

Questions teams ask before scripting Synapse account changes

How much effort does scripting Synapse user administration take?

The effort depends less on the number of API calls than on how many account states your script must handle safely. Creating a user, resetting a password or listing accounts is a small change, but a script that deactivates accounts, clears devices and adjusts rate limits needs dry-run output, logging, error handling and a rollback plan for each action. The main drivers are the number of account operations you need, whether they run once or on a schedule, how many identity sources feed the account list, and whether the script must work across more than one homeserver. Ask any partner to break the work into the operations in scope and the tests planned for each one.

Can an in-house team script the Synapse Admin API without outside help?

Yes, if the team has someone comfortable with the server host, a scripting language and the Synapse configuration manual. The Admin API requires an admin access token, and calls run against the homeserver, so the people involved need shell access, a way to store the token securely and a habit of testing against a non-production server first. Outside help tends to add value when the team needs a review of how the script authenticates, how it logs and how it handles failures, or when the account process is tied to HR and identity systems. Ask whether the partner will leave the script, its documentation and a test plan with your team.

What access and people does a user administration project need from my side?

Expect to provide three things: shell or deployment access to the Synapse host or its container, a test homeserver with the same version and configuration as production, and a named owner for the identity provider that supplies user identities. The identity provider owner matters because account creation and deactivation should follow the source of truth, not a spreadsheet. You also need an owner who can approve which admin accounts exist and which operations the script may run. Confirm with your platform team which server version you run, because the Admin API endpoints and their behavior change between Synapse releases.

How long does it take to get a safe user script running?

No duration is given here because it depends on the operations in scope, the state of the test environment and how many people must approve the change. A realistic plan separates three phases: building the script against a test homeserver, reviewing it with the identity and security owners, and running it in production with a limited first batch and logs checked after each run. Ask for the phases, the exit criteria for each one and the dates on which the test and production runs will happen. Be wary of any plan that skips the test server.

What goes wrong when admin scripts run against production accounts?

The most common problems are a script that runs with the wrong admin token, a loop that deactivates or erases more accounts than intended, and a change that is hard to reverse. Synapse's upgrade notes also warn that rolling back can be difficult because of database schema changes between releases, so a script that depends on a specific version should be pinned and tested after every upgrade. Protect the token, require a dry run before any destructive call, cap the number of accounts per run and keep an audit trail of every request and response.

When does Matrix Authentication Service change how I administer users?

Once MAS handles authentication, account tasks such as password resets, admin rights and personal sessions move to the MAS Admin API and CLI, and some Synapse endpoints that scripts depend on stop working. Plan the Synapse script against the authentication model you will run for the next few years, not the one you run today. Confirm with the MAS documentation which endpoints remain valid after the move, and check how your upstream identity providers, such as Keycloak, Microsoft Entra ID or Authentik, will provision accounts. Scripts written before the move will usually need a second review.

Which Synapse version should my script target?

Target the version you run in production, and confirm the Admin API behavior for that exact release in the Synapse documentation and upgrade notes before writing calls. The latest release listed on the project's GitHub releases page at the time of writing is v1.163.0, but your production version may differ. Pin the version in your change records, test every script again after each upgrade, and read the notes for every release between your current and target versions, since upstream drops support for Python and PostgreSQL versions once they reach end of life.

How DeployOpen scopes Synapse account administration

The sequence below shows how DeployOpen turns a request for Synapse account administration into a written scope, tested account scripts and a runbook your team can operate. Each step ends with an output you can check before the next one starts.

  1. Confirm Synapse and MAS versions

    DeployOpen records the Synapse release, the database engine and version, the Python runtime and, if present, the Matrix Authentication Service release that your homeserver runs. The team checks these against the upgrade notes for each release, because some admin endpoints and account behaviors change once MAS is in front of Synapse. The step closes with a version record signed off by your platform owner, so every later script is written against the versions you actually run.

  2. Map every access path to user accounts

    The team inventories who and what can reach account administration: the admin API listener, the admin user tokens, the host shell, the identity provider that drives provisioning, and any ticketing or HR feed. They confirm which paths are restricted to the server host and which are exposed through a reverse proxy. The output is a short access map listing each path, its owner and the controls around it, which you review before any script is written.

  3. Agree the account tasks in scope

    Together with your team, DeployOpen lists the account tasks the scripts will cover, such as creating and listing users, deactivating accounts, reviewing devices and setting rate limit overrides. Tasks that belong to another system, such as offboarding workflows or MAS-level sessions, are marked as out of scope or sent to a separate work item. The output is a written task list with the expected inputs and outputs for each task.

  4. Write scripts and test them on a copy

    The team writes the account scripts to run from the server host, using a dedicated admin account and token handled according to your secrets policy. Every script is first run against a copy of the homeserver restored from a recent backup, with test accounts that mirror your real user types. The test log records each call, its response and the database state before and after. The step closes when the scripts behave as the task list describes on the copy.

  5. Review logging, error handling and safeguards

    DeployOpen reviews how each script reports failures, logs actions, avoids printing tokens and refuses to act on malformed input, such as an unexpected user ID format. Destructive actions get a confirmation step or a dry-run mode where the design allows it. Your security or identity reviewer checks the findings. The output is a review record with each finding, its fix and the retest result.

  6. Document the runbook for operators

    The team writes a runbook covering each task, its prerequisites, the exact commands, the expected output, the rollback limits noted in the upgrade notes and the escalation path. It also records which versions the runbook was tested against and how to re-test after a Synapse or MAS upgrade. The output is a runbook in your documentation system, reviewed by the operators who will use it.

  7. Hand over scripts, runbook and deliverables

    DeployOpen hands over the scripts, test records, review record and runbook as written deliverables, and walks your operators through a live run on the copy. Engagements are fixed-scope, so the handover matches the task list agreed in writing at the start. Ongoing support for upgrades, script changes and periodic retesting is available as a retainer, which you can request separately from the original scope. The step closes when your team signs off the handover.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.