{
  "name": "HowToRomania · Enrich a CRM lead by CUI (webhook)",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": null,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0
        },
        "parameters": [
          {
            "name": "hook",
            "type": "hook:gateway-webhook",
            "label": "Webhook",
            "required": true
          },
          {
            "name": "maxResults",
            "type": "number",
            "label": "Maximum number of results"
          }
        ]
      }
    },
    {
      "id": 7,
      "module": "builtin:BasicRouter",
      "version": 1,
      "mapper": null,
      "metadata": {
        "designer": {
          "x": 150,
          "y": 0
        }
      },
      "routes": [
        {
          "flow": [
            {
              "id": 2,
              "module": "http:ActionSendDataAPIKeyAuth",
              "version": 3,
              "parameters": {
                "auth": null,
                "handleErrors": false
              },
              "mapper": {
                "url": "https://api.howtoromania.io/v1/company/{{trim(1.cui)}}",
                "serializeUrl": false,
                "method": "get",
                "headers": [],
                "qs": [],
                "bodyType": "",
                "parseResponse": true,
                "timeout": "30",
                "shareCookies": false,
                "ca": "",
                "rejectUnauthorized": true,
                "followRedirect": true,
                "useQuerystring": false,
                "gzip": true,
                "useMtls": false,
                "followAllRedirects": false
              },
              "metadata": {
                "designer": {
                  "x": 300,
                  "y": 0,
                  "name": "HowToRomania"
                },
                "restore": {
                  "expect": {
                    "method": {
                      "mode": "chose",
                      "label": "GET"
                    },
                    "headers": {
                      "mode": "chose"
                    },
                    "qs": {
                      "mode": "chose"
                    },
                    "bodyType": {
                      "label": "Empty"
                    }
                  }
                },
                "parameters": [
                  {
                    "name": "auth",
                    "type": "keychain:apikeyauth",
                    "label": "Credentials",
                    "required": true
                  },
                  {
                    "name": "handleErrors",
                    "type": "boolean",
                    "label": "Evaluate all states as errors (except for 2xx and 3xx )",
                    "required": true
                  }
                ]
              },
              "filter": {
                "name": "Has CUI",
                "conditions": [
                  [
                    {
                      "a": "{{trim(1.cui)}}",
                      "o": "exist"
                    }
                  ]
                ]
              }
            },
            {
              "id": 3,
              "module": "builtin:BasicRouter",
              "version": 1,
              "mapper": null,
              "metadata": {
                "designer": {
                  "x": 600,
                  "y": 0
                }
              },
              "routes": [
                {
                  "flow": [
                    {
                      "id": 4,
                      "module": "gateway:WebhookRespond",
                      "version": 1,
                      "parameters": {},
                      "filter": {
                        "name": "Found",
                        "conditions": [
                          [
                            {
                              "a": "{{2.statusCode}}",
                              "o": "number:equal",
                              "b": "200"
                            }
                          ]
                        ]
                      },
                      "mapper": {
                        "status": "200",
                        "body": "{\"ok\":true,\"leadId\":\"{{1.leadId}}\",\"cui\":\"{{2.data.data.cui}}\",\"vatId\":\"{{2.data.data.vatId}}\",\"name\":\"{{2.data.data.name}}\",\"registrationNumber\":\"{{2.data.data.registrationNumber}}\",\"caenCode\":\"{{2.data.data.caenCode}}\",\"active\":{{2.data.data.status.active}},\"vatRegistered\":{{2.data.data.vat.registered}},\"eFacturaRegistered\":{{2.data.data.eFactura.registered}},\"address\":\"{{2.data.data.address.fiscal.formatted}}\"}",
                        "headers": [
                          {
                            "key": "content-type",
                            "value": "application/json"
                          }
                        ]
                      },
                      "metadata": {
                        "designer": {
                          "x": 900,
                          "y": -150
                        }
                      }
                    }
                  ]
                },
                {
                  "flow": [
                    {
                      "id": 5,
                      "module": "gateway:WebhookRespond",
                      "version": 1,
                      "parameters": {},
                      "filter": {
                        "name": "Not found or invalid",
                        "conditions": [
                          [
                            {
                              "a": "{{2.statusCode}}",
                              "o": "number:notequal",
                              "b": "200"
                            }
                          ]
                        ]
                      },
                      "mapper": {
                        "status": "{{2.statusCode}}",
                        "body": "{\"ok\":false,\"leadId\":\"{{1.leadId}}\",\"error\":\"{{2.data.error.code}}\"}",
                        "headers": [
                          {
                            "key": "content-type",
                            "value": "application/json"
                          }
                        ]
                      },
                      "metadata": {
                        "designer": {
                          "x": 900,
                          "y": 150
                        }
                      }
                    }
                  ]
                }
              ]
            }
          ]
        },
        {
          "flow": [
            {
              "id": 6,
              "module": "gateway:WebhookRespond",
              "version": 1,
              "parameters": {},
              "filter": {
                "name": "Missing cui",
                "conditions": [
                  [
                    {
                      "a": "{{trim(1.cui)}}",
                      "o": "notexist"
                    }
                  ]
                ]
              },
              "mapper": {
                "status": "400",
                "body": "{\"ok\":false,\"leadId\":\"{{1.leadId}}\",\"error\":\"missing_cui\",\"message\":\"Send a JSON body with a non-empty cui field, e.g. {\\\"cui\\\":\\\"RO12345678\\\"}. No API call was made.\"}",
                "headers": [
                  {
                    "key": "content-type",
                    "value": "application/json"
                  }
                ]
              },
              "metadata": {
                "designer": {
                  "x": 300,
                  "y": 300
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "metadata": {
    "instant": false,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "eu1.make.com"
  }
}