{"id":2107,"date":"2022-11-08T17:44:23","date_gmt":"2022-11-08T17:44:23","guid":{"rendered":"https:\/\/serviceobjects.wpaladdin.com\/?post_type=serviceobjects&#038;p=2107"},"modified":"2025-09-27T12:37:26","modified_gmt":"2025-09-27T19:37:26","slug":"agca-rest","status":"publish","type":"page","link":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/","title":{"rendered":"AGCA &#8211; REST"},"content":{"rendered":"\n<div class=\"wp-block-create-block-tabs\"><ul class=\"tab-labels\" role=\"tablist\" aria-label=\"tabbed content\"><li class=\"tab-label active\" role=\"tab\" aria-selected=\"true\" aria-controls=\"C#\" tabindex=\"0\">C#<\/li><li class=\"tab-label\" role=\"tab\" aria-selected=\"false\" aria-controls=\"Python\" tabindex=\"0\">Python<\/li><li class=\"tab-label\" role=\"tab\" aria-selected=\"false\" aria-controls=\"NodeJS\" tabindex=\"0\">NodeJS<\/li><\/ul><div class=\"tab-content\">\n<div class=\"wp-block-create-block-tab tab-panel\" role=\"tabpanel\" tabindex=\"0\">\n<p><strong>Address GeoCoder Canada C# Rest Snippet<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">\ufeffusing System.Web;\n\n\nnamespace address_geocode_canada_dot_net.REST\n{\n    \/\/\/ &lt;summary>\n    \/\/\/ Provides functionality to call the ServiceObjects Address Geocode CA (AGCA) REST API's GetGeoLocation endpoint,\n    \/\/\/ retrieving geocoding information (e.g., latitude, longitude, postal code) for a given Canadian address with fallback to a backup endpoint\n    \/\/\/ for reliability in live mode.\n    \/\/\/ &lt;\/summary>\n    public static class GetGeoLocationClient\n    {\n        private const string LiveBaseUrl = \"https:\/\/sws.serviceobjects.com\/GCC\/api.svc\/json\/\";\n        private const string BackupBaseUrl = \"https:\/\/swsbackup.serviceobjects.com\/GCC\/api.svc\/json\/\";\n        private const string TrialBaseUrl = \"https:\/\/trial.serviceobjects.com\/GCC\/api.svc\/json\/\";\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Synchronously calls the GetGeoLocation REST endpoint to retrieve geocoding information,\n        \/\/\/ attempting the primary endpoint first and falling back to the backup if the response is invalid\n        \/\/\/ (Error.Number == \"4\") in live mode.\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"input\">The input parameters including address, municipality, province, postal code, and license key.&lt;\/param>\n        \/\/\/ &lt;returns>Deserialized &lt;see cref=\"GetGeoLocationResponse\"\/> containing geocoding data or an error.&lt;\/returns>\n        public static GetGeoLocationResponse Invoke(GetGeoLocationInput input)\n        {\n            \/\/ Use query string parameters so missing\/optional fields don't break the URL\n            string url = BuildUrl(input, input.IsLive ? LiveBaseUrl : TrialBaseUrl);\n            GetGeoLocationResponse response = Helper.HttpGet&lt;GetGeoLocationResponse>(url, input.TimeoutSeconds);\n\n            \/\/ Fallback on error in live mode\n            if (input.IsLive &amp;&amp; !IsValid(response))\n            {\n                string fallbackUrl = BuildUrl(input, BackupBaseUrl);\n                GetGeoLocationResponse fallbackResponse = Helper.HttpGet&lt;GetGeoLocationResponse>(fallbackUrl, input.TimeoutSeconds);\n                return fallbackResponse;\n            }\n\n            return response;\n        }\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Asynchronously calls the GetGeoLocation REST endpoint to retrieve geocoding information,\n        \/\/\/ attempting the primary endpoint first and falling back to the backup if the response is invalid\n        \/\/\/ (Error.Number == \"4\") in live mode.\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"input\">The input parameters including address, municipality, province, postal code, and license key.&lt;\/param>\n        \/\/\/ &lt;returns>Deserialized &lt;see cref=\"GetGeoLocationResponse\"\/> containing geocoding data or an error.&lt;\/returns>\n        public static async Task&lt;GetGeoLocationResponse> InvokeAsync(GetGeoLocationInput input)\n        {\n            \/\/ Use query string parameters so missing\/optional fields don't break the URL\n            string url = BuildUrl(input, input.IsLive ? LiveBaseUrl : TrialBaseUrl);\n            GetGeoLocationResponse response = await Helper.HttpGetAsync&lt;GetGeoLocationResponse>(url, input.TimeoutSeconds).ConfigureAwait(false);\n\n            \/\/ Fallback on error in live mode\n            if (input.IsLive &amp;&amp; !IsValid(response))\n            {\n                string fallbackUrl = BuildUrl(input, BackupBaseUrl);\n                GetGeoLocationResponse fallbackResponse = await Helper.HttpGetAsync&lt;GetGeoLocationResponse>(fallbackUrl, input.TimeoutSeconds).ConfigureAwait(false);\n                return fallbackResponse;\n            }\n\n            return response;\n        }\n\n        \/\/ Build the full request URL, including URL-encoded query string\n        public static string BuildUrl(GetGeoLocationInput input, string baseUrl)\n        {\n            \/\/ Construct query string with URL-encoded parameters\n            string qs = $\"GetGeoLocation?\" +\n                        $\"Address={HttpUtility.UrlEncode(input.Address)}\" +\n                        $\"&amp;Municipality={HttpUtility.UrlEncode(input.Municipality)}\" +\n                        $\"&amp;Province={HttpUtility.UrlEncode(input.Province)}\" +\n                        $\"&amp;PostalCode={HttpUtility.UrlEncode(input.PostalCode)}\" +\n                        $\"&amp;LicenseKey={HttpUtility.UrlEncode(input.LicenseKey)}\";\n            return baseUrl + qs;\n        }\n\n        private static bool IsValid(GetGeoLocationResponse response) => response?.Error == null || response.Error.Number != \"4\";\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Input parameters for the GetGeoLocation API call. Represents a Canadian address to geocode\n        \/\/\/ and returns latitude, longitude, postal code, and match code with cascading logic for partial matches.\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"Address\">Address line of the address to geocode (e.g., \"124 Main Street\"). Required.&lt;\/param>\n        \/\/\/ &lt;param name=\"Municipality\">The municipality of the address to geocode (e.g., \"Cayuga\"). Optional if postal code is provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"Province\">The province of the address to geocode (e.g., \"ON\"). Optional if postal code is provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"PostalCode\">The postal code of the address to geocode. Optional if municipality and province are provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"LicenseKey\">The license key to authenticate the API request.&lt;\/param>\n        \/\/\/ &lt;param name=\"IsLive\">Indicates whether to use the live service (true) or trial service (false).&lt;\/param>\n        \/\/\/ &lt;param name=\"TimeoutSeconds\">Timeout duration for the API call, in seconds.&lt;\/param>\n        public record GetGeoLocationInput(\n             string Address = \"\",\n             string Municipality = \"\",\n             string Province = \"\",\n             string PostalCode = \"\",\n             string LicenseKey = \"\",\n             bool IsLive = true,\n             int TimeoutSeconds = 15\n        );\n    }\n}\n\n\n\n\ufeffusing System.Runtime.Serialization;\n\nnamespace address_geocode_canada_dot_net.REST\n{\n    \/\/\/ &lt;summary>\n    \/\/\/ Response from GetGeoLocation API, containing the latitude, longitude, postal code, \n    \/\/\/ and match code for the given Canadian address.\n    \/\/\/ &lt;\/summary>\n    [DataContract]\n    public class GetGeoLocationResponse\n    {\n        public string Latitude { get; set; }\n        public string Longitude { get; set; }\n        public string PostalCode { get; set; }\n        public string MatchCode { get; set; }\n        public Error Error { get; set; }\n\n        public override string ToString()\n        {\n            return $\"Latitude: {Latitude}\\n\" +\n                   $\"Longitude: {Longitude}\\n\" +\n                   $\"PostalCode: {PostalCode}\\n\" +\n                   $\"MatchCode: {MatchCode}\\n\" +\n                   $\"Error: {(Error != null ? Error.ToString() : \"null\")}\";\n        }\n    }\n\n    [DataContract]\n    public class GetPostalCodeInfoResponse\n    {\n        public string Latitude { get; set; }\n        public string Longitude { get; set; }\n        public string PostalCode { get; set; }\n        public string TimeZone { get; set; }\n        public string DST { get; set; }\n        public string AreaCode { get; set; }\n        public string City { get; set; }\n        public string CityPopulation { get; set; }\n        public string Province { get; set; }\n        public Error Error { get; set; }\n\n        public override string ToString()\n        {\n            return $\"Latitude: {Latitude}\\n\" +\n                   $\"Longitude: {Longitude}\\n\" +\n                   $\"PostalCode: {PostalCode}\\n\" +\n                   $\"TimeZone: {TimeZone}\\n\" +\n                   $\"DST: {DST}\\n\" +\n                   $\"AreaCode: {AreaCode}\\n\" +\n                   $\"City: {City}\\n\" +\n                   $\"CityPopulation: {CityPopulation}\\n\" +\n                   $\"Province: {Province}\\n\" +\n                   $\"Error: {(Error != null ? Error.ToString() : \"null\")}\";\n        }\n    }\n\n    \/\/\/ &lt;summary>\n    \/\/\/ Response from GetGeoLocationByMunicipalityProvince API, containing the latitude, longitude, \n    \/\/\/ postal code, and error for the given Canadian municipality and province.\n    \/\/\/ &lt;\/summary>\n    [DataContract]\n    public class GetGeoLocationByMunicipalityProvinceResponse\n    {\n        public string Latitude { get; set; }\n        public string Longitude { get; set; }\n        public string PostalCode { get; set; }\n        public Error Error { get; set; }\n        public override string ToString()\n        {\n            return $\"Latitude: {Latitude}\\n\" +\n                   $\"Longitude: {Longitude}\\n\" +\n                   $\"PostalCode: {PostalCode}\\n\" +\n                   $\"Error: {(Error != null ? Error.ToString() : \"null\")}\";\n        }\n    }\n\n    \/\/\/ &lt;summary>\n    \/\/\/ Error object for API responses\n    \/\/\/ &lt;\/summary>\n    [DataContract]\n    public class Error\n    {\n        public string Desc { get; set; }\n        public string Number { get; set; }\n\n        public string Location { get; set; }\n\n        public override string ToString()\n        {\n            return $\"Desc: {Desc}, Number: {Number}, Location: {Location}\";\n        }\n    }\n}\n\n\ufeffusing System.Text.Json;\nusing System.Web;\n\nnamespace address_geocode_canada_dot_net.REST\n{\n    public class Helper\n    {\n        public static T HttpGet&lt;T>(string url, int timeoutSeconds)\n        {\n            using var httpClient = new HttpClient\n            {\n                Timeout = TimeSpan.FromSeconds(timeoutSeconds)\n            };\n            using var request = new HttpRequestMessage(HttpMethod.Get, url);\n            using HttpResponseMessage response = httpClient\n                .SendAsync(request)\n                .GetAwaiter()\n                .GetResult();\n            response.EnsureSuccessStatusCode();\n            using Stream responseStream = response.Content\n                .ReadAsStreamAsync()\n                .GetAwaiter()\n                .GetResult();\n            var options = new JsonSerializerOptions\n            {\n                PropertyNameCaseInsensitive = true\n            };\n            object? obj = JsonSerializer.Deserialize(responseStream, typeof(T), options);\n            T result = (T)obj!;\n            return result;\n        }\n\n        \/\/ Asynchronous HTTP GET and JSON deserialize\n        public static async Task&lt;T> HttpGetAsync&lt;T>(string url, int timeoutSeconds)\n        {\n            HttpClient HttpClient = new HttpClient();\n            HttpClient.Timeout = TimeSpan.FromSeconds(timeoutSeconds);\n            using var httpResponse = await HttpClient.GetAsync(url).ConfigureAwait(false);\n            httpResponse.EnsureSuccessStatusCode();\n            var stream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);\n            return JsonSerializer.Deserialize&lt;T>(stream)!;\n        }\n\n        public static string UrlEncode(string value) => HttpUtility.UrlEncode(value ?? string.Empty);\n    }\n}\n<\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-create-block-tab tab-panel\" role=\"tabpanel\" tabindex=\"0\">\n<p><strong>Address GeoCoder Canada Python Code Snippet<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import requests\nfrom agca_response import GetGeoLocationResponse, Error\n\n# Endpoint URLs for ServiceObjects Address Geocode CA (AGCA) API\nprimary_url = \"https:\/\/sws.serviceobjects.com\/GCC\/api.svc\/json\/GetGeoLocation?\"\nbackup_url = \"https:\/\/swsbackup.serviceobjects.com\/GCC\/api.svc\/json\/GetGeoLocation?\"\ntrial_url = \"https:\/\/trial.serviceobjects.com\/GCC\/api.svc\/json\/GetGeoLocation?\"\n\ndef get_geo_location(\n    address: str,\n    municipality: str,\n    province: str,\n    postal_code: str,\n    license_key: str,\n    is_live: bool = True\n) -> GetGeoLocationResponse:\n    \"\"\"\n    Call ServiceObjects Address Geocode CA (AGCA) API's GetGeoLocation endpoint\n    to retrieve geocoding information (latitude, longitude, postal code, match code) for a given Canadian address.\n\n    Parameters:\n        address: Address line of the address to geocode (e.g., \"123 Main Street\").\n        municipality: The municipality of the address to geocode (e.g., \"Cayuga\").\n        province: The province of the address to geocode (e.g., \"ON\").\n        postal_code: The postal code of the address to geocode (e.g., \"N0A 1E0\").\n        license_key: Your ServiceObjects license key.\n        is_live: Use live or trial servers.\n\n    Returns:\n        GetGeoLocationResponse: Parsed JSON response with geocoding results or error details.\n\n    Raises:\n        RuntimeError: If the API returns an error payload.\n        requests.RequestException: On network\/HTTP failures (trial mode).\n    \"\"\"\n    params = {\n        \"Address\": address,\n        \"Municipality\": municipality,\n        \"Province\": province,\n        \"PostalCode\": postal_code,\n        \"LicenseKey\": license_key,\n    }\n    # Select the base URL: production vs trial\n    url = primary_url if is_live else trial_url\n\n    try:\n        # Attempt primary (or trial) endpoint\n        response = requests.get(url, params=params, timeout=10)\n        response.raise_for_status()\n        data = response.json()\n\n        # If API returned an error in JSON payload, trigger fallback\n        error = data.get('Error', None)\n        if not (error is None or error.get('Number', None) != \"4\"):\n            if is_live:\n                # Try backup URL\n                response = requests.get(backup_url, params=params, timeout=10)\n                response.raise_for_status()\n                data = response.json()\n\n                # If still error, propagate exception\n                if 'Error' in data:\n                    raise RuntimeError(f\"AGCA service error: {data['Error']}\")\n\n        # Convert JSON response to GetGeoLocationResponse for structured access\n        error = Error(**data.get(\"Error\", {})) if data.get(\"Error\") else None\n\n        return GetGeoLocationResponse(\n            Latitude=data.get(\"Latitude\"),\n            Longitude=data.get(\"Longitude\"),\n            PostalCode=data.get(\"PostalCode\"),\n            MatchCode=data.get(\"MatchCode\"),\n            Error=error,\n        )\n\n    except requests.RequestException as req_exc:\n        # Network or HTTP-level error occurred\n        if is_live:\n            try:\n                # Fallback to backup URL\n                response = requests.get(backup_url, params=params, timeout=10)\n                response.raise_for_status()\n                data = response.json()\n                if \"Error\" in data:\n                    raise RuntimeError(f\"AGCA backup error: {data['Error']}\") from req_exc\n\n                error = Error(**data.get(\"Error\", {})) if data.get(\"Error\") else None\n\n                return GetGeoLocationResponse(\n                    Latitude=data.get(\"Latitude\"),\n                    Longitude=data.get(\"Longitude\"),\n                    PostalCode=data.get(\"PostalCode\"),\n                    MatchCode=data.get(\"MatchCode\"),\n                    Error=error,\n                )\n            except Exception as backup_exc:\n                raise RuntimeError(\"AGCA service unreachable on both endpoints\") from backup_exc\n        else:\n            raise RuntimeError(f\"AGCA trial error: {str(req_exc)}\") from req_exc\n\n\nfrom dataclasses import dataclass\nfrom typing import Optional\n\n@dataclass\nclass GetGeoLocationInput:\n    Address: Optional[str] = None\n    Municipality: Optional[str] = None\n    Province: Optional[str] = None\n    PostalCode: Optional[str] = None\n    LicenseKey: Optional[str] = None\n    IsLive: bool = True\n    TimeoutSeconds: int = 15\n\n    def __str__(self) -> str:\n        return (f\"GetGeoLocationInput: Address={self.Address}, Municipality={self.Municipality}, \"\n                f\"Province={self.Province}, PostalCode={self.PostalCode}, LicenseKey={self.LicenseKey}, \"\n                f\"IsLive={self.IsLive}, TimeoutSeconds={self.TimeoutSeconds}\")\n\n@dataclass\nclass GetPostalCodeInfoInput:\n    PostalCode: Optional[str] = None\n    LicenseKey: Optional[str] = None\n    IsLive: bool = True\n    TimeoutSeconds: int = 15\n\n    def __str__(self) -> str:\n        return (f\"GetPostalCodeInfoInput: PostalCode={self.PostalCode}, LicenseKey={self.LicenseKey}, \"\n                f\"IsLive={self.IsLive}, TimeoutSeconds={self.TimeoutSeconds}\")\n\n@dataclass\nclass GetGeoLocationByMunicipalityProvinceInput:\n    Municipality: Optional[str] = None\n    Province: Optional[str] = None\n    LicenseKey: Optional[str] = None\n    IsLive: bool = True\n    TimeoutSeconds: int = 15\n\n    def __str__(self) -> str:\n        return (f\"GetGeoLocationByMunicipalityProvinceInput: Municipality={self.Municipality}, \"\n                f\"Province={self.Province}, LicenseKey={self.LicenseKey}, \"\n                f\"IsLive={self.IsLive}, TimeoutSeconds={self.TimeoutSeconds}\")\n\n@dataclass\nclass Error:\n    Desc: Optional[str] = None\n    Number: Optional[str] = None\n    Location: Optional[str] = None\n\n    def __str__(self) -> str:\n        return f\"Error: Desc={self.Desc}, Number={self.Number}, Location={self.Location}\"\n\n@dataclass\nclass GetGeoLocationResponse:\n    Latitude: Optional[str] = None\n    Longitude: Optional[str] = None\n    PostalCode: Optional[str] = None\n    MatchCode: Optional[str] = None\n    Error: Optional['Error'] = None\n\n    def __str__(self) -> str:\n        error = str(self.Error) if self.Error else 'None'\n        return (f\"GetGeoLocationResponse: Latitude={self.Latitude}, Longitude={self.Longitude}, \"\n                f\"PostalCode={self.PostalCode}, MatchCode={self.MatchCode}, Error={error}\")\n\n@dataclass\nclass GetPostalCodeInfoResponse:\n    Latitude: Optional[str] = None\n    Longitude: Optional[str] = None\n    PostalCode: Optional[str] = None\n    TimeZone: Optional[str] = None\n    DST: Optional[str] = None\n    AreaCode: Optional[str] = None\n    City: Optional[str] = None\n    CityPopulation: Optional[str] = None\n    Province: Optional[str] = None\n    Error: Optional['Error'] = None\n\n    def __str__(self) -> str:\n        error = str(self.Error) if self.Error else 'None'\n        return (f\"GetPostalCodeInfoResponse: Latitude={self.Latitude}, Longitude={self.Longitude}, \"\n                f\"PostalCode={self.PostalCode}, TimeZone={self.TimeZone}, DST={self.DST}, \"\n                f\"AreaCode={self.AreaCode}, City={self.City}, CityPopulation={self.CityPopulation}, \"\n                f\"Province={self.Province}, Error={error}\")\n\n@dataclass\nclass GetGeoLocationByMunicipalityProvinceResponse:\n    Latitude: Optional[str] = None\n    Longitude: Optional[str] = None\n    PostalCode: Optional[str] = None\n    Error: Optional['Error'] = None\n\n    def __str__(self) -> str:\n        error = str(self.Error) if self.Error else 'None'\n        return (f\"GetGeoLocationByMunicipalityProvinceResponse: Latitude={self.Latitude}, \"\n                f\"Longitude={self.Longitude}, PostalCode={self.PostalCode}, Error={error}\")\n<\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-create-block-tab tab-panel\" role=\"tabpanel\" tabindex=\"0\">\n<p><strong>Address GeoCoder Canada NodeJS Code Snippet<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">import axios from 'axios';\nimport querystring from 'querystring';\nimport { GetGeoLocationResponse } from '.\/agca_response.js';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the live ServiceObjects Address Geocode CA (AGCA) API service.\n *\/\nconst LiveBaseUrl = 'https:\/\/sws.serviceobjects.com\/GCC\/api.svc\/json\/';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the backup ServiceObjects Address Geocode CA (AGCA) API service.\n *\/\nconst BackupBaseUrl = 'https:\/\/swsbackup.serviceobjects.com\/GCC\/api.svc\/json\/';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the trial ServiceObjects Address Geocode CA (AGCA) API service.\n *\/\nconst TrialBaseUrl = 'https:\/\/trial.serviceobjects.com\/GCC\/api.svc\/json\/';\n\n\/**\n * &lt;summary>\n * Checks if a response from the API is valid by verifying that it either has no Error object\n * or the Error.Number is not equal to '4'.\n * &lt;\/summary>\n * &lt;param name=\"response\" type=\"Object\">The API response object to validate.&lt;\/param>\n * &lt;returns type=\"boolean\">True if the response is valid, false otherwise.&lt;\/returns>\n *\/\nconst isValid = (response) => !response?.Error || response.Error.Number !== '4';\n\n\/**\n * &lt;summary>\n * Constructs a full URL for the GetGeoLocation API endpoint by combining the base URL\n * with query parameters derived from the input parameters.\n * &lt;\/summary>\n * &lt;param name=\"params\" type=\"Object\">An object containing all the input parameters.&lt;\/param>\n * &lt;param name=\"baseUrl\" type=\"string\">The base URL for the API service (live, backup, or trial).&lt;\/param>\n * &lt;returns type=\"string\">The constructed URL with query parameters.&lt;\/returns>\n *\/\nconst buildUrl = (params, baseUrl) =>\n    `${baseUrl}GetGeoLocation?${querystring.stringify(params)}`;\n\n\/**\n * &lt;summary>\n * Performs an HTTP GET request to the specified URL with a given timeout.\n * &lt;\/summary>\n * &lt;param name=\"url\" type=\"string\">The URL to send the GET request to.&lt;\/param>\n * &lt;param name=\"timeoutSeconds\" type=\"number\">The timeout duration in seconds for the request.&lt;\/param>\n * &lt;returns type=\"Promise&lt;GetGeoLocationResponse>\">A promise that resolves to a GetGeoLocationResponse object containing the API response data.&lt;\/returns>\n * &lt;exception cref=\"Error\">Thrown if the HTTP request fails, with a message detailing the error.&lt;\/exception>\n *\/\nconst httpGet = async (url, timeoutSeconds) => {\n    try {\n        const response = await axios.get(url, { timeout: timeoutSeconds * 1000 });\n        return new GetGeoLocationResponse(response.data);\n    } catch (error) {\n        throw new Error(`HTTP request failed: ${error.message}`);\n    }\n};\n\n\/**\n * &lt;summary>\n * Provides functionality to call the ServiceObjects Address Geocode CA (AGCA) API's GetGeoLocation endpoint,\n * retrieving geocoding information (e.g., latitude, longitude, postal code) for a given Canadian address with fallback to a backup endpoint for reliability in live mode.\n * &lt;\/summary>\n *\/\nconst GetGeoLocationClient = {\n    \/**\n     * &lt;summary>\n     * Asynchronously invokes the GetGeoLocation API endpoint, attempting the primary endpoint\n     * first and falling back to the backup if the response is invalid (Error.Number == '4') in live mode.\n     * &lt;\/summary>\n     * @param {string} Address - Address line of the address to geocode (e.g., \"123 Main Street\"). Required.\n     * @param {string} Municipality - The municipality of the address to geocode (e.g., \"Cayuga\"). Optional if postal code is provided.\n     * @param {string} Province - The province of the address to geocode (e.g., \"ON\"). Optional if postal code is provided.\n     * @param {string} PostalCode - The postal code of the address to geocode. Optional if municipality and province are provided.\n     * @param {string} LicenseKey - Your license key to use the service.\n     * @param {boolean} IsLive - Value to determine whether to use the live or trial servers.\n     * @param {number} TimeoutSeconds - Timeout, in seconds, for the call to the service.\n     * @returns {Promise&lt;GetGeoLocationResponse>} - A promise that resolves to a GetGeoLocationResponse object.\n     *\/\n    async invokeAsync(Address, Municipality, Province, PostalCode, LicenseKey, IsLive = true, TimeoutSeconds = 15) {\n        const params = {\n            Address,\n            Municipality,\n            Province,\n            PostalCode,\n            LicenseKey: LicenseKey\n        };\n\n        const url = buildUrl(params, IsLive ? LiveBaseUrl : TrialBaseUrl);\n        let response = await httpGet(url, TimeoutSeconds);\n\n        if (IsLive &amp;&amp; !isValid(response)) {\n            const fallbackUrl = buildUrl(params, BackupBaseUrl);\n            const fallbackResponse = await httpGet(fallbackUrl, TimeoutSeconds);\n            return fallbackResponse;\n        }\n        return response;\n    },\n\n    \/**\n     * &lt;summary>\n     * Synchronously invokes the GetGeoLocation API endpoint by wrapping the async call\n     * and awaiting its result immediately.\n     * &lt;\/summary>\n     * @param {string} Address - Address line of the address to geocode (e.g., \"123 Main Street\"). Required.\n     * @param {string} Municipality - The municipality of the address to geocode (e.g., \"Cayuga\"). Optional if postal code is provided.\n     * @param {string} Province - The province of the address to geocode (e.g., \"ON\"). Optional if postal code is provided.\n     * @param {string} PostalCode - The postal code of the address to geocode. Optional if municipality and province are provided.\n     * @param {string} LicenseKey - Your license key to use the service.\n     * @param {boolean} IsLive - Value to determine whether to use the live or trial servers.\n     * @param {number} TimeoutSeconds - Timeout, in seconds, for the call to the service.\n     * @returns {GetGeoLocationResponse} - A GetGeoLocationResponse object with geocoding details or an error.\n     *\/\n    invoke(Address, Municipality, Province, PostalCode, LicenseKey, IsLive = true, TimeoutSeconds = 15) {\n        return (async () => await this.invokeAsync(Address, Municipality, Province, PostalCode, LicenseKey, IsLive, TimeoutSeconds))();\n    }\n};\n\nexport { GetGeoLocationClient, GetGeoLocationResponse };\n\n\n\/**\n * Input parameters for the GetGeoLocation API call.\n *\/\nexport class GetGeoLocationInput {\n    constructor(data = {}) {\n        this.Address = data.Address;\n        this.Municipality = data.Municipality;\n        this.Province = data.Province;\n        this.PostalCode = data.PostalCode;\n        this.LicenseKey = data.LicenseKey;\n        this.IsLive = data.IsLive !== undefined ? data.IsLive : true;\n        this.TimeoutSeconds = data.TimeoutSeconds !== undefined ? data.TimeoutSeconds : 15;\n    }\n\n    toString() {\n        return `GetGeoLocationInput: Address = ${this.Address}, Municipality = ${this.Municipality}, Province = ${this.Province}, PostalCode = ${this.PostalCode}, LicenseKey = ${this.LicenseKey}, IsLive = ${this.IsLive}, TimeoutSeconds = ${this.TimeoutSeconds}`;\n    }\n}\n\n\/**\n * Input parameters for the GetPostalCodeInfo API call.\n *\/\nexport class GetPostalCodeInfoInput {\n    constructor(data = {}) {\n        this.PostalCode = data.PostalCode;\n        this.LicenseKey = data.LicenseKey;\n        this.IsLive = data.IsLive !== undefined ? data.IsLive : true;\n        this.TimeoutSeconds = data.TimeoutSeconds !== undefined ? data.TimeoutSeconds : 15;\n    }\n\n    toString() {\n        return `GetPostalCodeInfoInput: PostalCode = ${this.PostalCode}, LicenseKey = ${this.LicenseKey}, IsLive = ${this.IsLive}, TimeoutSeconds = ${this.TimeoutSeconds}`;\n    }\n}\n\n\/**\n * Input parameters for the GetGeoLocationByMunicipalityProvince API call.\n *\/\nexport class GetGeoLocationByMunicipalityProvinceInput {\n    constructor(data = {}) {\n        this.Municipality = data.Municipality;\n        this.Province = data.Province;\n        this.LicenseKey = data.LicenseKey;\n        this.IsLive = data.IsLive !== undefined ? data.IsLive : true;\n        this.TimeoutSeconds = data.TimeoutSeconds !== undefined ? data.TimeoutSeconds : 15;\n    }\n\n    toString() {\n        return `GetGeoLocationByMunicipalityProvinceInput: Municipality = ${this.Municipality}, Province = ${this.Province}, LicenseKey = ${this.LicenseKey}, IsLive = ${this.IsLive}, TimeoutSeconds = ${this.TimeoutSeconds}`;\n    }\n}\n\n\/**\n * Error object for API responses.\n *\/\nexport class Error {\n    constructor(data = {}) {\n        this.Desc = data.Desc;\n        this.Number = data.Number;\n        this.Location = data.Location;\n    }\n\n    toString() {\n        return `Error: Desc = ${this.Desc}, Number = ${this.Number}, Location = ${this.Location}`;\n    }\n}\n\n\/**\n * Response from GetGeoLocation API, containing the latitude, longitude, postal code, \n * and match code for the given Canadian address.\n *\/\nexport class GetGeoLocationResponse {\n    constructor(data = {}) {\n        this.Latitude = data.Latitude;\n        this.Longitude = data.Longitude;\n        this.PostalCode = data.PostalCode;\n        this.MatchCode = data.MatchCode;\n        this.Error = data.Error ? new Error(data.Error) : null;\n    }\n\n    toString() {\n        return `GetGeoLocationResponse: Latitude = ${this.Latitude}, Longitude = ${this.Longitude}, PostalCode = ${this.PostalCode}, MatchCode = ${this.MatchCode}, Error = ${this.Error ? this.Error.toString() : 'null'}`;\n    }\n}\n\n\/**\n * Response from GetPostalCodeInfo API, containing the latitude, longitude, postal code, \n * time zone, DST, area code, city, city population, province, and error for the given Canadian postal code.\n *\/\nexport class GetPostalCodeInfoResponse {\n    constructor(data = {}) {\n        this.Latitude = data.Latitude;\n        this.Longitude = data.Longitude;\n        this.PostalCode = data.PostalCode;\n        this.TimeZone = data.TimeZone;\n        this.DST = data.DST;\n        this.AreaCode = data.AreaCode;\n        this.City = data.City;\n        this.CityPopulation = data.CityPopulation;\n        this.Province = data.Province;\n        this.Error = data.Error ? new Error(data.Error) : null;\n    }\n\n    toString() {\n        return `GetPostalCodeInfoResponse: Latitude = ${this.Latitude}, Longitude = ${this.Longitude}, PostalCode = ${this.PostalCode}, TimeZone = ${this.TimeZone}, DST = ${this.DST}, AreaCode = ${this.AreaCode}, City = ${this.City}, CityPopulation = ${this.CityPopulation}, Province = ${this.Province}, Error = ${this.Error ? this.Error.toString() : 'null'}`;\n    }\n}\n\n\/**\n * Response from GetGeoLocationByMunicipalityProvince API, containing the latitude, longitude, \n * postal code, and error for the given Canadian municipality and province.\n *\/\nexport class GetGeoLocationByMunicipalityProvinceResponse {\n    constructor(data = {}) {\n        this.Latitude = data.Latitude;\n        this.Longitude = data.Longitude;\n        this.PostalCode = data.PostalCode;\n        this.Error = data.Error ? new Error(data.Error) : null;\n    }\n\n    toString() {\n        return `GetGeoLocationByMunicipalityProvinceResponse: Latitude = ${this.Latitude}, Longitude = ${this.Longitude}, PostalCode = ${this.PostalCode}, Error = ${this.Error ? this.Error.toString() : 'null'}`;\n    }\n}\n\nexport default GetGeoLocationResponse;<\/pre>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":2072,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-2107","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>AGCA - REST<\/title>\n<meta name=\"description\" content=\"C#PythonNodeJS Address GeoCoder Canada C# Rest Snippet \ufeffusing System.Web; namespace address_geocode_canada_dot_net.REST { \/\/\/ &lt;summary&gt; \/\/\/ Provides\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AGCA - REST\" \/>\n<meta property=\"og:description\" content=\"C#PythonNodeJS Address GeoCoder Canada C# Rest Snippet \ufeffusing System.Web; namespace address_geocode_canada_dot_net.REST { \/\/\/ &lt;summary&gt; \/\/\/ Provides\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/\" \/>\n<meta property=\"og:site_name\" content=\"Service Objects | Contact, Phone, Email Verification | Data Quality Services\" \/>\n<meta property=\"article:modified_time\" content=\"2025-09-27T19:37:26+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/\",\"url\":\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/\",\"name\":\"AGCA - REST\",\"isPartOf\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#website\"},\"datePublished\":\"2022-11-08T17:44:23+00:00\",\"dateModified\":\"2025-09-27T19:37:26+00:00\",\"description\":\"C#PythonNodeJS Address GeoCoder Canada C# Rest Snippet \ufeffusing System.Web; namespace address_geocode_canada_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides\",\"breadcrumb\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DOTS Address Geocode \u2013\u00a0Canada\u00a0\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"AGCA &#8211; Code Snippets and Sample Code\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"AGCA &#8211; REST\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#website\",\"url\":\"https:\/\/www.serviceobjects.com\/docs\/\",\"name\":\"Service Objects | Contact, Phone, Email Verification | Data Quality Services\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.serviceobjects.com\/docs\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#organization\",\"name\":\"Service Objects | Contact, Phone, Email Verification | Data Quality Services\",\"url\":\"https:\/\/www.serviceobjects.com\/docs\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.serviceobjects.com\/docs\/wp-content\/uploads\/2022\/08\/SO-logo-2560px-transparent.png\",\"contentUrl\":\"https:\/\/www.serviceobjects.com\/docs\/wp-content\/uploads\/2022\/08\/SO-logo-2560px-transparent.png\",\"width\":2560,\"height\":1440,\"caption\":\"Service Objects | Contact, Phone, Email Verification | Data Quality Services\"},\"image\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#\/schema\/logo\/image\/\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"AGCA - REST","description":"C#PythonNodeJS Address GeoCoder Canada C# Rest Snippet \ufeffusing System.Web; namespace address_geocode_canada_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/","og_locale":"en_US","og_type":"article","og_title":"AGCA - REST","og_description":"C#PythonNodeJS Address GeoCoder Canada C# Rest Snippet \ufeffusing System.Web; namespace address_geocode_canada_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides","og_url":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/","og_site_name":"Service Objects | Contact, Phone, Email Verification | Data Quality Services","article_modified_time":"2025-09-27T19:37:26+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/","url":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/","name":"AGCA - REST","isPartOf":{"@id":"https:\/\/www.serviceobjects.com\/docs\/#website"},"datePublished":"2022-11-08T17:44:23+00:00","dateModified":"2025-09-27T19:37:26+00:00","description":"C#PythonNodeJS Address GeoCoder Canada C# Rest Snippet \ufeffusing System.Web; namespace address_geocode_canada_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides","breadcrumb":{"@id":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/agca-rest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.serviceobjects.com\/docs\/"},{"@type":"ListItem","position":2,"name":"DOTS Address Geocode \u2013\u00a0Canada\u00a0","item":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/"},{"@type":"ListItem","position":3,"name":"AGCA &#8211; Code Snippets and Sample Code","item":"https:\/\/www.serviceobjects.com\/docs\/dots-address-geocode-canada\/agca-code-snippets-and-sample-code\/"},{"@type":"ListItem","position":4,"name":"AGCA &#8211; REST"}]},{"@type":"WebSite","@id":"https:\/\/www.serviceobjects.com\/docs\/#website","url":"https:\/\/www.serviceobjects.com\/docs\/","name":"Service Objects | Contact, Phone, Email Verification | Data Quality Services","description":"","publisher":{"@id":"https:\/\/www.serviceobjects.com\/docs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.serviceobjects.com\/docs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.serviceobjects.com\/docs\/#organization","name":"Service Objects | Contact, Phone, Email Verification | Data Quality Services","url":"https:\/\/www.serviceobjects.com\/docs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.serviceobjects.com\/docs\/#\/schema\/logo\/image\/","url":"https:\/\/www.serviceobjects.com\/docs\/wp-content\/uploads\/2022\/08\/SO-logo-2560px-transparent.png","contentUrl":"https:\/\/www.serviceobjects.com\/docs\/wp-content\/uploads\/2022\/08\/SO-logo-2560px-transparent.png","width":2560,"height":1440,"caption":"Service Objects | Contact, Phone, Email Verification | Data Quality Services"},"image":{"@id":"https:\/\/www.serviceobjects.com\/docs\/#\/schema\/logo\/image\/"}}]}},"_links":{"self":[{"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/2107","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/comments?post=2107"}],"version-history":[{"count":17,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/2107\/revisions"}],"predecessor-version":[{"id":12362,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/2107\/revisions\/12362"}],"up":[{"embeddable":true,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/2072"}],"wp:attachment":[{"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/media?parent=2107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}