# Integrating with Your CRM

Sync contacts between Mailnaptic and your CRM

Keeping your CRM and Mailnaptic in sync ensures your sales team works with up-to-date email engagement data while your marketing emails reflect the latest CRM information. Mailnaptic supports CRM integration through its API and webhook system.

## Integration approaches

There are three common ways to connect Mailnaptic with your CRM:

| Approach | Best for | Complexity |
| --- | --- | --- |
| Zapier / Make | Teams without developers | Low |
| Outgoing webhooks | Real-time sync to CRM | Medium |
| API-based sync | Full bidirectional sync | High |

## What to sync

### From CRM to Mailnaptic

- **New contacts:** When a lead or customer is created in your CRM, add them to Mailnaptic with the appropriate list and tags.
- **Contact updates:** When a CRM field changes (e.g., deal stage, company name), update the corresponding custom field in Mailnaptic.
- **Deal stage changes:** Use tags or custom fields to reflect pipeline stages so you can segment by deal status.

### From Mailnaptic to CRM

- **Email engagement:** Push open and click events to CRM activity timelines so sales reps see engagement without leaving their CRM.
- **Unsubscribes:** Flag contacts who opt out so sales reps don't inadvertently email them.
- **New subscribers:** When someone subscribes via a Mailnaptic form, create or update the CRM record.

## Setting up real-time sync with webhooks

For pushing Mailnaptic events to your CRM in real time:

1. Create an outgoing webhook endpoint in **Organization → Webhooks**.
2. Point it at your CRM's API (or a middleware layer you control).
3. Subscribe to relevant events: `contact.created`, `contact.updated`, `email.opened`, `email.clicked`, `contact.unsubscribed`.
4. In your middleware, map Mailnaptic event data to your CRM's API format and push updates.

## Setting up bidirectional sync via API

For a full two-way sync, build a sync service that:

1. **Polls or listens** for changes on both sides (Mailnaptic webhooks + CRM webhooks or polling).
2. **Maps fields** between the two systems. Create a field mapping table: 
 ```
 CRM "Company" → Mailnaptic custom field "company"
 CRM "Deal Stage" → Mailnaptic tag "stage:{{value}}"
 Mailnaptic "opened" → CRM activity "Email Opened"
 ```
3. **Handles conflicts** with a "last write wins" or "CRM is source of truth" strategy.
4. **Deduplicates** using email address as the shared identifier.

## CRM-specific tips

- **HubSpot:** Use HubSpot's native webhook triggers plus Mailnaptic's API. Map Mailnaptic tags to HubSpot contact properties.
- **Salesforce:** Use a middleware like Zapier or a custom Apex trigger that calls Mailnaptic's API on record changes.
- **Pipedrive:** Pipedrive's webhook feature can push deal updates to your sync service, which then updates Mailnaptic tags.

## Best practices

- **Start small:** Begin with one-directional sync (e.g., CRM → Mailnaptic) and expand once stable.
- **Log everything:** Maintain sync logs to debug mismatches.
- **Use idempotent operations:** Mailnaptic's upsert contact endpoint prevents duplicates even if sync runs twice.
- **Rate limit awareness:** Respect API rate limits on both Mailnaptic and your CRM to avoid throttling.

> **Tip:** Use Mailnaptic's contact tags to reflect CRM segments (e.g., `crm:customer`, `crm:prospect`) so you can target campaigns based on CRM data.
