How do I update an existing Inbound SIP Trunk's nu...
# ask-ai
h
How do I update an existing Inbound SIP Trunk's numbers with Python API?
t
Thanks for reaching out, Corey. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to update an existing Inbound SIP Trunk's numbers using the Python API, here’s a simple way to do it: 1. Initialize the LiveKit API Client: Start by creating an instance of the
LiveKitAPI
client with your LiveKit URL, API key, and API secret. 2. Prepare the Update Request: Use the
SIPInboundTrunkUpdate
class to set up the new list of numbers. The
ListUpdate
helper makes it easy to specify these numbers. 3. Call the Update Method: Then, call the
update_sip_inbound_trunk_fields
method from the
SipService
class, passing the trunk ID along with your update request. Here’s a quick example to guide you:
Copy code
from livekit import api
from livekit.protocol.models import ListUpdate
from livekit.protocol.sip import (
    SIPInboundTrunkUpdate,
)

async def update_inbound_trunk_numbers():
    # First, initialize the LiveKit API client
    lk_api = api.LiveKitAPI(
        url="your_livekit_url",
        api_key="your_api_key",
        api_secret="your_api_secret",
    )

    # Swap out "existing_trunk_id" with your actual Inbound Trunk ID
    trunk_id = "existing_trunk_id"
    
    # Define your new list of numbers
    new_numbers = ["+1234567890", "+2345678901"]

    # Create the update request with the new numbers
    update = SIPInboundTrunkUpdate(
        numbers=ListUpdate(set=new_numbers),
    )

    # Now, update the trunk
    updated_trunk = await lk_api.sip.update_sip_inbound_trunk_fields(trunk_id, numbers=new_numbers)

    print("Inbound Trunk updated:", updated_trunk)

# Just a heads up: make sure to run this inside an async context
# if __name__ == "__main__":
#     import asyncio
#     asyncio.run(update_inbound_trunk_numbers())
Don’t forget to replace placeholders like
your_livekit_url
,
your_api_key
,
your_api_secret
,
existing_trunk_id
, and the new numbers with your actual info. This will smoothly update your Inbound Trunk with the new numbers you want.
h
AttributeError: Assignment not allowed to message field "numbers" in protocol message object.
t
Hey there! The error you're seeing happens because the
numbers
field in the
SIPInboundTrunkUpdate
object is immutable. To update it, you’ll want to use the
ListUpdate
helper instead. Here’s a simple way to fix it:
Copy code
from livekit.protocol.models import ListUpdate
from livekit.protocol.sip import SIPInboundTrunkUpdate

# Create the update object with ListUpdate for numbers
update = SIPInboundTrunkUpdate(
    numbers=ListUpdate(set=["+1234567890", "+2345678901"]),
)

# Use the update object in your request
response = await lk_api.sip.update_sip_inbound_trunk_fields(
    trunk_id="existing_trunk_id",
    update=update
)

print("Inbound Trunk updated:", response)
Just make sure to use the
ListUpdate
constructor with the
set
parameter to replace your list of numbers. This little tweak fixes the immutability hiccup and lets your update go through smoothly. Hope this helps!
h
TypeError: SipService.update_sip_inbound_trunk_fields() got an unexpected keyword argument 'update'
t
Hey there! The error you're seeing happens because the
update_sip_inbound_trunk_fields
method doesn’t take an
update
keyword argument. Instead, you can just pass the fields you want to update directly as keyword arguments. Here's how you can do it:
Copy code
from livekit import api

# Initialize the LiveKit API client
lk_api = api.LiveKitAPI(
    url="your_livekit_url",
    api_key="your_api_key",
    api_secret="your_api_secret",
)

# Update specific fields of an inbound trunk
updated_trunk = await lk_api.sip.update_sip_inbound_trunk_fields(
    trunk_id="existing_trunk_id",
    numbers=["+1234567890", "+2345678901"],
    name="Updated Trunk Name",
    metadata="Updated metadata"
)

print("Inbound Trunk updated:", updated_trunk)
Just swap out the placeholders like
your_livekit_url
,
your_api_key
,
your_api_secret
, and
existing_trunk_id
with your real info. Then, pass the fields you want to update (like
numbers
,
name
, or
metadata
) directly to the method. Hope this helps! Sources: livekit-protocol/livekit/protocol/sip.py | SIP APIs | LiveKit Docs | SIP inbound trunk | LiveKit Docs
h
The same issue persists AttributeError: Assignment not allowed to message field "numbers" in protocol message object. Since 'update' is not a valid argument, how do I update numbers for an existing SIP Trunk?
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!