{"id":5114,"date":"2022-11-13T20:16:53","date_gmt":"2022-11-13T20:16:53","guid":{"rendered":"https:\/\/serviceobjects.wpaladdin.com\/?page_id=5114"},"modified":"2025-09-26T14:56:38","modified_gmt":"2025-09-26T21:56:38","slug":"pa2-rest","status":"publish","type":"page","link":"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/","title":{"rendered":"PA2 &#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>Phone Append 2 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;\n\nnamespace phone_append_2_dot_net.REST\n{\n    \/\/\/ &lt;summary>\n    \/\/\/ Provides functionality to call the ServiceObjects PhoneAppend (PA2) REST API's PhoneAppend endpoint,\n    \/\/\/ retrieving phone number information for a contact based on provided inputs with fallback to a backup endpoint for reliability in live mode.\n    \/\/\/ &lt;\/summary>\n    public static class PhoneAppendClient  \n    {\n        \/\/ Base URL constants: production, backup, and trial\n        private const string LiveBaseUrl = \"https:\/\/sws.serviceobjects.com\/pa2\/api.svc\/json\/\";\n        private const string BackupBaseUrl = \"https:\/\/swsbackup.serviceobjects.com\/pa2\/api.svc\/json\/\";\n        private const string TrialBaseUrl = \"https:\/\/trial.serviceobjects.com\/pa2\/api.svc\/json\/\";\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Synchronously calls the PhoneAppend REST endpoint to retrieve phone number information,\n        \/\/\/ attempting the primary endpoint first and falling back to the backup if the response is invalid\n        \/\/\/ (Error.TypeCode == \"3\") in live mode.\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"input\">The input parameters including full name, first name, last name, address, city, state, postal code, and license key.&lt;\/param>\n        \/\/\/ &lt;returns>Deserialized &lt;see cref=\"PA2Response\"\/> containing phone number data or an error.&lt;\/returns>\n        public static PA2Response Invoke(PhoneAppendInput 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            PA2Response response = Helper.HttpGet&lt;PA2Response>(url, input.TimeoutSeconds);\n\n            \/\/ Fallback on error in live mode\n            if (input.IsLive &amp;&amp; !ValidResponse(response))\n            {\n                string fallbackUrl = BuildUrl(input, BackupBaseUrl);\n                PA2Response fallbackResponse = Helper.HttpGet&lt;PA2Response>(fallbackUrl, input.TimeoutSeconds);\n                return fallbackResponse;\n            }\n\n            return response;\n        }\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Asynchronously calls the PhoneAppend REST endpoint to retrieve phone number information,\n        \/\/\/ attempting the primary endpoint first and falling back to the backup if the response is invalid\n        \/\/\/ (Error.TypeCode == \"3\") in live mode.\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"input\">The input parameters including full name, first name, last name, address, city, state, postal code, and license key.&lt;\/param>\n        \/\/\/ &lt;returns>Deserialized &lt;see cref=\"PA2Response\"\/> containing phone number data or an error.&lt;\/returns>\n        public static async Task&lt;PA2Response> InvokeAsync(PhoneAppendInput 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            PA2Response response = await Helper.HttpGetAsync&lt;PA2Response>(url, input.TimeoutSeconds).ConfigureAwait(false);\n\n            \/\/ Fallback on error in live mode\n            if (input.IsLive &amp;&amp; !ValidResponse(response))\n            {\n                string fallbackUrl = BuildUrl(input, BackupBaseUrl);\n                PA2Response fallbackResponse = await Helper.HttpGetAsync&lt;PA2Response>(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        private static string BuildUrl(PhoneAppendInput input, string baseUrl)\n        {\n            \/\/ Construct query string with URL-encoded parameters\n            string qs = $\"PhoneAppendJson?\" +\n                        $\"FullName={Helper.UrlEncode(input.FullName)}\" +\n                        $\"&amp;FirstName={Helper.UrlEncode(input.FirstName)}\" +\n                        $\"&amp;LastName={Helper.UrlEncode(input.LastName)}\" +\n                        $\"&amp;Address={Helper.UrlEncode(input.Address)}\" +\n                        $\"&amp;City={Helper.UrlEncode(input.City)}\" +\n                        $\"&amp;State={Helper.UrlEncode(input.State)}\" +\n                        $\"&amp;PostalCode={Helper.UrlEncode(input.PostalCode)}\" +\n                        $\"&amp;LicenseKey={Helper.UrlEncode(input.LicenseKey)}\";\n            return baseUrl + qs;\n        }\n\n        private static bool ValidResponse(PA2Response response)\n        {\n            return (response?.Error == null || response.Error.TypeCode != \"3\");\n        }\n\n        \/\/\/ &lt;summary>\n        \/\/\/ Input parameters for the PhoneAppend API call. Represents a contact to retrieve phone number information.\n        \/\/\/ &lt;\/summary>\n        \/\/\/ &lt;param name=\"FullName\">The full name of the contact. Optional if FirstName and LastName are provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"FirstName\">The first name of the contact. Optional if FullName is provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"LastName\">The last name of the contact. Optional if FullName is provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"Address\">Address line of the contact. Optional.&lt;\/param>\n        \/\/\/ &lt;param name=\"City\">The city of the contact. Optional if postal code is provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"State\">The state of the contact. Optional if postal code is provided.&lt;\/param>\n        \/\/\/ &lt;param name=\"PostalCode\">The postal code of the contact. Optional if city and state 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 PhoneAppendInput(\n            string FullName = \"\",\n            string FirstName = \"\",\n            string LastName = \"\",\n            string Address = \"\",\n            string City = \"\",\n            string State = \"\",\n            string PostalCode = \"\",\n            string LicenseKey = \"\",\n            bool IsLive = true,\n            int TimeoutSeconds = 15\n        );\n    }\n}\n\n\n\ufeffusing System.Runtime.Serialization;\n\n[DataContract]\npublic class PA2Response\n{\n    public PhoneInfo PhoneInfo { get; set; }\n    public Error Error { get; set; }\n\n    public override string ToString()\n    {\n        return $\"PA2 PhoneInfo: {PhoneInfo} \\nError: {Error}\\n\";\n    }\n\n}\npublic class PhoneInfo\n{\n    public string Phone { get; set; }\n    public string Name { get; set; }\n    public string Address { get; set; }\n    public string City { get; set; }\n    public string State { get; set; }\n    public string PostalCode { get; set; }\n    public string IsResidential { get; set; }\n    public string Certainty { get; set; }\n    public string LineType { get; set; }\n    public override string ToString()\n    {\n        return $\"Phone: {Phone}\\n\" +\n               $\"Name: {Name}\\n\" +\n               $\"Address: {Address}\\n\" +\n               $\"City: {City}\\n\" +\n               $\"State: {State}\\n\" +\n               $\"Postal Code: {PostalCode}\\n\" +\n               $\"Is Residential: {IsResidential}\\n\" +\n               $\"Certainty: {Certainty}\\n\" +\n               $\"Line Type: {LineType}\\n\";\n    }\n}\npublic class Error\n{\n    public string Type { get; set; }\n    public string TypeCode { get; set; }\n    public string Desc { get; set; }\n    public string DescCode { get; set; }\n    public override string ToString()\n    {\n        return $\"Type: {Type} \" +\n            $\"TypeCode: {TypeCode} \" +\n            $\"Desc: {Desc} \" +\n            $\"DescCode: {DescCode} \";\n    }\n}\n\n\n\ufeffusing System.Text.Json;\nusing System.Web;\n\nnamespace phone_append_2_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>Phone Append 2 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=\"\">from pa2_response import PA2Response, PhoneInfo, Error\nimport requests\nfrom typing import Optional\n\n# Endpoint URLs for ServiceObjects PhoneAppend API\nprimary_url = \"https:\/\/sws.serviceobjects.com\/pa2\/api.svc\/json\/PhoneAppendJson?\"\nbackup_url = \"https:\/\/swsbackup.serviceobjects.com\/pa2\/api.svc\/json\/PhoneAppendJson?\"\ntrial_url = \"https:\/\/trial.serviceobjects.com\/pa2\/api.svc\/json\/PhoneAppendJson?\"\n\ndef get_phone_append(\n    full_name: Optional[str] = None,\n    first_name: Optional[str] = None,\n    last_name: Optional[str] = None,\n    address: Optional[str] = None,\n    city: Optional[str] = None,\n    state: Optional[str] = None,\n    postal_code: Optional[str] = None,\n    license_key: Optional[str] = None,\n    is_live: bool = True\n) -> PA2Response:\n    \"\"\"\n    Call ServiceObjects PhoneAppend API to retrieve a phone number for a given residential contact.\n\n    Parameters:\n        full_name: The full name of the contact. Optional if first_name and last_name are provided.\n        first_name: The first name of the contact. Optional if full_name is provided.\n        last_name: The last name of the contact. Optional if full_name is provided.\n        address: Address line of the contact. Optional.\n        city: The city of the contact. Optional.\n        state: The state of the contact. Optional.\n        postal_code: The postal code of the contact. Optional.\n        license_key: Your ServiceObjects license key.\n        is_live: Use live or trial servers.\n\n    Returns:\n        PA2Response: Parsed JSON response with phone information 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        \"FullName\": full_name,\n        \"FirstName\": first_name,\n        \"LastName\": last_name,\n        \"Address\": address,\n        \"City\": city,\n        \"State\": state,\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')\n        if not (error is None or error.get('TypeCode') != \"3\"):\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\"PhoneAppend service error: {data['Error']}\")\n            else:\n                # Trial mode error is terminal\n                raise RuntimeError(f\"PhoneAppend trial error: {data['Error']}\")\n\n        # Convert JSON response to PA2Response for structured access\n        error = Error(**data.get(\"Error\", {})) if data.get(\"Error\") else None\n\n        return PA2Response(\n            PhoneInfo=PhoneInfo(\n                Phone=data.get(\"PhoneInfo\", {}).get(\"Phone\"),\n                Name=data.get(\"PhoneInfo\", {}).get(\"Name\"),\n                Address=data.get(\"PhoneInfo\", {}).get(\"Address\"),\n                City=data.get(\"PhoneInfo\", {}).get(\"City\"),\n                State=data.get(\"PhoneInfo\", {}).get(\"State\"),\n                PostalCode=data.get(\"PhoneInfo\", {}).get(\"PostalCode\"),\n                IsResidential=data.get(\"PhoneInfo\", {}).get(\"IsResidential\"),\n                Certainty=data.get(\"PhoneInfo\", {}).get(\"Certainty\"),\n                LineType=data.get(\"PhoneInfo\", {}).get(\"LineType\"),\n                Debug=data.get(\"PhoneInfo\", {}).get(\"Debug\")\n            ) if data.get(\"PhoneInfo\") else None,\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\"PhoneAppend backup error: {data['Error']}\") from req_exc\n\n                error = Error(**data.get(\"Error\", {})) if data.get(\"Error\") else None\n\n                return PA2Response(\n                    PhoneInfo=PhoneInfo(\n                        Phone=data.get(\"PhoneInfo\", {}).get(\"Phone\"),\n                        Name=data.get(\"PhoneInfo\", {}).get(\"Name\"),\n                        Address=data.get(\"PhoneInfo\", {}).get(\"Address\"),\n                        City=data.get(\"PhoneInfo\", {}).get(\"City\"),\n                        State=data.get(\"PhoneInfo\", {}).get(\"State\"),\n                        PostalCode=data.get(\"PhoneInfo\", {}).get(\"PostalCode\"),\n                        IsResidential=data.get(\"PhoneInfo\", {}).get(\"IsResidential\"),\n                        Certainty=data.get(\"PhoneInfo\", {}).get(\"Certainty\"),\n                        LineType=data.get(\"PhoneInfo\", {}).get(\"LineType\"),\n                        Debug=data.get(\"PhoneInfo\", {}).get(\"Debug\")\n                    ) if data.get(\"PhoneInfo\") else None,\n                    Error=error\n                )\n            except Exception as backup_exc:\n                raise RuntimeError(\"PhoneAppend service unreachable on both endpoints\") from backup_exc\n        else:\n            raise RuntimeError(f\"PhoneAppend trial error: {str(req_exc)}\") from req_exc\n\n\nfrom dataclasses import dataclass\nfrom typing import Optional, List\n\n# Input parameters for the PhoneAppend API call.\n@dataclass\nclass PhoneAppendInput:\n    FullName: Optional[str] = None\n    FirstName: Optional[str] = None\n    LastName: Optional[str] = None\n    Address: Optional[str] = None\n    City: Optional[str] = None\n    State: Optional[str] = None\n    PostalCode: Optional[str] = None\n    IsBusiness: Optional[str] = None\n    LicenseKey: Optional[str] = None\n\n    def __str__(self) -> str:\n        return (f\"PhoneAppendInput: FullName={self.FullName}, FirstName={self.FirstName}, \"\n                f\"LastName={self.LastName}, Address={self.Address}, City={self.City}, \"\n                f\"State={self.State}, PostalCode={self.PostalCode}, \"\n                f\"IsBusiness={self.IsBusiness}, LicenseKey={self.LicenseKey}\")\n\n# Error object for API responses.\n@dataclass\nclass Error:\n    Type: Optional[str] = None\n    TypeCode: Optional[str] = None\n    Desc: Optional[str] = None\n    DescCode: Optional[str] = None\n\n    def __str__(self) -> str:\n        return (f\"Error: Type={self.Type}, TypeCode={self.TypeCode}, \"\n                f\"Desc={self.Desc}, DescCode={self.DescCode}\")\n\n# Phone information for API responses.\n@dataclass\nclass PhoneInfo:\n    Phone: Optional[str] = None\n    Name: Optional[str] = None\n    Address: Optional[str] = None\n    City: Optional[str] = None\n    State: Optional[str] = None\n    PostalCode: Optional[str] = None\n    IsResidential: Optional[str] = None\n    Certainty: Optional[str] = None\n    LineType: Optional[str] = None\n    Debug: Optional[str] = None\n\n    def __str__(self) -> str:\n        return (f\"PhoneInfo: Phone={self.Phone}, Name={self.Name}, \"\n                f\"Address={self.Address}, City={self.City}, State={self.State}, \"\n                f\"PostalCode={self.PostalCode}, IsResidential={self.IsResidential}, \"\n                f\"Certainty={self.Certainty}, LineType={self.LineType}, Debug={self.Debug}\")\n\n# Response from PhoneAppend API, containing phone information and potential error.\n@dataclass\nclass PA2Response:\n    PhoneInfo: Optional['PhoneInfo'] = None\n    Error: Optional['Error'] = None\n\n    def __str__(self) -> str:\n        phone_info = str(self.PhoneInfo) if self.PhoneInfo else 'None'\n        error = str(self.Error) if self.Error else 'None'\n        return f\"PA2Response: PhoneInfo={phone_info}, 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>Phone Append 2 NodeJS<\/strong> <strong>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 { PA2Response } from '.\/pa2_response.js';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the live ServiceObjects PhoneAppend2 (PA2) API service.\n *\/\nconst LiveBaseUrl = 'https:\/\/sws.serviceobjects.com\/pa2\/api.svc\/json\/';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the backup ServiceObjects PhoneAppend2 (PA2) API service.\n *\/\nconst BackupBaseUrl = 'https:\/\/swsbackup.serviceobjects.com\/pa2\/api.svc\/json\/';\n\n\/**\n * @constant\n * @type {string}\n * @description The base URL for the trial ServiceObjects PhoneAppend2 (PA2) API service.\n *\/\nconst TrialBaseUrl = 'https:\/\/trial.serviceobjects.com\/pa2\/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.TypeCode is not equal to '3'.\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.TypeCode !== '3';\n\n\/**\n * &lt;summary>\n * Constructs a full URL for the PhoneAppendJson 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}PhoneAppendJson?${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;PA2Response>\">A promise that resolves to a PA2Response 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 PA2Response(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 PhoneAppend2 (PA2) API's PhoneAppendJson endpoint,\n * retrieving phone number information for a contact based on provided inputs with fallback to a backup endpoint for reliability in live mode.\n * &lt;\/summary>\n *\/\nconst PhoneAppendClient = {\n    \/**\n     * &lt;summary>\n     * Asynchronously invokes the PhoneAppendJson API endpoint, attempting the primary endpoint\n     * first and falling back to the backup if the response is invalid (Error.TypeCode == '3') in live mode.\n     * &lt;\/summary>\n     * @param {string} FullName - The full name of the contact. Optional if FirstName and LastName are provided.\n     * @param {string} FirstName - The first name of the contact. Optional if FullName is provided.\n     * @param {string} LastName - The last name of the contact. Optional if FullName is provided.\n     * @param {string} Address - Address line of the contact. Optional.\n     * @param {string} City - The city of the contact. Optional if postal code is provided.\n     * @param {string} State - The state of the contact. Optional if postal code is provided.\n     * @param {string} PostalCode - The postal code of the contact. Optional if city and state 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;PA2Response>} - A promise that resolves to a PA2Response object.\n     *\/\n    async invokeAsync(FullName, FirstName, LastName, Address, City, State, PostalCode, LicenseKey, isLive = true, timeoutSeconds = 15) {\n        const params = {\n            FullName,\n            FirstName,\n            LastName,\n            Address,\n            City,\n            State,\n            PostalCode,\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 fallbackResponse;\n        }\n        return response;\n    },\n\n    \/**\n     * &lt;summary>\n     * Synchronously invokes the PhoneAppendJson API endpoint by wrapping the async call\n     * and awaiting its result immediately.\n     * &lt;\/summary>\n     * @param {string} FullName - The full name of the contact. Optional if FirstName and LastName are provided.\n     * @param {string} FirstName - The first name of the contact. Optional if FullName is provided.\n     * @param {string} LastName - The last name of the contact. Optional if FullName is provided.\n     * @param {string} Address - Address line of the contact. Optional.\n     * @param {string} City - The city of the contact. Optional if postal code is provided.\n     * @param {string} State - The state of the contact. Optional if postal code is provided.\n     * @param {string} PostalCode - The postal code of the contact. Optional if city and state 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 {PA2Response} - A PA2Response object with phone number details or an error.\n     *\/\n    invoke(FullName, FirstName, LastName, Address, City, State, PostalCode, LicenseKey, isLive = true, timeoutSeconds = 15) {\n        return (async () => await this.invokeAsync(\n            FullName, FirstName, LastName, Address, City, State, PostalCode, LicenseKey, isLive, timeoutSeconds\n        ))();\n    }\n};\n\nexport { PhoneAppendClient, PA2Response };\n\n\n\/**\n * Response from PhoneAppend API, containing phone information and potential error.\n *\/\nexport class PA2Response {\n    constructor(data = {}) {\n        this.PhoneInfo = data.PhoneInfo ? new PhoneInfo(data.PhoneInfo) : null;\n        this.Error = data.Error ? new Error(data.Error) : null;\n    }\n\n    toString() {\n        return `PA2Response: PhoneInfo = ${this.PhoneInfo ? this.PhoneInfo.toString() : 'null'}, Error = ${this.Error ? this.Error.toString() : 'null'}`;\n    }\n}\n\n\/**\n * Phone information for API responses.\n *\/\nexport class PhoneInfo {\n    constructor(data = {}) {\n        this.Phone = data.Phone;\n        this.Name = data.Name;\n        this.Address = data.Address;\n        this.City = data.City;\n        this.State = data.State;\n        this.PostalCode = data.PostalCode;\n        this.IsResidential = data.IsResidential;\n        this.Certainty = data.Certainty;\n        this.LineType = data.LineType;\n    }\n\n    toString() {\n        return `PhoneInfo: Phone = ${this.Phone}, Name = ${this.Name}, Address = ${this.Address}, City = ${this.City}, State = ${this.State}, PostalCode = ${this.PostalCode}, IsResidential = ${this.IsResidential}, Certainty = ${this.Certainty}, LineType = ${this.LineType}`;\n    }\n}\n\n\/**\n * Error object for API responses.\n *\/\nexport class Error {\n    constructor(data = {}) {\n        this.Type = data.Type;\n        this.TypeCode = data.TypeCode;\n        this.Desc = data.Desc;\n        this.DescCode = data.DescCode;\n    }\n\n    toString() {\n        return `Error: Type = ${this.Type}, TypeCode = ${this.TypeCode}, Desc = ${this.Desc}, DescCode = ${this.DescCode}`;\n    }\n}\n\nexport default PA2Response;<\/pre>\n<\/div>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"parent":5100,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5114","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>PA2 - REST<\/title>\n<meta name=\"description\" content=\"C#PythonNodeJS Phone Append 2 C# Rest Code Snippet \ufeffusing System.Web; namespace phone_append_2_dot_net.REST { \/\/\/ &lt;summary&gt; \/\/\/ Provides functionality\" \/>\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-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PA2 - REST\" \/>\n<meta property=\"og:description\" content=\"C#PythonNodeJS Phone Append 2 C# Rest Code Snippet \ufeffusing System.Web; namespace phone_append_2_dot_net.REST { \/\/\/ &lt;summary&gt; \/\/\/ Provides functionality\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-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-26T21:56:38+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-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/\",\"url\":\"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/\",\"name\":\"PA2 - REST\",\"isPartOf\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/#website\"},\"datePublished\":\"2022-11-13T20:16:53+00:00\",\"dateModified\":\"2025-09-26T21:56:38+00:00\",\"description\":\"C#PythonNodeJS Phone Append 2 C# Rest Code Snippet \ufeffusing System.Web; namespace phone_append_2_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides functionality\",\"breadcrumb\":{\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"DOTS Phone Append 2\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PA2 &#8211; Code Snippets and Sample Code\",\"item\":\"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"PA2 &#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":"PA2 - REST","description":"C#PythonNodeJS Phone Append 2 C# Rest Code Snippet \ufeffusing System.Web; namespace phone_append_2_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides functionality","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-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/","og_locale":"en_US","og_type":"article","og_title":"PA2 - REST","og_description":"C#PythonNodeJS Phone Append 2 C# Rest Code Snippet \ufeffusing System.Web; namespace phone_append_2_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides functionality","og_url":"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/","og_site_name":"Service Objects | Contact, Phone, Email Verification | Data Quality Services","article_modified_time":"2025-09-26T21:56:38+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-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/","url":"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/","name":"PA2 - REST","isPartOf":{"@id":"https:\/\/www.serviceobjects.com\/docs\/#website"},"datePublished":"2022-11-13T20:16:53+00:00","dateModified":"2025-09-26T21:56:38+00:00","description":"C#PythonNodeJS Phone Append 2 C# Rest Code Snippet \ufeffusing System.Web; namespace phone_append_2_dot_net.REST { \/\/\/ &lt;summary> \/\/\/ Provides functionality","breadcrumb":{"@id":"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/pa2-rest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.serviceobjects.com\/docs\/"},{"@type":"ListItem","position":2,"name":"DOTS Phone Append 2","item":"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/"},{"@type":"ListItem","position":3,"name":"PA2 &#8211; Code Snippets and Sample Code","item":"https:\/\/www.serviceobjects.com\/docs\/dots-phone-append-2\/pa2-code-snippets-and-sample-code\/"},{"@type":"ListItem","position":4,"name":"PA2 &#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\/5114","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=5114"}],"version-history":[{"count":9,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/5114\/revisions"}],"predecessor-version":[{"id":12340,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/5114\/revisions\/12340"}],"up":[{"embeddable":true,"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/pages\/5100"}],"wp:attachment":[{"href":"https:\/\/www.serviceobjects.com\/docs\/wp-json\/wp\/v2\/media?parent=5114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}