{"id":4614,"date":"2022-11-12T20:29:47","date_gmt":"2022-11-12T20:29:47","guid":{"rendered":"https:\/\/serviceobjects.wpaladdin.com\/?page_id=4614"},"modified":"2025-09-26T13:35:13","modified_gmt":"2025-09-26T20:35:13","slug":"ipav-rest","status":"publish","type":"page","link":"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/","title":{"rendered":"IPAV &#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>IP Address Validation C# Rest Code 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;\nusing System.Threading.Tasks;\n\nnamespace ip_address_validation_dot_net.REST\n{\n    \/\/\/ &lt;summary>\n    \/\/\/ Provides functionality to call the ServiceObjects IP Address Validation REST API's GetGeoLocationByIP_V4 endpoint,\n    \/\/\/ retrieving geographic location, proxy, host name, and US region information for a given IP address with fallback to a backup endpoint\n    \/\/\/ for reliability in live mode.\n    \/\/\/ &lt;\/summary>\n    public class GetGeoLocationByIPV4Client\n    {\n        private const string LiveBaseUrl = \"https:\/\/sws.serviceobjects.com\/GPP\/web.svc\/\";\n        private const string BackupBaseUrl = \"https:\/\/swsbackup.serviceobjects.com\/GPP\/web.svc\/\";\n        private const string TrialBaseUrl = \"https:\/\/trial.serviceobjects.com\/GPP\/web.svc\/\";\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Synchronously calls the GetGeoLocationByIP_V4 REST endpoint to retrieve geographic location 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 IP address and license key.&lt;\/param>\n        \/\/\/ &lt;returns>Deserialized &lt;see cref=\"IPAVResponse\"\/>.&lt;\/returns>\n        public static IPAVResponse Invoke(GetGeoLocationByIPV4Input input)\n        {\n            \/\/ Use query string parameters so missing\/optional fields don't break\n            \/\/ the URL as path parameters would.\n            string url = BuildUrl(input, input.IsLive ? LiveBaseUrl : TrialBaseUrl);\n            IPAVResponse response = Helper.HttpGet&lt;IPAVResponse>(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                IPAVResponse fallbackResponse = Helper.HttpGet&lt;IPAVResponse>(fallbackUrl, input.TimeoutSeconds);\n                return fallbackResponse;\n            }\n\n            return response;\n        }\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Asynchronously calls the GetGeoLocationByIP_V4 REST endpoint to retrieve geographic location 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 IP address and license key.&lt;\/param>\n        \/\/\/ &lt;returns>Deserialized &lt;see cref=\"IPAVResponse\"\/>.&lt;\/returns>\n        public static async Task&lt;IPAVResponse> InvokeAsync(GetGeoLocationByIPV4Input input)\n        {\n            \/\/ Use query string parameters so missing\/optional fields don't break\n            \/\/ the URL as path parameters would.\n            string url = BuildUrl(input, input.IsLive ? LiveBaseUrl : TrialBaseUrl);\n            IPAVResponse response = await Helper.HttpGetAsync&lt;IPAVResponse>(url, input.TimeoutSeconds).ConfigureAwait(false);\n            if (input.IsLive &amp;&amp; !IsValid(response))\n            {\n                string fallbackUrl = BuildUrl(input, BackupBaseUrl);\n                IPAVResponse fallbackResponse = await Helper.HttpGetAsync&lt;IPAVResponse>(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(GetGeoLocationByIPV4Input input, string baseUrl)\n        {\n            string qs = $\"JSON\/GetLocationByIP_V4?\" +\n                        $\"IPAddress={HttpUtility.UrlEncode(input.IPAddress)}\" +\n                        $\"&amp;LicenseKey={HttpUtility.UrlEncode(input.LicenseKey)}\";\n            return baseUrl + qs;\n        }\n\n        \/\/ Check if the response is valid (no error or error code is not 4)\n        private static bool IsValid(IPAVResponse response) =>\n            response?.Error == null || response.Error.Number != \"4\";\n\n        \/\/\/ &lt;summary>\n        \/\/\/ This is the basic operation for retrieving geographic location, proxy, host name, and US region information\n        \/\/\/ for a given IP address. It consults IP address validation databases to provide details such as city, region,\n        \/\/\/ country, latitude, longitude, proxy status, ISP, and more. The operation returns a single response per IP address.\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"IPAddress\">The IP address to look up, e.g., \"209.85.173.104\".&lt;\/param>\n        \/\/\/ &lt;param name=\"LicenseKey\">Your license key to use the service.&lt;\/param>\n        \/\/\/ &lt;param name=\"IsLive\">Option to use live service or trial service.&lt;\/param>\n        \/\/\/ &lt;param name=\"TimeoutSeconds\">Timeout, in seconds, for the call to the service.&lt;\/param>\n        public record GetGeoLocationByIPV4Input(\n            string IPAddress = \"\",\n            string LicenseKey = \"\",\n            bool IsLive = true,\n            int TimeoutSeconds = 15\n        );\n    }\n}\n\n\n\ufeffusing System;\nusing System.Collections.Generic;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing static System.Runtime.InteropServices.JavaScript.JSType;\n\nnamespace ip_address_validation_dot_net.REST\n{\n    public class IPAVResponse\n    {\n\n        public int Certainty { get; set; }\n        public string City { get; set; }\n        public string Region { get; set; }\n        public string Country { get; set; }\n        public string CountryISO3 { get; set; }\n        public string CountryISO2 { get; set; }\n        public string PostalCode { get; set; }\n        public string MetroCode { get; set; }\n        public string DMA { get; set; }\n        public string StateFIPS { get; set; }\n        public string CountyFIPS { get; set; }\n        public double Latitude { get; set; }\n        public double Longitude { get; set; }\n        public string IsProxy { get; set; }\n        public string ProxyType { get; set; }\n        public string PossibleMobileDevice { get; set; }\n        public string ISP { get; set; }\n        public string NetblockOwner { get; set; }\n        public string HostNames { get; set; }\n        public string IPNoteCodes { get; set; }\n        public string IPNotes { get; set; }\n        public string Debug { get; set; }\n        public Error Error { get; set; }\n\n        public override string ToString()\n        {\n            return $\"Certainty: {Certainty}\\n\" +\n                   $\"City: {City}\\n\" +\n                   $\"Region: {Region}\\n\" +\n                   $\"Country: {Country}\\n\" +\n                   $\"CountryISO3: {CountryISO3}\\n\" +\n                   $\"CountryISO2: {CountryISO2}\\n\" +\n                   $\"PostalCode: {PostalCode}\\n\" +\n                   $\"MetroCode: {MetroCode}\\n\" +\n                   $\"DMA: {DMA}\\n\" +\n                   $\"StateFIPS: {StateFIPS}\\n\" +\n                   $\"CountyFIPS: {CountyFIPS}\\n\" +\n                   $\"Latitude: {Latitude}\\n\" +\n                   $\"Longitude: {Longitude}\\n\" +\n                   $\"IsProxy: {IsProxy}\\n\" +\n                   $\"ProxyType: {ProxyType}\\n\" +\n                   $\"PossibleMobileDevice: {PossibleMobileDevice}\\n\" +\n                   $\"ISP: {ISP}\\n\" +\n                   $\"NetblockOwner: {NetblockOwner}\\n\" +\n                   $\"HostNames: {HostNames}\\n\" +\n                   $\"IPNoteCodes: {IPNoteCodes}\\n\" +\n                   $\"IPNotes: {IPNotes}\\n\" +\n                   $\"Debug: {Debug}\\n\" +\n                   $\"Error: {Error}\\n\";\n        }\n\n    }\n    public class CountryLocation\n    {\n        public string Country { get; set; }\n        public string Cntry { get; set; }\n        public string Ctry { get; set; }\n        public double Latitude { get; set; }\n        public double Longitude { get; set; }\n        public string IsPublicProxy { get; set; }\n        public Error Error { get; set; }\n        public override string ToString()\n        {\n            return $\"Country: {Country}{Environment.NewLine}\" +\n                   $\"Cntry: {Cntry}{Environment.NewLine}\" +\n                   $\"Ctry: {Ctry}{Environment.NewLine}\" +\n                   $\"Longitude: {Longitude}{Environment.NewLine}\" +\n                   $\"Latitude: {Latitude}{Environment.NewLine}\" +\n                   $\"IsPublicProxy: {IsPublicProxy}{Environment.NewLine}\" +\n                   $\"Error: {Error}\";\n        }\n    }\n    public class Error\n    {\n        public string Desc { get; set; }\n        public string Number { get; set; }\n        public string Location { get; set; }\n        public override string ToString()\n        {\n            return $\"Desc: {Desc} \" +\n                $\"Number: {Number} \" +\n                $\"Location: {Location}\";\n        }\n    }\n\n}\n\n\ufeffusing System.Text.Json;\nusing System.Web;\n\nnamespace ip_address_validation_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}<\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-create-block-tab tab-panel\" role=\"tabpanel\" tabindex=\"0\">\n<p><strong>IP Address Validation Python Rest Code Snippet<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">from dataclasses import dataclass\nfrom typing import Optional\nimport requests\nfrom ipav_response import IPAVResponse, Error\n\n# Endpoint URLs for IP Address Validation GetGeoLocationByIP_V4 REST API\nprimary_url = 'https:\/\/sws.serviceobjects.com\/GPP\/web.svc\/JSON\/GetLocationByIP_V4?'\nbackup_url = 'https:\/\/swsbackup.serviceobjects.com\/GPP\/web.svc\/JSON\/GetLocationByIP_V4?'\ntrial_url = 'https:\/\/trial.serviceobjects.com\/GPP\/web.svc\/JSON\/GetLocationByIP_V4?'\n\ndef get_geo_location_by_ipv4(\n    ip_address: str,\n    license_key: str,\n    is_live: bool = True,\n    timeout_seconds: int = 15\n) -> IPAVResponse:\n    \"\"\"\n    Call IP Address Validation GetGeoLocationByIP_V4 API to retrieve geographic location, proxy, host name, and US region information.\n\n    Parameters:\n        ip_address: The IP address to look up, e.g., \"209.85.173.104\".\n        license_key: Your license key to use the service.\n        is_live: Value to determine whether to use the live or trial servers (default: True).\n        timeout_seconds: Timeout, in seconds, for the call to the service (default: 15).\n\n    Returns:\n        IPAVResponse: Parsed JSON response with geolocation information or error details.\n    \"\"\"\n    params = {\n        'IPAddress': ip_address,\n        'LicenseKey': license_key\n    }\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=timeout_seconds)\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')\n        if not (error is None or error.get('Number') != \"4\"):\n          if is_live:\n            # Try backup URL\n            response = requests.get(backup_url, params=params, timeout=timeout_seconds)\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\"IPAV service error: {data['Error']}\")\n          else:\n              # Trial mode error is terminal\n              raise RuntimeError(f\"IPAV trial error: {data['Error']}\")\n\n        # Convert JSON response to IPAVResponse for structured access\n        error = Error(**data.get('Error', {})) if data.get('Error') else None\n        return IPAVResponse(\n            IPAddress=data.get('IPAddress'),\n            LicenseKey=data.get('LicenseKey'),\n            Certainty=data.get('Certainty'),\n            City=data.get('City'),\n            Region=data.get('Region'),\n            Country=data.get('Country'),\n            CountryISO3=data.get('CountryISO3'),\n            CountryISO2=data.get('CountryISO2'),\n            PostalCode=data.get('PostalCode'),\n            MetroCode=data.get('MetroCode'),\n            DMA=data.get('DMA'),\n            StateFIPS=data.get('StateFIPS'),\n            CountyFIPS=data.get('CountyFIPS'),\n            Latitude=data.get('Latitude'),\n            Longitude=data.get('Longitude'),\n            IsProxy=data.get('IsProxy'),\n            ProxyType=data.get('ProxyType'),\n            PossibleMobileDevice=data.get('PossibleMobileDevice'),\n            ISP=data.get('ISP'),\n            NetblockOwner=data.get('NetblockOwner'),\n            HostNames=data.get('HostNames'),\n            IPNoteCodes=data.get('IPNoteCodes'),\n            IPNotes=data.get('IPNotes'),\n            Debug=data.get('Debug'),\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 on network failure\n                response = requests.get(backup_url, params=params, timeout=timeout_seconds)\n                response.raise_for_status()\n                data = response.json()\n                if 'Error' in data:\n                    raise RuntimeError(f\"IPAV backup error: {data['Error']}\") from req_exc\n\n                # Convert JSON response to IPAVResponse for structured access\n                error = Error(**data.get('Error', {})) if data.get('Error') else None\n                return IPAVResponse(\n                    IPAddress=data.get('IPAddress'),\n                    LicenseKey=data.get('LicenseKey'),\n                    Certainty=data.get('Certainty'),\n                    City=data.get('City'),\n                    Region=data.get('Region'),\n                    Country=data.get('Country'),\n                    CountryISO3=data.get('CountryISO3'),\n                    CountryISO2=data.get('CountryISO2'),\n                    PostalCode=data.get('PostalCode'),\n                    MetroCode=data.get('MetroCode'),\n                    DMA=data.get('DMA'),\n                    StateFIPS=data.get('StateFIPS'),\n                    CountyFIPS=data.get('CountyFIPS'),\n                    Latitude=data.get('Latitude'),\n                    Longitude=data.get('Longitude'),\n                    IsProxy=data.get('IsProxy'),\n                    ProxyType=data.get('ProxyType'),\n                    PossibleMobileDevice=data.get('PossibleMobileDevice'),\n                    ISP=data.get('ISP'),\n                    NetblockOwner=data.get('NetblockOwner'),\n                    HostNames=data.get('HostNames'),\n                    IPNoteCodes=data.get('IPNoteCodes'),\n                    IPNotes=data.get('IPNotes'),\n                    Debug=data.get('Debug'),\n                    Error=error\n                )\n            except Exception as backup_exc:\n                raise RuntimeError(\"IPAV service unreachable on both endpoints\") from backup_exc\n        else:\n            raise RuntimeError(f\"IPAV trial error: {str(req_exc)}\") from req_exc\n\n\nfrom dataclasses import dataclass\nfrom typing import Optional\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 IPAVResponse:\n    IPAddress: Optional[str] = None\n    LicenseKey: Optional[str] = None\n    Certainty: Optional[int] = None\n    City: Optional[str] = None\n    Region: Optional[str] = None\n    Country: Optional[str] = None\n    CountryISO3: Optional[str] = None\n    CountryISO2: Optional[str] = None\n    PostalCode: Optional[str] = None\n    MetroCode: Optional[str] = None\n    DMA: Optional[str] = None\n    StateFIPS: Optional[str] = None\n    CountyFIPS: Optional[str] = None\n    Latitude: Optional[float] = None\n    Longitude: Optional[float] = None\n    IsProxy: Optional[str] = None\n    ProxyType: Optional[str] = None\n    PossibleMobileDevice: Optional[str] = None\n    ISP: Optional[str] = None\n    NetblockOwner: Optional[str] = None\n    HostNames: Optional[str] = None\n    IPNoteCodes: Optional[str] = None\n    IPNotes: Optional[str] = None\n    Debug: 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\"IPAVResponse: IPAddress={self.IPAddress}, LicenseKey={self.LicenseKey}, \"\n                f\"Certainty={self.Certainty}, City={self.City}, Region={self.Region}, \"\n                f\"Country={self.Country}, CountryISO3={self.CountryISO3}, CountryISO2={self.CountryISO2}, \"\n                f\"PostalCode={self.PostalCode}, MetroCode={self.MetroCode}, DMA={self.DMA}, \"\n                f\"StateFIPS={self.StateFIPS}, CountyFIPS={self.CountyFIPS}, Latitude={self.Latitude}, \"\n                f\"Longitude={self.Longitude}, IsProxy={self.IsProxy}, ProxyType={self.ProxyType}, \"\n                f\"PossibleMobileDevice={self.PossibleMobileDevice}, ISP={self.ISP}, \"\n                f\"NetblockOwner={self.NetblockOwner}, HostNames={self.HostNames}, \"\n                f\"IPNoteCodes={self.IPNoteCodes}, IPNotes={self.IPNotes}, Debug={self.Debug}, \"\n                f\"Error={error}\")<\/pre>\n<\/div>\n\n\n\n<div class=\"wp-block-create-block-tab tab-panel\" role=\"tabpanel\" tabindex=\"0\">\n<p><strong>IP Address Validation NodeJS Rest 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 { IPAVResponse } from '.\/ipav_response.js';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the live ServiceObjects IP Address Validation API service.\n *\/\nconst LiveBaseUrl = 'https:\/\/sws.serviceobjects.com\/GPP\/web.svc\/';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the backup ServiceObjects IP Address Validation API service.\n *\/\nconst BackupBaseUrl = 'https:\/\/swsbackup.serviceobjects.com\/GPP\/web.svc\/';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the trial ServiceObjects IP Address Validation API service.\n *\/\nconst TrialBaseUrl = 'https:\/\/trial.serviceobjects.com\/GPP\/web.svc\/';\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 GetGeoLocationByIP_V4 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}JSON\/GetLocationByIP_V4?${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;IPAVResponse>\">A promise that resolves to an IPAVResponse 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 IPAVResponse(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 IP Address Validation API's GetGeoLocationByIP_V4 endpoint,\n * retrieving geographic location, proxy, host name, and US region information with fallback to a backup endpoint for reliability in live mode.\n * &lt;\/summary>\n *\/\nconst GetGeoLocationByIPV4Client = {\n    \/**\n     * &lt;summary>\n     * Asynchronously invokes the GetGeoLocationByIP_V4 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} IPAddress - The IP address to look up, e.g., \"209.85.173.104\".\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;IPAVResponse>} - A promise that resolves to an IPAVResponse object.\n     *\/\n    async invokeAsync(IPAddress, LicenseKey, isLive = true, timeoutSeconds = 15) {\n        const params = {\n            IPAddress,\n            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 isValid(fallbackResponse) ? fallbackResponse : response;\n        }\n\n        return response;\n    },\n\n    \/**\n     * &lt;summary>\n     * Synchronously invokes the GetGeoLocationByIP_V4 API endpoint by wrapping the async call\n     * and awaiting its result immediately.\n     * &lt;\/summary>\n     * @returns {IPAVResponse} - An IPAVResponse object with geographic location details or an error.\n     *\/\n    invoke(IPAddress, LicenseKey, isLive = true, timeoutSeconds = 15) {\n        return (async () => await this.invokeAsync(\n            IPAddress, LicenseKey, isLive, timeoutSeconds\n        ))();\n    }\n};\n\nexport { GetGeoLocationByIPV4Client, IPAVResponse };\n\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\nexport class IPAVResponse {\n    constructor(data = {}) {\n        this.IPAddress = data.IPAddress;\n        this.LicenseKey = data.LicenseKey;\n        this.Certainty = data.Certainty || 0;\n        this.City = data.City;\n        this.Region = data.Region;\n        this.Country = data.Country;\n        this.CountryISO3 = data.CountryISO3;\n        this.CountryISO2 = data.CountryISO2;\n        this.PostalCode = data.PostalCode;\n        this.MetroCode = data.MetroCode;\n        this.DMA = data.DMA;\n        this.StateFIPS = data.StateFIPS;\n        this.CountyFIPS = data.CountyFIPS;\n        this.Latitude = data.Latitude;\n        this.Longitude = data.Longitude;\n        this.IsProxy = data.IsProxy;\n        this.ProxyType = data.ProxyType;\n        this.PossibleMobileDevice = data.PossibleMobileDevice;\n        this.ISP = data.ISP;\n        this.NetblockOwner = data.NetblockOwner;\n        this.HostNames = data.HostNames;\n        this.IPNoteCodes = data.IPNoteCodes;\n        this.IPNotes = data.IPNotes;\n        this.Debug = data.Debug;\n        this.Error = data.Error ? new Error(data.Error) : null;\n    }\n\n    toString() {\n        return `IPAVResponse: IPAddress = ${this.IPAddress ?? 'null'}, LicenseKey = ${this.LicenseKey ?? 'null'}, ` +\n               `Certainty = ${this.Certainty}, City = ${this.City ?? 'null'}, Region = ${this.Region ?? 'null'}, ` +\n               `Country = ${this.Country ?? 'null'}, CountryISO3 = ${this.CountryISO3 ?? 'null'}, ` +\n               `CountryISO2 = ${this.CountryISO2 ?? 'null'}, PostalCode = ${this.PostalCode ?? 'null'}, ` +\n               `MetroCode = ${this.MetroCode ?? 'null'}, DMA = ${this.DMA ?? 'null'}, ` +\n               `StateFIPS = ${this.StateFIPS ?? 'null'}, CountyFIPS = ${this.CountyFIPS ?? 'null'}, ` +\n               `Latitude = ${this.Latitude ?? 'null'}, Longitude = ${this.Longitude ?? 'null'}, ` +\n               `IsProxy = ${this.IsProxy ?? 'null'}, ProxyType = ${this.ProxyType ?? 'null'}, ` +\n               `PossibleMobileDevice = ${this.PossibleMobileDevice ?? 'null'}, ISP = ${this.ISP ?? 'null'}, ` +\n               `NetblockOwner = ${this.NetblockOwner ?? 'null'}, HostNames = ${this.HostNames ?? 'null'}, ` +\n               `IPNoteCodes = ${this.IPNoteCodes ?? 'null'}, IPNotes = ${this.IPNotes ?? 'null'}, ` +\n               `Debug = ${this.Debug ?? 'null'}, Error = ${this.Error ? this.Error.toString() : 'null'}`;\n    }\n}\n\nexport default IPAVResponse;<\/pre>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":4301,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-4614","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>IPAV - REST<\/title>\n<meta name=\"description\" content=\"C#PythonNodeJS IP Address Validation C# Rest Code Snippet \ufeffusing System.Web; using System.Threading.Tasks; namespace ip_address_validation_dot_net.REST {\" \/>\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-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"IPAV - REST\" \/>\n<meta property=\"og:description\" content=\"C#PythonNodeJS IP Address Validation C# Rest Code Snippet \ufeffusing System.Web; using System.Threading.Tasks; namespace ip_address_validation_dot_net.REST {\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-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-26T20:35:13+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-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/\",\"url\":\"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/\",\"name\":\"IPAV - REST\",\"isPartOf\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#website\"},\"datePublished\":\"2022-11-12T20:29:47+00:00\",\"dateModified\":\"2025-09-26T20:35:13+00:00\",\"description\":\"C#PythonNodeJS IP Address Validation C# Rest Code Snippet \ufeffusing System.Web; using System.Threading.Tasks; namespace ip_address_validation_dot_net.REST {\",\"breadcrumb\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DOTS IP Address Validation\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"IPAV &#8211; Code Snippets and Sample Code\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"IPAV &#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":"IPAV - REST","description":"C#PythonNodeJS IP Address Validation C# Rest Code Snippet \ufeffusing System.Web; using System.Threading.Tasks; namespace ip_address_validation_dot_net.REST {","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-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/","og_locale":"en_US","og_type":"article","og_title":"IPAV - REST","og_description":"C#PythonNodeJS IP Address Validation C# Rest Code Snippet \ufeffusing System.Web; using System.Threading.Tasks; namespace ip_address_validation_dot_net.REST {","og_url":"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/","og_site_name":"Service Objects | Contact, Phone, Email Verification | Data Quality Services","article_modified_time":"2025-09-26T20:35:13+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-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/","url":"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/","name":"IPAV - REST","isPartOf":{"@id":"https:\/\/www.serviceobjects.com\/docs\/#website"},"datePublished":"2022-11-12T20:29:47+00:00","dateModified":"2025-09-26T20:35:13+00:00","description":"C#PythonNodeJS IP Address Validation C# Rest Code Snippet \ufeffusing System.Web; using System.Threading.Tasks; namespace ip_address_validation_dot_net.REST {","breadcrumb":{"@id":"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/ipav-rest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.serviceobjects.com\/docs\/"},{"@type":"ListItem","position":2,"name":"DOTS IP Address Validation","item":"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/"},{"@type":"ListItem","position":3,"name":"IPAV &#8211; Code Snippets and Sample Code","item":"https:\/\/www.serviceobjects.com\/docs\/dots-ip-address-validation\/ipav-code-snippets-and-sample-code\/"},{"@type":"ListItem","position":4,"name":"IPAV &#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\/4614","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=4614"}],"version-history":[{"count":8,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/4614\/revisions"}],"predecessor-version":[{"id":12337,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/4614\/revisions\/12337"}],"up":[{"embeddable":true,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/4301"}],"wp:attachment":[{"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/media?parent=4614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}