Mautic REST API authentication: OAuth2 or basic auth

How to secure access to the Mautic REST API, when OAuth2 is the right choice, when basic authentication is acceptable, and how to design the API user behind each integration.

On this page

Mautic REST API authentication: which method fits your integration

A team connecting Mautic to another system first needs to decide which credential method to use and who owns it, and the answer depends on whether the caller is a person, a server-side job or a third-party service. Mautic's documentation recommends OAuth2 for API access, so start there and move away from it only when a specific constraint forces the change. This section covers the Mautic REST API: its OAuth2 grants, when basic authentication is acceptable, how to design the API user behind each integration, and the checks to run before go-live. User sign-in to the Mautic interface, whether basic authentication or SAML single sign-on where configured, is a separate topic that the Mautic authentication docs cover. Confirm grant names, endpoints and enabling steps against the Mautic API documentation for the exact version you run, because these details can change between releases.

The grant you choose follows from who is acting. The authorization code grant suits an application where a person approves access once and the integration then acts on that person's behalf, with a refresh token keeping the session alive without storing the person's password. The client credentials grant suits a server-side job that runs without a user present, such as a nightly sync, and it ties access to the application itself, so the integration keeps working when an employee changes roles. Basic authentication sends a username and password with each request, so it is defensible only in narrow cases, such as a short internal test on a non-production instance served over HTTPS. Before you design any integration around basic authentication, confirm whether your Mautic version still accepts it for the API and whether it is enabled in your configuration. Ask your Mautic administrator to verify which methods the API accepts first.

Design the API user before generating any credential. Create a dedicated user for each integration, assign only the permissions that integration needs, and record a named owner, the systems that use the credential and the date it was last rotated. Store client secrets and refresh tokens in your secrets manager and keep them out of source control. Before go-live, run these checks: confirm the integration can read and write only the objects it is meant to touch, revoke a test token and verify that the integration fails safely, check that API activity appears in the logs your security team reviews, and confirm the integration still works after a Mautic upgrade in a test environment. Ask any implementation partner to list each check in the written scope so the evidence exists when an auditor or security review asks for it.

What you need before issuing API credentials

These prerequisites decide whether API credentials can be issued safely at all. Each card covers one item to confirm before anyone creates a client, user or token, because a weak foundation here makes every later permission decision harder to defend.

A supported Mautic release line

Confirm which release line your instance runs and whether it still receives security support before you design API access. The Mautic releases page lists the supported lines and their end dates, and authentication behavior can change between them. If your instance is on a line that is near or past its support end, plan the upgrade first so credentials are not issued against a platform you will have to change shortly afterward.

Mautic releases

Self-hosted on a VPS or dedicated server

The API should run on infrastructure you control, not shared hosting. The Mautic requirements page says Mautic should not be installed on shared hosting and recommends a VPS or dedicated server. Confirm who patches the server, who manages PHP and the web server, and who restores backups, because API credentials are only as trustworthy as the host that stores their secrets.

Mautic requirements

HTTPS on the public API domain

Serve the API only over HTTPS on the domain your integrations call. Tokens and client secrets sent over plain HTTP can be read by anyone on the network path. Confirm the certificate is valid, that HTTP redirects to HTTPS, and that the proxy or load balancer in front of Mautic passes the correct scheme and host so that OAuth2 redirect and callback URLs match exactly.

API enabled and feature set confirmed

Enable the API in Mautic configuration and confirm which API features your version exposes before designing permissions. Permissions can only be scoped to capabilities the instance actually provides, so check the endpoints your use cases need in the documentation for your exact version and test them in a non-production copy first.

A named owner for each integration

Assign one accountable person to every integration that will call the API. This person approves the scope, receives expiry and rotation reminders, and decides when access is removed. Without a named owner, credentials tend to outlive the project that created them, and nobody can explain later why a client still has write access to contact records.

A register of calling systems and data

Document each calling system, the Mautic objects it reads or writes, its direction of data flow and where its credentials will be stored. This register is the basis for choosing between authorization code, refresh token and client credentials flows, and for setting the narrowest permissions each caller needs. It also gives your security reviewers the evidence they will ask for.

How a token request moves between the caller, Mautic and your secrets store

This illustrative diagram follows a server-side integration through its token lifecycle. The integration server, inside its own network, sends its client credentials to the Mautic token endpoint over HTTPS and receives an access token and a refresh token. It keeps the client secret and refresh token in a secrets store, calls Mautic's API endpoints with the bearer token, and requests a new access token when the current one expires. The dotted paths show where the client secret must never appear: browser code, logs or the code repository. Confirm exact endpoint paths and token lifetimes in the API documentation for your Mautic version.

Token lifecycle for a server-side Mautic integration, with the client secret kept inside the trust boundary.

Which OAuth2 grant to use for each integration pattern

A server-side integration that syncs data on a schedule and acts for the organization, with no person involved at run time, fits the client credentials grant. The application authenticates with its client ID and client secret and receives an access token that is not tied to any individual's sign-in. Confirm in the Mautic API documentation for your version that this grant is available before you design around it.

  • Stored secret: keep the client secret in a secrets manager or protected environment configuration, never in source control, and scope it to one integration.
  • Rotation: plan a procedure that updates the secret in Mautic and in the job at the same time, so a rotation does not interrupt a nightly sync midway.
  • Token handling: request a new token when the current one expires and keep tokens in memory instead of writing them to disk.
  • What breaks: if a team uses a personal login or a shared password for this job, the job fails when that person leaves or changes a password, and audit records attribute every action to one human.
  • Permissions: limit the API identity to the objects the job needs, because a machine credential with broad administrator rights is an attractive target.

Check which identity the grant maps to in your version, who can read the client secret, and how the job responds when a token request is refused.

When basic authentication is acceptable for the Mautic API

Basic authentication is acceptable for the Mautic API only as a narrow exception, and only when four conditions hold together. The caller must sit inside a network you control, the connection must be HTTPS-only, the credential must belong to a dedicated API user with the fewest rights the integration needs, and your team must be able to rotate that password without breaking other systems. Basic authentication sends the username and password with every request, so any weakness in transport, logging or a copied script exposes the credential each time it is used. If one of the four conditions fails, the case for OAuth2 becomes the default rather than a debate. Confirm the exact basic authentication behavior and the settings that govern it in your Mautic version against the Mautic authentication docs before you write the integration design.

The Mautic authentication docs describe basic authentication in the context of user sign-in, and they point to SAML single sign-on as the option for people who log in to the interface. OAuth2 is the method Mautic recommends for API access, because it issues tokens to a client application rather than handing over a user's password on every call. That distinction matters for ownership. Teams should not reuse a person's interface login for an integration, because the integration then breaks when that person changes role or leaves, its actions appear in logs as that person, and their password rotation schedule becomes the integration's schedule. Create a separate API user for each integration, assign it only the permissions its endpoints need, and record who owns it.

If a test script or internal tool needs basic authentication for a short period, document an owner, the reason for the exception, the network it runs on and a removal date before the first request is sent. Review the exception on that date and either move it to OAuth2 or retire it. Treat an expired exception as an open finding, not a reminder to renew it quietly. Ask your Mautic administrator to confirm which API user the exception uses and that its password can be changed without a code release.

How to configure Mautic API access in order

This sequence takes an integration from no API access to a tested, least-privilege connection to Mautic. Each step ends with a check so the team knows the access works before any production data moves.

  1. Create a dedicated API user

    Create a separate Mautic user for the integration instead of reusing an administrator or a staff login. Give that user a role limited to the objects the integration needs, such as contacts or segments, and nothing else. Record the user's purpose and owner in your access register. The step is closed when the user exists, belongs to a restricted role, and a reviewer confirms that no administrative permissions were granted.

  2. Enable the API and confirm HTTPS

    Turn on API access in Mautic's configuration, then confirm the instance is reached only over HTTPS with a valid certificate. Check the endpoint's response from the network where the integration will run, not only from a browser on an admin workstation. Confirm which API version your integration targets, since the original REST API and the v2 endpoint differ. The step is closed when an unauthenticated request is refused and the endpoint answers over HTTPS from the integration host.

  3. Register the API client for the chosen grant

    Register an API client or application in Mautic for the grant your integration uses, such as the authorization code, refresh token or client credentials flow. Where the grant requires a redirect URI, record the exact value and make sure it matches what the application sends. Confirm the grant type against the Mautic version you run, because supported options can differ between releases. The step is closed when the client ID is recorded, the redirect URI matches in both places, and the grant type is written down in the integration design.

  4. Store secrets outside code and repositories

    Move the client secret and any refresh token into your organization's secrets store, with access limited to the service that needs them. Keep them out of source code, configuration files committed to the repository, container images and chat messages. Set a rotation owner and record where each secret lives. The step is closed when a repository search finds no secret values and the integration reads its credentials from the secrets store at runtime.

  5. Request a token and test a read-only call

    Request an access token using the chosen grant, then call one read-only endpoint, such as listing a small set of contacts. Check that the response contains only the data the API user's role allows and that a request outside that role is refused. Log the token request and the call without logging the token itself. The step is closed when the read call succeeds, the restricted call is denied, and the logs show the request without exposing the credential.

  6. Run a write test on a test contact

    Create a test contact through the API, update one field, and then delete the contact. Use a test address that your team controls and that cannot receive marketing email. Confirm the change appears in Mautic's records and that the audit trail attributes it to the API user. Remove the test contact afterward and confirm it no longer appears in searches. The step is closed when the create, update and delete calls succeed, the audit entries name the API user, and the test record is gone.

How integration types map to API users, grants and permissions

This table matches common Mautic integration types to the API user owner, grant or credential method, the general permission categories they need and the review triggered when their scope changes. Use it to design one API user per integration rather than sharing a single account. Role and permission names must be taken from the Mautic role settings in the version you install.

Integration typeAPI user owner and grant or credentialPermission categories (general)Review when scope changes
Sync job that reads contacts into a data warehouseData team owns a dedicated API user; OAuth2 client credentials or authorization code with a stored refresh token, depending on whether a person is involvedRead access to contacts and segments; no write access to contacts or campaignsAny new object type, field, or segment read, and any move to write access
Service that creates contacts from a website or partner formMarketing operations owns the API user; OAuth2 with a narrow write grant, with credentials held in a secrets storeCreate or update contacts; read only what is needed to match existing recordsNew fields written, changes to duplicate matching, and any added delete or segment access
Internal reporting tool showing campaign resultsReporting owner holds a read-only API user; OAuth2 client credentials kept server-sideRead campaigns, segments and aggregate contact counts; no contact personal data if avoidableAny request for contact-level detail or access to additional campaigns
Two-way CRM synchronizationIntegration owner with a service account; OAuth2 authorization code plus refresh token, reviewed on rotationRead and write contacts, companies and segment membership; read campaigns to avoid conflictsEvery new object, deletion permission, or change to which system is the record of truth
Legacy script using basic authenticationNamed technical owner; basic authentication only where the version and network controls allow it, with a migration date setSame categories as the replacement integration, kept as narrow as the script allowsAny change in the script, host, or network path, and every planned move to OAuth2
Interactive administrator access for a personNamed staff member through their own Mautic user account and role, not a shared API userLimited to the role assigned in Mautic; API access follows the user's roleRole change, departure, or change in the person's duties
Marketplace plugin calling the APIPlugin vendor or internal owner; credentials issued per installation and scoped to the plugin's stated needsOnly the categories the plugin documents; confirm each one before enablingEach plugin update, new permission request, or change in data sent to the plugin

Hardening Mautic API credentials after go-live

Once the Mautic API is connected to CRMs, data warehouses and other systems, the credentials behind those connections become the main way into your contact data. The six cards below cover the common exposure points and the control and check for each, so the team can review them before and after go-live.

Client secrets in code or logs

A client secret or API user password copied into a repository, a configuration file or an integration log gives anyone with read access full API reach. Move every secret into a secrets manager and inject it at runtime. Then search the repositories, CI variables, container images and application logs for the secret values. Confirm that your integration platform masks secrets in its run history, and confirm this in your own version rather than relying on the default.

Shared API users across integrations

When several integrations authenticate as one API user, you cannot tell which system made a change, and revoking one integration means breaking all of them. Create one API user or OAuth2 client per integration, with only the permissions that integration needs. Check that each client maps to a single owner and that no integration reuses another's credentials.

Tokens without rotation

Long-lived access tokens and client secrets that are never rotated stay valid long after the person who issued them has moved on. Set a rotation schedule for client secrets and review how refresh tokens are stored and revoked. Confirm the token lifetimes your Mautic version and identity layer actually enforce, and test that an expired or rotated credential is refused.

Public exposure of the API

The Mautic API only needs to be reachable from the systems that call it. If the API path is open to the internet, every credential weakness becomes an internet-facing attack surface. Restrict the API path at the reverse proxy or firewall to the known addresses of your integration servers, and keep the admin interface on a separate access rule. Test the restriction from outside the allowed network.

Missing ownership for each credential

A credential nobody owns is a credential nobody reviews. Keep a credential register that records the owning team, the integration it serves, the grant type, the permissions, the rotation date and the system that stores the secret. Check the register against the live API users and clients each quarter. Confirm which audit events your Mautic version records about API access before you rely on them for reviews.

Credentials kept after retirement

When an integration is retired, its API user, OAuth2 client and stored secrets often survive the project. Add a revocation step to the offboarding checklist that disables the API user or client, revokes its tokens, removes the secret from the secrets manager and updates the credential register. Verify by attempting a call with the retired credential and confirming it is refused.

Why Mautic API calls fail authentication and how to fix them

This table maps common authentication failures against the Mautic REST API to their likely causes and first fixes. Read it by matching the status code or behavior you see, then confirm the cause in logs before changing any setting. Check the Mautic and web server logs for the failing request first, because the request details usually point to one cause.

SymptomLikely causeFix
401 responses after a token worked earlierThe access token has expired, or the client refreshed with an old or already-used refresh tokenCheck the token expiry time. Request a new access token with the refresh token, and store the newest refresh token returned each time.
403 responses with a valid tokenThe API user lacks permission for that object or action in its user roleReview the API user's role for the specific object, such as contacts or segments, and grant only the permissions the integration needs.
Redirect URI mismatch in the authorization code flowThe redirect URI sent in the request does not exactly match the one registered for the API clientCompare scheme, host, port, path and trailing slash character by character. Update the registration or the request so they match exactly.
Calls fail from one network onlyA proxy or firewall blocks or rewrites requests, or the base URL uses HTTP instead of HTTPSConfirm the base URL uses HTTPS and the proxy passes Authorization headers. Test from an allowed network and review firewall rules with the network team.
Basic authentication works in a browser but fails from a scriptSpecial characters in the password are not encoded correctly, or the script uses a different user accountURL-encode or correctly encode the credential string in the script, and confirm the username and password match the account tested in the browser.
Credentials work in staging but not productionProduction uses a different API client registration or secret, or a different base URLCompare the client ID, secret and base URL for each environment. Register production credentials separately and store them in your secrets manager, not in code.

Questions buyers ask about Mautic API authentication

How much effort does it take to set up OAuth2 for one integration?

For one integration, the work is mostly design, configuration and testing, and the total depends on a few drivers. The number of API clients and the grant type each client needs set how much design is required. Each grant type adds its own flow to test, and the redirect handling in the authorization code grant takes more care than a server-to-server client. Secrets infrastructure matters because client secrets and refresh tokens must live in a store your team controls, not in ad hoc configuration files. Testing against a non-production instance and documenting which client calls which endpoints add effort too. Ask for a quote that lists each driver as a separate line so you can see what moves the total.

Can our own team set up Mautic API authentication without outside help?

A team with the right skills can do it in-house, and the deciding factor is whether those skills exist today. The work needs solid HTTP knowledge, including headers, redirects and status codes, plus working understanding of OAuth2 concepts such as authorization codes, access tokens, refresh tokens and scopes. Someone must know the Mautic configuration well enough to create API credentials, set up a dedicated API user with the right role and enable the authentication method the integration needs. The connecting application must also request, store and renew tokens correctly. Teams without these skills often spend their effort on trial and error with credentials, so a short, scoped design review can be worth considering. Confirm the exact steps against the Mautic version you run.

What do we need to provide before an API authentication project starts?

Before work starts, the client needs named owners, a test instance, access to a secrets store and a list of data flows. The usual inputs are:

  • A named owner for the Mautic instance and a named owner for each connected system, who can approve scopes and changes.
  • A test Mautic instance close enough to production to prove token behavior, with test contacts instead of real customer records.
  • Access to the secrets store where client credentials and refresh tokens will be kept, along with the policy for who may read them.
  • A list of data flows showing which system calls which Mautic endpoints, how often, and what data moves in each direction.

Agree in advance who receives alerts when an integration fails authentication, because that person will need the data flow list to act on them.

Is basic authentication ever acceptable for the Mautic API?

Basic authentication can be acceptable in narrow cases, but it should be a deliberate exception that someone signs off on. The Mautic authentication docs describe basic authentication for users, which makes it a practical option for a single administrator, a manual test or a short internal script on a locked-down host. Conditions that apply: the connection must use HTTPS end to end because credentials travel with every request, the account must be a dedicated API user with the minimum role, the password must sit in a secrets store and be rotated on a schedule, and the host running the script must be under your control. Integrations that serve several systems or teams are better served by OAuth2, because tokens can be scoped, renewed and revoked without changing a user password.

How long does it take to design token rotation and revocation?

No duration is stated here, because the design effort depends on the drivers below. Rotation design grows with the number of integrations that hold credentials and the number of teams that own them. Each client needs a rule for how often secrets change, how refresh tokens are renewed and what happens when a renewal fails. Revocation needs a documented path that answers who can revoke a client, how the connected system learns that access has ended and how quickly that change reaches every place the token is cached. Teams that already run a secrets store and a rotation process usually move faster than teams designing both from scratch. Ask the provider for a written list of rotation and revocation cases with an owner for each, and confirm how your target system handles token expiry.

What should a quote for Mautic API authentication include?

A quote should start from a written scope, so you can compare proposals on equal terms. Most DeployOpen engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts. Ask that the quote include:

  • The number of API clients, the grant type for each and the target system behind it.
  • The environments covered, such as a test instance and production, and who approves changes between them.
  • The testing plan, including token expiry, refresh failure, revocation and rejected-scope cases.
  • Secrets handling, meaning where credentials are stored and who can access them.
  • Documentation, such as the client inventory, configuration records and a runbook for renewal and revocation.
  • Ownership after handover and whether ongoing support is priced separately.
How does API authentication differ from setting up SAML single sign-on?

API authentication controls how software systems call Mautic, while SAML single sign-on controls how people sign in to the Mautic interface. They are separate projects with separate owners. SAML needs an identity provider that sends email, first name and last name attributes, and the Mautic docs describe no LDAP option for user sign-in. API work centers on API clients, grant types, tokens, scopes and the secrets each connected system holds. An SSO change will not secure an integration by itself, and an API client cannot sign a person in. Teams often start both in the same period, so plan them as two workstreams that share identity owners. Confirm which authentication options your Mautic version offers before committing to a design.

How DeployOpen scopes and delivers Mautic API access

DeployOpen plans and implements Mautic API access inside your own infrastructure, from the choice between OAuth2 and basic authentication through API user design, testing and handover. Engagements are fixed-scope, with the authentication model, API users and deliverables agreed in writing before work starts.

How we scope

  • Inventory every system that will call the Mautic API and the actions each one needs
  • Agree in writing whether OAuth2 grants or basic authentication apply to each integration
  • Define API user roles, permissions and ownership before any credentials are issued

How we build

  • Configure OAuth2 clients and grant types on your Mautic instance, or document the basic authentication setup where it is justified
  • Run a dedicated API user per integration with least-privilege roles and separate credentials
  • Test token issuance, refresh behavior, revocation and rejected requests against your own environment

How we hand over

  • Deliver a written record of the authentication design, grant types, API users and their permissions
  • Provide runbooks for rotating client secrets, revoking tokens and disabling an integration
  • Walk your engineering and security teams through the configuration and the test results

How we support

  • Review authentication settings again when Mautic moves to a new release line on your upgrade schedule
  • Offer ongoing support and periodic access reviews as a retainer, agreed in writing
  • Retest API access after changes to integrations, plugins or the web server configuration

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.