{
  "name": "Google Maps leads to a Google Sheet with Maps Harvest",
  "flow": [
    {
      "id": 1,
      "module": "util:SetVariables",
      "version": 1,
      "parameters": {},
      "mapper": {
        "variables": [
          {
            "name": "api_key",
            "value": "mh_live_PASTE_YOUR_KEY_HERE"
          },
          {
            "name": "query",
            "value": "Dentist"
          },
          {
            "name": "country",
            "value": "us"
          },
          {
            "name": "states",
            "value": "Texas"
          },
          {
            "name": "cities",
            "value": "Austin"
          },
          {
            "name": "max_total_results",
            "value": "50"
          }
        ]
      },
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0
        }
      }
    },
    {
      "module": "http:MakeRequest",
      "version": 4,
      "parameters": {
        "authenticationType": "noAuth"
      },
      "id": 2,
      "mapper": {
        "stopOnHttpError": true,
        "timeout": 40,
        "allowRedirects": true,
        "shareCookies": false,
        "requestCompressedContent": true,
        "url": "https://api.mapsharvest.com/scrape",
        "method": "post",
        "headers": [
          {
            "name": "Authorization",
            "value": "Bearer {{1.api_key}}"
          }
        ],
        "contentType": "json",
        "inputMethod": "jsonString",
        "jsonStringBodyContent": "{\"query\": \"{{1.query}}\", \"country\": \"{{1.country}}\", \"states\": \"{{1.states}}\", \"cities\": \"{{1.cities}}\", \"max_total_results\": {{1.max_total_results}}, \"require_phone\": true, \"name\": \"Make: {{1.query}} in {{1.cities}}\"}",
        "parseResponse": true
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0
        }
      }
    },
    {
      "id": 3,
      "module": "builtin:BasicRepeater",
      "version": 1,
      "parameters": {},
      "mapper": {
        "start": "1",
        "repeats": "8",
        "step": "1"
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0
        }
      }
    },
    {
      "id": 4,
      "module": "util:GetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "leads_saved"
      },
      "metadata": {
        "designer": {
          "x": 750,
          "y": 0
        }
      }
    },
    {
      "id": 5,
      "module": "util:FunctionSleep",
      "version": 1,
      "parameters": {},
      "filter": {
        "name": "Not saved yet",
        "conditions": [
          [
            {
              "a": "{{4.leads_saved}}",
              "o": "notexist"
            }
          ]
        ]
      },
      "mapper": {
        "duration": "30"
      },
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0
        }
      }
    },
    {
      "module": "http:MakeRequest",
      "version": 4,
      "parameters": {
        "authenticationType": "noAuth"
      },
      "id": 6,
      "mapper": {
        "stopOnHttpError": true,
        "timeout": 40,
        "allowRedirects": true,
        "shareCookies": false,
        "requestCompressedContent": true,
        "url": "https://api.mapsharvest.com/jobs/{{2.data.job_id}}",
        "method": "get",
        "headers": [
          {
            "name": "Authorization",
            "value": "Bearer {{1.api_key}}"
          }
        ],
        "parseResponse": true
      },
      "metadata": {
        "designer": {
          "x": 1200,
          "y": 0
        }
      }
    },
    {
      "module": "http:MakeRequest",
      "version": 4,
      "parameters": {
        "authenticationType": "noAuth"
      },
      "id": 7,
      "filter": {
        "name": "Search finished",
        "conditions": [
          [
            {
              "a": "{{6.data.status}}",
              "b": "completed",
              "o": "text:equal"
            }
          ],
          [
            {
              "a": "{{6.data.status}}",
              "b": "stopped",
              "o": "text:equal"
            }
          ]
        ]
      },
      "mapper": {
        "stopOnHttpError": true,
        "timeout": 40,
        "allowRedirects": true,
        "shareCookies": false,
        "requestCompressedContent": true,
        "url": "https://api.mapsharvest.com/jobs/{{2.data.job_id}}/download?fmt=csv",
        "method": "get",
        "headers": [
          {
            "name": "Authorization",
            "value": "Bearer {{1.api_key}}"
          }
        ],
        "parseResponse": false
      },
      "metadata": {
        "designer": {
          "x": 1500,
          "y": 0
        }
      }
    },
    {
      "id": 8,
      "module": "google-drive:uploadAFile",
      "version": 4,
      "parameters": {
        "__IMTCONN__": ""
      },
      "mapper": {
        "select": "map",
        "folderId": "root",
        "convert": true,
        "filename": "Maps Harvest - {{1.query}} in {{1.cities}} {{formatDate(now; \"YYYY-MM-DD\")}}.csv",
        "data": "{{7.data}}"
      },
      "metadata": {
        "designer": {
          "x": 1800,
          "y": 0
        }
      }
    },
    {
      "id": 9,
      "module": "util:SetVariable2",
      "version": 1,
      "parameters": {},
      "mapper": {
        "name": "leads_saved",
        "value": "1"
      },
      "metadata": {
        "designer": {
          "x": 2100,
          "y": 0
        }
      }
    }
  ],
  "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": []
    }
  }
}