Exporting Campaigns
Before importing or exporting data, back up your database as a safety precaution in case you need to restore it. Speak to the administrator of your Mautic instance to do this, as it requires specific technical knowledge.
Important
Both the import and export features are available only in Mautic 7.0 and later versions.
Supported data types
When you select a Campaign, the export feature extracts all Campaign data and entities, along with any dependencies the Campaign needs to function, including:
Dynamic Content
Asset*
Other related dependencies
Note
* The exported Campaign includes only directly associated Assets.
The export command:
Detect use of Plugins and Custom Fields
Include the data to support these dependencies
Important
The importing instance needs the same Custom Fields and Plugins to be present.
Exporting a Campaign
You can export a Campaign in three ways.
1.Using Mautic instance
Go to the Campaigns menu.
Click the three-dot icon next to the Campaign’s name that you want to export to open the options.
Select the Export option from the dropdown menu. It automatically downloads the ZIP file.
2.Using the command line
Use the following commands to save the exported file:
1. In a specific directory
bin/console mautic:entity:export --entity=campaign --id=1 --zip-file --path=path/to-file
Command parameters
--entity: defines the type of entity to export, in this case,campaign.--id: defines the ID of the Campaign to export. When you view or edit the Campaign, look at the URL to find the ID. For example,/s/campaigns/view/123, where123is the ID.--zip-file: creates a ZIP file of the Campaign and its dependencies.--path: specifies the directory to save the exported file.
2. In a JSON file
bin/console mautic:entity:export --entity=campaign --id=1 --json-only
Creates only a JSON file and ignores any additional resources.
3.Using Mautic API
You can programmatically export Campaigns using the Mautic API. To do this, you must authenticate your API request with the credentials stored in Mautic’s settings.
For more details on how to authenticate, see the Authentication page.
Important
The API uses a GET request to export a specific Campaign by ID.
Before running the following cURL or Python examples, ensure you:
Replace
example.comwith the actual Mautic instance domain.Replace
YOUR_ACCESS_TOKENwith a valid authentication token.Verify that the User account has the necessary API permissions.
cURL example
curl --location 'https://example.com/api/campaigns/export/1' \
--header 'Authorization: Bearer YOUR_ACCESS_TOKEN'
Python example
import requests
# API Endpoint
campaign_id = 1
url = f'https://example.com/api/campaigns/export/{campaign_id}'
# Authentication
headers = {
'Authorization': 'Bearer YOUR_ACCESS_TOKEN'
}
# Send export request
response = requests.get(url, headers=headers)
# Handle response
if response.status_code == 200:
export_file = response.content
# Save or process the exported campaign
How Campaign export works
Whether exporting via Mautic instance, the command line, or the API, the process follows these logic steps:
Permissions: verifies that the logged-in User has the correct permissions to export.
Bulk export: supports exporting multiple Campaigns simultaneously.
Data structure: exports data in a structured JSON format to ensure compatibility.
Asset management: exports Assets into a separate folder in their original format.
File packaging: compresses the resulting collection of files into a single ZIP file for easy transfer across systems.