Skip to content

Commit ec252d5

Browse files
committed
examples: dids - display 2026-04-16 emergency fields and identity
1 parent bd53fb7 commit ec252d5

1 file changed

Lines changed: 69 additions & 0 deletions

File tree

examples/dids.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
DIDs: list DIDs and display 2026-04-16 emergency fields and identity.
3+
Updates DID routing/capacity by assigning trunk and capacity pool.
4+
5+
Usage: DIDWW_API_KEY=xxx python examples/dids.py
6+
"""
7+
from client_factory import create_client
8+
from didww.query_params import QueryParams
9+
from didww.resources.did import Did
10+
from didww.resources.voice_in_trunk import VoiceInTrunk
11+
12+
client = create_client()
13+
14+
# Get DIDs with 2026-04-16 emergency relationships included
15+
print("=== Finding last ordered DID ===")
16+
params = QueryParams().include("identity", "emergency_calling_service", "emergency_verification")
17+
dids = client.dids().list(params).data
18+
19+
if not dids:
20+
print("No DIDs found. Please order a DID first.")
21+
raise SystemExit(1)
22+
23+
did = dids[0]
24+
print(f"Selected DID: {did.id}")
25+
print(f" Number: {did.number}")
26+
print(f" Emergency enabled: {did.emergency_enabled}")
27+
if did.emergency_calling_service:
28+
print(f" Emergency Calling Service: {did.emergency_calling_service.id}")
29+
if did.emergency_verification:
30+
print(f" Emergency Verification: {did.emergency_verification.id}")
31+
if did.identity:
32+
print(f" Identity: {did.identity.id}")
33+
34+
# Get last SIP trunk
35+
print("\n=== Finding SIP trunk ===")
36+
trunks = client.voice_in_trunks().list(
37+
QueryParams().filter("configuration.type", "sip_configurations")
38+
).data
39+
40+
if not trunks:
41+
print("No SIP trunks found. Please create a SIP trunk first.")
42+
raise SystemExit(1)
43+
44+
trunk = trunks[0]
45+
print(f"Selected trunk: {trunk.name}")
46+
47+
# Assign trunk to DID
48+
print("\n=== Assigning trunk to DID ===")
49+
update = Did.build(did.id)
50+
update.voice_in_trunk = VoiceInTrunk.build(trunk.id)
51+
client.dids().update(update)
52+
print(f"Assigned trunk: {trunk.name}")
53+
54+
# Assign capacity pool
55+
print("\n=== Assigning capacity pool ===")
56+
capacity_pools = client.capacity_pools().list().data
57+
58+
if capacity_pools:
59+
pool = capacity_pools[0]
60+
update = Did.build(did.id)
61+
update.capacity_pool = pool
62+
update.capacity_limit = 5
63+
update.description = "Updated by Python example"
64+
client.dids().update(update)
65+
print(f"DID {did.id}")
66+
print(f" description: {update.description}")
67+
print(f" capacity_limit: {update.capacity_limit}")
68+
else:
69+
print("No capacity pools found")

0 commit comments

Comments
 (0)