{
  "name": "MailGuard — Onboard domain from CRM",
  "nodes": [
    {
      "parameters": {
        "events": ["dealStageChanged"],
        "filters": { "stage": "won" }
      },
      "id": "1",
      "name": "CRM — Deal Won",
      "type": "n8n-nodes-base.hubspotTrigger",
      "typeVersion": 1,
      "position": [240, 300],
      "notes": "Replace with your CRM's trigger node (Pipedrive, Close, Salesforce). Whatever fires on a closed-won deal."
    },
    {
      "parameters": {
        "values": {
          "string": [
            {
              "name": "domain",
              "value": "={{ $json.company.domain || $json.deal.company_domain }}"
            },
            {
              "name": "company_name",
              "value": "={{ $json.company.name || $json.deal.company_name }}"
            }
          ]
        },
        "options": {}
      },
      "id": "2",
      "name": "Set — extract domain",
      "type": "n8n-nodes-base.set",
      "typeVersion": 2,
      "position": [460, 300]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.themailguard.ai/v1/domains",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Idempotency-Key",
              "value": "=crm-deal-{{ $json.deal_id }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"name\": \"{{ $json.domain }}\",\n  \"display_name\": \"{{ $json.company_name }}\"\n}",
        "options": {}
      },
      "id": "3",
      "name": "MailGuard — POST /v1/domains",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [680, 300],
      "credentials": {
        "httpHeaderAuth": {
          "id": "MAILGUARD_API_KEY_ID",
          "name": "MailGuard API key"
        }
      },
      "notes": "Idempotency-Key prevents duplicate domain rows on n8n retries within 24h."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://api.themailguard.ai/v1/checks",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"domain_id\": \"{{ $json.id }}\"\n}",
        "options": {}
      },
      "id": "4",
      "name": "MailGuard — POST /v1/checks",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [900, 300],
      "credentials": {
        "httpHeaderAuth": {
          "id": "MAILGUARD_API_KEY_ID",
          "name": "MailGuard API key"
        }
      }
    },
    {
      "parameters": {
        "channel": "#sales-onboarding",
        "text": "=:white_check_mark: MailGuard monitoring is live for *{{ $node['Set — extract domain'].json['domain'] }}* (deal: {{ $('CRM — Deal Won').item.json.deal_id }}). First health score available in ~30 seconds."
      },
      "id": "5",
      "name": "Slack — notify account manager",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.2,
      "position": [1120, 300],
      "credentials": {
        "slackApi": {
          "id": "SLACK_CRED_ID",
          "name": "Slack workspace"
        }
      }
    }
  ],
  "connections": {
    "CRM — Deal Won": {
      "main": [[{ "node": "Set — extract domain", "type": "main", "index": 0 }]]
    },
    "Set — extract domain": {
      "main": [[{ "node": "MailGuard — POST /v1/domains", "type": "main", "index": 0 }]]
    },
    "MailGuard — POST /v1/domains": {
      "main": [[{ "node": "MailGuard — POST /v1/checks", "type": "main", "index": 0 }]]
    },
    "MailGuard — POST /v1/checks": {
      "main": [[{ "node": "Slack — notify account manager", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveExecutionProgress": true
  },
  "tags": [{ "name": "mailguard" }, { "name": "crm-onboarding" }],
  "meta": {
    "schema": "mailguard-integration-template/v1",
    "documentation_url": "https://themailguard.ai/integrations/n8n-onboard-domain-from-crm",
    "mailguard_api_version": "v1",
    "min_plan": "solo",
    "scopes_required": ["domains:write", "checks:run"]
  }
}
