python code to update sip trunk
# ask-ai
e
python code to update sip trunk
t
Thanks for reaching out, Shehryar. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you with the SIP trunk update! Could you please share a bit more about what you're trying to do? For instance, are you updating certain settings, adding new configurations, or working on something else? The more details you provide, the better I can assist you.
e
provide python example to update the sip inbound trunk
t
Hi there! I’m happy to share two Python examples to help you update a SIP inbound trunk in LiveKit. Let’s walk through them together: 1. Update specific fields of an existing trunk:
Copy code
import asyncio
from livekit import api

async def main():
    livekit_api = api.LiveKitAPI()

    # Update specific fields of the trunk
    trunk = await livekit_api.sip.update_inbound_trunk_fields(
        trunk_id="<sip-trunk-id>",
        allowed_numbers=["+13105550100", "+17145550100"],
        name="My updated trunk",
    )

    print(f"Successfully updated trunk {trunk}")
    await livekit_api.aclose()

asyncio.run(main())
2. Replace the entire trunk with a new configuration:
Copy code
import asyncio
from livekit import api
from livekit.protocol.sip import SIPInboundTrunkInfo

async def main():
    livekit_api = api.LiveKitAPI()

    # Create a new trunk configuration
    trunk = SIPInboundTrunkInfo(
        numbers=['+15105550100'],
        allowed_numbers=["+13105550100", "+17145550100"],
        name="My replaced inbound trunk",
    )

    # Replace the existing trunk
    updated_trunk = await livekit_api.sip.update_inbound_trunk(
        trunk_id="<sip-trunk-id>",
        trunk=trunk
    )

    print(f"Successfully replaced trunk {updated_trunk}")
    await livekit_api.aclose()

asyncio.run(main())
Just to clarify, the first method lets you update only certain fields like
name
,
numbers
, or
allowed_numbers
. The second method is great if you want to replace the entire trunk configuration with a new one. If you have any questions or need a hand with anything else, please don’t hesitate to reach out—I’m here to help! Sources: livekit-protocol/livekit/protocol/sip.pyi | SIP inbound trunk | LiveKit Docs