Created
May 2, 2025 17:31
-
-
Save louka1996/e27fef9b7ba16c7040f3d34b29e108a1 to your computer and use it in GitHub Desktop.
Deluge function that integrates with the Google Places API to autocomplete addresses and retrieve postal codes based on place ID, designed for use in Zoho CRM.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string standalone.google_place_api1(String Address, String City, String place_id) | |
| { | |
| data = Map(); | |
| data.put("key", "YOUR_GOOGLE_API_KEY"); // Replace with connection or encrypted variable | |
| data.put("language", "fr"); | |
| if (place_id == "") | |
| { | |
| urlApi = "https://maps.googleapis.com/maps/api/place/autocomplete/json"; | |
| data.put("input", Address + ", " + City + ", Canada"); | |
| response = invokeurl | |
| [ | |
| url : urlApi | |
| type : GET | |
| parameters : data | |
| ]; | |
| info response; | |
| return response; | |
| } | |
| else | |
| { | |
| data.put("place_id", place_id); | |
| data.put("fields", "address_component"); | |
| urlDetails = "https://maps.googleapis.com/maps/api/place/details/json"; | |
| response = invokeurl | |
| [ | |
| url : urlDetails | |
| type : GET | |
| parameters : data | |
| ]; | |
| info response; | |
| addressComponents = response.get("result").get("address_components"); | |
| locationData = Map(); | |
| if (addressComponents.size() > 0) | |
| { | |
| hasSublocality = false; | |
| hasNoCity = false; | |
| for each component in addressComponents | |
| { | |
| types = component.get("types"); | |
| if (types.contains("street_number")) { DataNumber = component.get("short_name"); } | |
| if (types.contains("route")) { DataStreet = component.get("short_name"); } | |
| if (types.contains("sublocality_level_1")) { locationData.put("City", component.get("short_name")); hasSublocality = true; } | |
| if (types.contains("locality") && !hasSublocality) { locationData.put("City", component.get("short_name")); hasNoCity = true; } | |
| if (types.contains("administrative_area_level_3") && !hasSublocality && !hasNoCity) { locationData.put("City", component.get("short_name")); } | |
| if (types.contains("postal_code")) { locationData.put("Postal Code", component.get("short_name")); } | |
| } | |
| locationData.put("Address", DataNumber + " " + DataStreet); | |
| } | |
| else | |
| { | |
| info "No address components found."; | |
| } | |
| return locationData; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
This Deluge script for Zoho CRM connects to the Google Places API to perform two functions:
Address,City, andCanada.Postal Codeand refinedCityfrom a givenplace_idusing Place Details API.If
place_idis empty, the function will call theautocompleteendpoint. If aplace_idis provided, it queries thedetailsendpoint and extracts structured address components like street number, route, postal code, and city/sublocality hierarchy.It returns a raw JSON response (for autocomplete) or a map containing parsed address information (for place_id-based lookup).
This function is particularly useful in CRM modules where accurate and structured address input is critical (e.g., leads, contacts, or custom forms).
Requirements