normalize_phone_number
Turn any national or international phone number into E.164, so customer lookups match.
normalize_phone_number(phone: str, default_country: str = "US") -> str | NoneReturns the number in international E.164 format, or None when the input
cannot be parsed. Customers type numbers in many formats, so normalizing them
first makes lookups in your systems match. For national numbers, pass an ISO
country code as default_country. International input keeps its own country
code.
Parameters
| Name | Type | Description |
|---|---|---|
phone | str | The phone number as the customer or a system wrote it |
default_country | str | ISO country code used for national numbers, such as "GB" or "GR". Defaults to "US" |
Returns
str | None: the number in E.164 format, such as "+302101234567", or None when it can't be parsed.
Example
number = normalize_phone_number(context["args"]["phone"], "GR")
if number is None:
return {"success": False, "message": "Please check the phone number."}A parsed number is not proof that it is assigned, reachable or owned by the
customer. If the request fails, the helper raises requests.HTTPError: stop
rather than falling back to a lookup with the raw input, and never log the
customer's number.
Store the normalized number with upsert_customer so the same customer is always matched the same way.