Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
Expand Down
39 changes: 39 additions & 0 deletions examples/orders_nanpa.py
Original file line number Diff line number Diff line change
@@ -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(number=1, size=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(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})")

# 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}")
Loading