{
 "name": "S04 - API לקליטת לידים",
 "flow": [
  {
   "id": 1,
   "module": "gateway:CustomWebHook",
   "version": 1,
   "parameters": {
    "hook": null,
    "maxResults": 1
   },
   "mapper": {},
   "metadata": {
    "designer": {
     "x": 0,
     "y": 0,
     "name": "POST /lead (עם Headers)"
    }
   }
  },
  {
   "id": 6,
   "module": "builtin:BasicRouter",
   "version": 1,
   "parameters": {},
   "mapper": null,
   "metadata": {
    "designer": {
     "x": 600,
     "y": 0,
     "name": "אימות וולידציה"
    }
   },
   "routes": [
    {
     "flow": [
      {
       "id": 2,
       "module": "util:SetVariables",
       "version": 1,
       "parameters": {},
       "mapper": {
        "variables": [
         {
          "name": "email",
          "value": "{{lower(trim(1.email))}}"
         },
         {
          "name": "domain",
          "value": "{{last(split(lower(trim(1.email)); \"@\"))}}"
         },
         {
          "name": "leadId",
          "value": "L-{{formatDate(now; \"YYYYMMDDHHmmss\")}}"
         }
        ],
        "scope": "roundtrip"
       },
       "metadata": {
        "designer": {
         "x": 900,
         "y": -200,
         "name": "העשרה"
        }
       },
       "filter": {
        "name": "מאומת + מייל תקין",
        "conditions": [
         [
          {
           "a": "{{get(map(1.__IMTHEADERS__; \"value\"; \"name\"; \"x-api-key\"); 1)}}",
           "o": "text:equal",
           "b": "REPLACE_WITH_SECRET"
          },
          {
           "a": "{{1.email}}",
           "o": "text:matches",
           "b": "^[^@\\s]+@[^@\\s]+\\.[^@\\s]+$"
          }
         ]
        ]
       }
      },
      {
       "id": 3,
       "module": "gateway:WebhookRespond",
       "version": 1,
       "parameters": {},
       "mapper": {
        "status": "201",
        "body": "{\"ok\": true, \"leadId\": \"{{2.leadId}}\", \"domain\": \"{{2.domain}}\"}",
        "headers": [
         {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
         }
        ]
       },
       "metadata": {
        "designer": {
         "x": 1200,
         "y": -200,
         "name": "201 Created"
        }
       }
      }
     ]
    },
    {
     "flow": [
      {
       "id": 4,
       "module": "gateway:WebhookRespond",
       "version": 1,
       "parameters": {},
       "mapper": {
        "status": "400",
        "body": "{\"ok\": false, \"error\": \"invalid email\"}",
        "headers": [
         {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
         }
        ]
       },
       "metadata": {
        "designer": {
         "x": 900,
         "y": 0,
         "name": "400 מייל לא תקין"
        }
       },
       "filter": {
        "name": "מאומת, מייל שגוי",
        "conditions": [
         [
          {
           "a": "{{get(map(1.__IMTHEADERS__; \"value\"; \"name\"; \"x-api-key\"); 1)}}",
           "o": "text:equal",
           "b": "REPLACE_WITH_SECRET"
          },
          {
           "a": "{{1.email}}",
           "o": "notExist"
          }
         ],
         [
          {
           "a": "{{get(map(1.__IMTHEADERS__; \"value\"; \"name\"; \"x-api-key\"); 1)}}",
           "o": "text:equal",
           "b": "REPLACE_WITH_SECRET"
          },
          {
           "a": "{{contains(1.email; \"@\")}}",
           "o": "equal",
           "b": "false"
          }
         ]
        ]
       }
      }
     ]
    },
    {
     "flow": [
      {
       "id": 5,
       "module": "gateway:WebhookRespond",
       "version": 1,
       "parameters": {},
       "mapper": {
        "status": "401",
        "body": "{\"ok\": false, \"error\": \"unauthorized\"}",
        "headers": [
         {
          "key": "Content-Type",
          "value": "application/json; charset=utf-8"
         }
        ]
       },
       "metadata": {
        "designer": {
         "x": 900,
         "y": 200,
         "name": "401 לא מורשה"
        }
       },
       "filter": {
        "name": "מפתח שגוי",
        "conditions": [
         [
          {
           "a": "{{get(map(1.__IMTHEADERS__; \"value\"; \"name\"; \"x-api-key\"); 1)}}",
           "o": "text:notEqual",
           "b": "REPLACE_WITH_SECRET"
          }
         ]
        ]
       }
      }
     ]
    }
   ]
  }
 ],
 "metadata": {
  "instant": true,
  "version": 1,
  "scenario": {
   "roundtrips": 1,
   "maxErrors": 3,
   "autoCommit": true,
   "autoCommitTriggerLast": true,
   "sequential": false,
   "slots": null,
   "confidential": false,
   "dataloss": false,
   "dlq": true,
   "freshVariables": false
  },
  "designer": {
   "orphans": []
  },
  "zone": "eu1.make.com"
 }
}