From 49570ce376ffa7f183b15fd423f23bb5efea0895 Mon Sep 17 00:00:00 2001 From: Igor Fedoronchuk Date: Fri, 13 Mar 2026 21:05:23 +0100 Subject: [PATCH 1/2] Add orders_nanpa example --- examples/README.md | 1 + examples/orders_nanpa.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 examples/orders_nanpa.py diff --git a/examples/README.md b/examples/README.md index 08582e1..2ea82f7 100644 --- a/examples/README.md +++ b/examples/README.md @@ -33,6 +33,7 @@ DIDWW_API_KEY=your_api_key python examples/balance.py | [`did_groups.py`](did_groups.py) | Fetches DID groups with included SKUs and shows group details. | | [`trunks.py`](trunks.py) | Creates SIP and PSTN trunks, prints details, then deletes them. | | [`orders_sku.py`](orders_sku.py) | Creates a DID order with all item types: by SKU, by available DID, and by reservation. Fetches ordered DIDs. | +| [`orders_nanpa.py`](orders_nanpa.py) | Orders a DID number by NPA/NXX prefix. | | [`upload_file.py`](upload_file.py) | Reads a file, encrypts it, and uploads to `encrypted_files`. | | [`identity_address_proofs.py`](identity_address_proofs.py) | Creates identity and address, encrypts and uploads files, attaches proofs to both. | | [`voice_in_trunk_groups.py`](voice_in_trunk_groups.py) | Creates trunks and a trunk group, lists groups with includes, updates, and deletes (cascade). | diff --git a/examples/orders_nanpa.py b/examples/orders_nanpa.py new file mode 100644 index 0000000..cab8658 --- /dev/null +++ b/examples/orders_nanpa.py @@ -0,0 +1,39 @@ +from client_factory import create_client +from didww.resources.order import Order +from didww.resources.order_item.did_order_item import DidOrderItem +from didww.query_params import QueryParams + +client = create_client() + +# Step 1: find the NANPA prefix by NPA/NXX (e.g. 201-221) +params = QueryParams().filter("npanxx", "201221").page(1, 1) +nanpa_prefixes = client.nanpa_prefixes().list(params).data +if not nanpa_prefixes: + print("NANPA prefix 201-221 not found") + exit(1) + +nanpa_prefix = nanpa_prefixes[0] +print(f"NANPA prefix: {nanpa_prefix.id} NPA={nanpa_prefix.npa} NXX={nanpa_prefix.nxx}") + +# Step 2: find a DID group for this prefix and load its SKUs +dg_params = QueryParams().filter("nanpa_prefix.id", nanpa_prefix.id).include("stock_keeping_units").page(1, 1) +did_groups = client.did_groups().list(dg_params).data +if not did_groups or not did_groups[0].stock_keeping_units: + print("No DID group with SKUs found for this NANPA prefix") + exit(1) + +sku = did_groups[0].stock_keeping_units[0] +print(f"DID group: {did_groups[0].id} SKU: {sku.id} (monthly={sku.monthly_price})") + +# Step 3: create the order +item = DidOrderItem() +item.sku_id = sku.id +item.nanpa_prefix_id = nanpa_prefix.id +item.qty = 1 + +order = Order() +order.allow_back_ordering = True +order.items = [item] +created = client.orders().create(order).data + +print(f"Order {created.id} amount={created.amount} status={created.status.value} ref={created.reference}") From f5e54c96bd7b7f6e5680d072ef2d7fe5c4717874 Mon Sep 17 00:00:00 2001 From: Igor Fedoronchuk Date: Sun, 15 Mar 2026 10:20:08 +0100 Subject: [PATCH 2/2] Use keyword args for page() and fix double space in output --- examples/orders_nanpa.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/orders_nanpa.py b/examples/orders_nanpa.py index cab8658..2ef509e 100644 --- a/examples/orders_nanpa.py +++ b/examples/orders_nanpa.py @@ -6,7 +6,7 @@ client = create_client() # Step 1: find the NANPA prefix by NPA/NXX (e.g. 201-221) -params = QueryParams().filter("npanxx", "201221").page(1, 1) +params = QueryParams().filter("npanxx", "201221").page(number=1, size=1) nanpa_prefixes = client.nanpa_prefixes().list(params).data if not nanpa_prefixes: print("NANPA prefix 201-221 not found") @@ -16,14 +16,14 @@ print(f"NANPA prefix: {nanpa_prefix.id} NPA={nanpa_prefix.npa} NXX={nanpa_prefix.nxx}") # Step 2: find a DID group for this prefix and load its SKUs -dg_params = QueryParams().filter("nanpa_prefix.id", nanpa_prefix.id).include("stock_keeping_units").page(1, 1) +dg_params = QueryParams().filter("nanpa_prefix.id", nanpa_prefix.id).include("stock_keeping_units").page(number=1, size=1) did_groups = client.did_groups().list(dg_params).data if not did_groups or not did_groups[0].stock_keeping_units: print("No DID group with SKUs found for this NANPA prefix") exit(1) sku = did_groups[0].stock_keeping_units[0] -print(f"DID group: {did_groups[0].id} SKU: {sku.id} (monthly={sku.monthly_price})") +print(f"DID group: {did_groups[0].id} SKU: {sku.id} (monthly={sku.monthly_price})") # Step 3: create the order item = DidOrderItem()