This is a Python script that uses the python-freeipa and mauticpy libraries to sync users from a FreeIPA server to a Mautic instance:
import ipalib
from mauticpy.api import MauticApi
# Configure FreeIPA connection
ipalib.api.bootstrap(context='cli')
ipalib.api.env['basedn'] = 'dc=example,dc=com'
ipalib.api.env['server'] = 'ipa.example.com'
ipalib.api.env['principal'] = 'admin'
ipalib.api.env['password'] = 'adminpassword'
# Connect to Mautic API
mautic = MauticApi('https://mautic.example.com', 'mauticusername', 'mauticpassword')
# Get all users from FreeIPA
users = ipalib.api.Command['user_find'](sizelimit=0)
# Iterate over users and sync to Mautic
for user in users['result']:
username = user['uid'][0]
email = user['mail'][0]
first_name = user['givenname'][0]
last_name = user['sn'][0]
# Check if user already exists in Mautic
contact_id = None
contacts = mautic.get_contacts(email=email)['contacts']
if len(contacts) > 0:
contact_id = contacts[0]['id']
# Create or update contact in Mautic
if contact_id is None:
mautic.create_contact(email=email, firstname=first_name, lastname=last_name)
print(f"Created contact {email} in Mautic.")
else:
mautic.edit_contact(contact_id, firstname=first_name, lastname=last_name)
print(f"Updated contact {email} in Mautic.")
You’ll need to replace the placeholders in the script with the actual values for your FreeIPA server and Mautic instance. Also, make sure that you have the python-freeipa and mauticpy libraries installed before running the script.