Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save louka1996/e27fef9b7ba16c7040f3d34b29e108a1 to your computer and use it in GitHub Desktop.

Select an option

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.
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;
}
}
@louka1996
Copy link
Author

Description

This Deluge script for Zoho CRM connects to the Google Places API to perform two functions:

  1. Autocomplete an address using a search string composed of Address, City, and Canada.
  2. Retrieve the Postal Code and refined City from a given place_id using Place Details API.

If place_id is empty, the function will call the autocomplete endpoint. If a place_id is provided, it queries the details endpoint 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

  • Google Cloud account with Places API enabled.
  • A valid API key with billing enabled.
  • The API key must be added securely using Zoho's connections, or stored and encrypted — do not hardcode in production.
  • Ensure your CRM modules or workflows handle the returned structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment