Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 

Repository files navigation

Mautic Segment Export

A simple Bash script for exporting all contacts from a specific Mautic segment to CSV using the Mautic REST API.

The script automatically works through the complete segment, so there is no need to manually specify a contact limit or page size.

Requirements

The script requires:

  • Bash
  • curl
  • jq
  • Access to the Mautic REST API
  • Mautic credentials with permission to read contacts

Configuration

Edit the configuration values at the top of mtc-export.sh:

MAUTIC="https://engage.yourdomain.com"
USER="user"
PASS="pass"

SEGMENT="segment-alias"

Mautic URL

Set MAUTIC to the base URL of your Mautic installation.

MAUTIC="https://engage.example.com"

Do not include /api at the end.

Credentials

Set USER and PASS to credentials that can access the Mautic API.

USER="api-user"
PASS="password"

Segment

SEGMENT must contain the segment alias, not the segment name.

For example, if the segment is named:

Monthly Newsletter Subscribers

and its alias is:

monthly-newsletter

use:

SEGMENT="monthly-newsletter"

Usage

Make the script executable:

chmod +x mtc-export.sh

Then run it:

./mtc-export.sh

The script retrieves contacts from Mautic until the entire segment has been exported.

Progress is displayed while the export runs:

Exported 30 of 247 contacts...
Exported 60 of 247 contacts...
Exported 90 of 247 contacts...

When complete:

Done. Exported 247 contacts to contacts-monthly-newsletter.csv

Output

The generated CSV file is named using the segment alias:

contacts-SEGMENT.csv

For example:

contacts-monthly-newsletter.csv

The CSV currently contains the following fields:

id
firstname
lastname
email
phone
company

Additional Mautic contact fields can be added by modifying the jq section of the script.

For example:

.contacts[] |
[
    .id,
    .fields.all.firstname,
    .fields.all.lastname,
    .fields.all.email,
    .fields.all.phone,
    .fields.all.company
] | @csv

How it works

The script queries:

/api/contacts

using Mautic's contact search syntax:

segment:segment-alias

It reads the number of contacts returned and Mautic's reported total, then advances the API start value until all contacts have been retrieved.

Security

The current script stores the Mautic username and password directly in mtc-export.sh.

Do not commit real credentials to a public repository. For shared or production use, consider moving credentials to environment variables or another secure configuration method.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages