{
  "name": "Jsonpage - Verify and enrich a CSV file dropped in Google Drive",
  "flow": [
    {
      "id": 1,
      "module": "google-drive:watchFilesInFolder",
      "version": 3,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "folderId": "/YOUR_FOLDER_ID",
        "watch": "created",
        "limit": "1",
        "select": "list"
      },
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "New file in the folder"
        }
      }
    },
    {
      "id": 2,
      "module": "google-drive:downloadAFile",
      "version": 3,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "fileId": "{{1.id}}",
        "select": "map"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Download the file"
        }
      },
      "filter": {
        "name": "A CSV file that is not our result",
        "conditions": [
          [
            {
              "a": "{{1.name}}",
              "o": "text:endwith",
              "b": ".csv"
            },
            {
              "a": "{{1.name}}",
              "o": "text:notendwith",
              "b": "-verified.csv"
            }
          ]
        ]
      }
    },
    {
      "id": 3,
      "module": "csv:ParseCSV",
      "version": 1,
      "parameters": {},
      "mapper": {
        "text": "{{2.data}}",
        "delimiter": ";",
        "containsHeaders": true
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Read the CSV (column named siren; use , if your file uses commas)"
        }
      }
    },
    {
      "id": 4,
      "module": "builtin:BasicFeeder",
      "version": 1,
      "parameters": {},
      "mapper": {
        "array": "{{3.array}}"
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0,
          "name": "Each row"
        }
      }
    },
    {
      "id": 5,
      "module": "util:TextAggregator",
      "version": 1,
      "parameters": {
        "feeder": 4,
        "rowSeparator": "other",
        "otherRowSeparator": ","
      },
      "mapper": {
        "value": "\"FR-{{substring(replace(replace(4.siren; \" \"; \"\"); \".\"; \"\"); 0; 9)}}\""
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 0,
          "name": "Identifiers (100 rows at most)"
        }
      }
    },
    {
      "id": 6,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": {
        "handleErrors": false,
        "useNewZLibDeCompress": true
      },
      "mapper": {
        "url": "https://api.jsonpage.com/v2/companies/batch",
        "method": "post",
        "headers": [
          {
            "name": "X-API-Key",
            "value": "PASTE_YOUR_JSONPAGE_API_KEY"
          }
        ],
        "qs": [],
        "bodyType": "raw",
        "contentType": "application/json",
        "parseResponse": true,
        "serializeUrl": false,
        "shareCookies": false,
        "followRedirect": true,
        "useMtls": false,
        "rejectUnauthorized": true,
        "evaluateAllStates": false,
        "timeout": "",
        "data": "{\"ids\": [{{5.text}}], \"include\": [\"address\", \"vat\"]}"
      },
      "metadata": {
        "designer": {
          "x": 1500,
          "y": 0,
          "name": "Verify and enrich (batch)"
        }
      }
    },
    {
      "id": 7,
      "module": "builtin:BasicFeeder",
      "version": 1,
      "parameters": {},
      "mapper": {
        "array": "{{6.data.data}}"
      },
      "metadata": {
        "designer": {
          "x": 1800,
          "y": 0,
          "name": "Each answer"
        }
      }
    },
    {
      "id": 8,
      "module": "util:TextAggregator",
      "version": 1,
      "parameters": {
        "feeder": 7,
        "rowSeparator": "\\n"
      },
      "mapper": {
        "value": "{{7.id}};{{if(7.data; \"yes\"; \"no\")}};{{7.data.name}};{{7.data.status}};{{7.data.address.formatted}};{{7.data.vat.number}};{{7.data.vat.status}};{{7.error.code}}"
      },
      "metadata": {
        "designer": {
          "x": 2100,
          "y": 0,
          "name": "One CSV line per company"
        }
      }
    },
    {
      "id": 9,
      "module": "google-drive:uploadAFile",
      "version": 3,
      "parameters": {
        "__IMTCONN__": null
      },
      "mapper": {
        "select": "map",
        "folderId": "{{1.parents[1]}}",
        "convert": false,
        "filename": "{{replace(1.name; \".csv\"; \"\")}}-verified.csv",
        "data": "id;found;name;status;address;vat_number;vat_status;error\n{{8.text}}"
      },
      "metadata": {
        "designer": {
          "x": 2400,
          "y": 0,
          "name": "Save next to the original"
        }
      }
    }
  ],
  "metadata": {
    "instant": false,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "slots": null,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "eu1.make.com"
  }
}
