{
 "name": "HDI leads to HubSpot (contact + deal)",
 "flow": [
  {
   "id": 1,
   "module": "gateway:CustomWebHook",
   "version": 1,
   "parameters": {
    "maxResults": 1
   },
   "mapper": {},
   "metadata": {
    "designer": {
     "x": 0,
     "y": 0
    }
   }
  },
  {
   "id": 4,
   "module": "hubspotcrm:MakeAPICall",
   "version": 2,
   "parameters": {},
   "filter": {
    "name": "Real leads with an email (not the test lead)",
    "conditions": [
     [
      {
       "a": "{{1.test}}",
       "b": "false",
       "o": "text:equal"
      },
      {
       "a": "{{1.lead.email}}",
       "o": "exist"
      },
      {
       "a": "{{1.lead.id}}",
       "o": "exist"
      }
     ]
    ]
   },
   "mapper": {
    "url": "/crm/v3/objects/deals/search",
    "method": "POST",
    "headers": [
     {
      "key": "Content-Type",
      "value": "application/json"
     }
    ],
    "qs": [],
    "body": "{\"query\":\"{{replace(1.lead.id; \"/[^A-Za-z0-9_-]/g\"; emptystring)}}\",\"limit\":1,\"properties\":[\"dealname\"]}"
   },
   "metadata": {
    "designer": {
     "x": 300,
     "y": 0
    }
   },
   "onerror": [
    {
     "id": 11,
     "module": "builtin:Break",
     "version": 1,
     "parameters": {},
     "mapper": {
      "count": "3",
      "retry": true,
      "interval": "15"
     },
     "metadata": {
      "designer": {
       "x": 300,
       "y": 300
      }
     }
    }
   ]
  },
  {
   "id": 2,
   "module": "hubspotcrm:upsertAContact",
   "version": 2,
   "parameters": {},
   "filter": {
    "name": "New lead only (no deal with this HDI lead id yet)",
    "conditions": [
     [
      {
       "a": "{{4.statusCode}}",
       "b": "200",
       "o": "number:equal"
      },
      {
       "a": "{{4.body.total}}",
       "b": "0",
       "o": "number:equal"
      }
     ]
    ]
   },
   "mapper": {
    "_method": "all",
    "swapPrimaryEmail": false,
    "parseCustomFields": true,
    "email": "{{1.lead.email}}",
    "company": "{{ifempty(1.lead.company; ignore)}}"
   },
   "metadata": {
    "designer": {
     "x": 600,
     "y": 0
    }
   },
   "onerror": [
    {
     "id": 12,
     "module": "builtin:Break",
     "version": 1,
     "parameters": {},
     "mapper": {
      "count": "3",
      "retry": true,
      "interval": "15"
     },
     "metadata": {
      "designer": {
       "x": 600,
       "y": 300
      }
     }
    }
   ]
  },
  {
   "id": 3,
   "module": "hubspotcrm:createDeal",
   "version": 2,
   "parameters": {},
   "mapper": {
    "_method": "all",
    "parseCustomFields": true,
    "dealname": "HDI screening: {{ifempty(1.lead.company; 1.lead.email)}} ({{1.lead.hdi_score}} of 100)",
    "pipeline": "default",
    "dealstage": "appointmentscheduled",
    "description": "HDI {{1.lead.hdi_score}} of 100, {{1.lead.band}}. Coordination {{1.lead.layers.coordination}}, control {{1.lead.layers.control}}, cognitive {{1.lead.layers.cognitive}}. Operational leak {{1.lead.operational_leak_hours_month}} hours a month. Sector: {{1.lead.industry_label}}. Screening completed {{1.lead.submitted_at}}. HDI lead id {{replace(1.lead.id; \"/[^A-Za-z0-9_-]/g\"; emptystring)}}. Result: {{1.lead.results_url}}",
    "associations": [
     {
      "associationCategory": "HUBSPOT_DEFINED",
      "associationTypeId": "3",
      "toId": "{{2.id}}"
     }
    ]
   },
   "metadata": {
    "designer": {
     "x": 900,
     "y": 0
    }
   },
   "onerror": [
    {
     "id": 13,
     "module": "builtin:Break",
     "version": 1,
     "parameters": {},
     "mapper": {
      "count": "3",
      "retry": true,
      "interval": "15"
     },
     "metadata": {
      "designer": {
       "x": 900,
       "y": 300
      }
     }
    }
   ]
  }
 ],
 "metadata": {
  "instant": true,
  "version": 1,
  "scenario": {
   "roundtrips": 1,
   "maxErrors": 3,
   "autoCommit": true,
   "autoCommitTriggerLast": true,
   "sequential": false,
   "confidential": false,
   "dataloss": false,
   "dlq": true,
   "freshVariables": false
  },
  "designer": {
   "orphans": []
  }
 }
}
