{
  "name": "Google Sheets \u2192 SIRENE Lookup API \u2192 Google Sheets",
  "flow": [
    {
      "id": 1,
      "module": "cron:Cron",
      "version": 1,
      "parameters": {},
      "mapper": {
        "cron": "0 8 * * *",
        "timezone": "Europe/Bucharest"
      },
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0,
          "name": "Every day at 08:00"
        }
      }
    },
    {
      "id": 2,
      "module": "google-sheets:getRange",
      "version": 2,
      "parameters": {
        "__IMTCONN__": "YOUR_GOOGLE_CONNECTION_ID"
      },
      "mapper": {
        "mode": "select",
        "spreadsheetId": "YOUR_GOOGLE_SHEET_ID",
        "sheetId": "Input",
        "range": "A:A",
        "includesHeaders": true
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0,
          "name": "Read SIREN list"
        },
        "restore": {
          "expect": [
            {
              "name": "spreadsheetId",
              "label": "Spreadsheet",
              "type": "select"
            },
            {
              "name": "sheetId",
              "label": "Sheet",
              "type": "select"
            }
          ]
        }
      }
    },
    {
      "id": 3,
      "module": "builtin:BasicFeeder",
      "version": 1,
      "parameters": {},
      "mapper": {
        "array": "{{2}}"
      },
      "filter": {
        "name": "Skip empty and invalid numbers",
        "conditions": [
          [
            {
              "a": "{{if(length(replace(3.siren_or_siret; \"/\\\\D/\"; \"\")) = 9; true; length(replace(3.siren_or_siret; \"/\\\\D/\"; \"\")) = 14)}}",
              "b": "{{true}}",
              "o": "text:equal"
            }
          ]
        ]
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0,
          "name": "Iterate rows"
        }
      }
    },
    {
      "id": 4,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": {
        "handleErrors": true,
        "useNewZLibDeCompress": true
      },
      "mapper": {
        "url": "https://sirene-lookup-api.corinaflorea8.workers.dev/v1/{{if(length(replace(3.siren_or_siret; \"/\\\\D/\"; \"\")) = 14; \"siret\"; \"siren\")}}/{{replace(3.siren_or_siret; \"/\\\\D/\"; \"\")}}",
        "serializeUrl": false,
        "method": "get",
        "headers": [
          {
            "name": "X-License-Key",
            "value": "{{SIRENE_LICENSE_KEY}}"
          },
          {
            "name": "Accept",
            "value": "application/json"
          }
        ],
        "qs": [],
        "bodyType": "",
        "parseResponse": true,
        "authUser": "",
        "authPass": "",
        "timeout": "30",
        "shareCookies": false,
        "ca": "",
        "rejectUnauthorized": true,
        "followRedirect": true,
        "useQuerystring": false,
        "gzip": true,
        "useMtls": false,
        "followAllRedirects": false
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0,
          "name": "SIRENE Lookup API"
        },
        "restore": {},
        "expect": [
          {
            "name": "url",
            "type": "url",
            "label": "URL",
            "required": true
          },
          {
            "name": "method",
            "type": "select",
            "label": "Method",
            "required": true
          },
          {
            "name": "headers",
            "type": "array",
            "label": "Headers"
          },
          {
            "name": "parseResponse",
            "type": "boolean",
            "label": "Parse response",
            "required": true
          }
        ]
      }
    },
    {
      "id": 5,
      "module": "google-sheets:addRow",
      "version": 2,
      "parameters": {
        "__IMTCONN__": "YOUR_GOOGLE_CONNECTION_ID"
      },
      "mapper": {
        "mode": "select",
        "spreadsheetId": "YOUR_GOOGLE_SHEET_ID",
        "sheetId": "Results",
        "includesHeaders": true,
        "insertDataOption": "INSERT_ROWS",
        "valueInputOption": "USER_ENTERED",
        "values": {
          "0": "{{3.siren_or_siret}}",
          "1": "{{ifempty(4.data.company.siren; 4.data.siren)}}",
          "2": "{{ifempty(4.data.company.name; 4.data.name)}}",
          "3": "{{ifempty(4.data.establishment.address; 4.data.head_office.address)}}",
          "4": "{{ifempty(4.data.company.naf_code; 4.data.naf_code)}}",
          "5": "{{ifempty(4.data.company.status; 4.data.status)}}",
          "6": "{{ifempty(4.data.company.creation_date; 4.data.creation_date)}}",
          "7": "{{ifempty(4.data.company.commercial_opt_out; 4.data.commercial_opt_out)}}",
          "8": "{{ifempty(4.data.company.diffusion.masked; 4.data.diffusion.masked)}}",
          "9": "{{4.error.code}}"
        }
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 0,
          "name": "Write results to Sheets"
        },
        "restore": {
          "expect": [
            {
              "name": "spreadsheetId",
              "label": "Spreadsheet",
              "type": "select"
            },
            {
              "name": "sheetId",
              "label": "Sheet",
              "type": "select"
            }
          ]
        }
      }
    }
  ],
  "metadata": {
    "instant": false,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": true,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "eu1.make.com",
    "notes": "Replace {{SIRENE_LICENSE_KEY}} with a Make secret or connection, never a raw key in the blueprint. Replace YOUR_GOOGLE_SHEET_ID and YOUR_GOOGLE_CONNECTION_ID after import. Leave at least 1 second between HTTP calls (60/min limit). Buy a key at https://corinaflorea.gumroad.com/l/xzhech."
  }
}
