如何使用twilio API创建新Trunk时更新origination_urls

时间:2018-06-15 21:58:19

标签: twilio-api

感谢本教程:https://www.twilio.com/docs/sip-trunking/api/trunks#action-create我可以在我的Twilio帐户上创建,读取,更新和删除中继。

要创建一个新的主干,我这样做:

curl -XPOST https://trunking.twilio.com/v1/Trunks \
  -d "FriendlyName=MyTrunk" \
  -u '{twilio account sid}:{twilio auth token}'

这是我在创建新主干时得到的响应:

    {
        "trunks": [
        {
            "sid": "TKfa1e5a85f63bfc475c2c753c0f289932",
            "account_sid": "ACxxx",
             ....
             ....
            "date_updated": "2015-09-02T23:23:11Z",
            "url": "https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932",
            "links": {
                "origination_urls": "https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/OriginationUrls",
                "credential_lists": "https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/CredentialLists",
                "ip_access_control_lists": "https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/IpAccessControlLists",
                 "phone_numbers": "https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/PhoneNumbers"
            }
        }],
        "meta": {
            "page": 0,
             "page_size": 50,
              ... more
        }
    }

我对此回复感兴趣的是:

    "links": {
                "origination_urls": "https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/OriginationUrls",

现在,如果我在该链接上执行get命令,如:

curl -G "https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/OriginationUrls" -u '{twilio account sid}:{twilio auth token}'

我回来了:

{
    "meta": 
    {
       "page": 0, 
       "page_size": 50, 
        "first_page_url":
        .... 
    }, 
    "origination_urls": []
}

现在我的目标是更新origination_urls 。所以使用我用来更新主干的相同方法我尝试过:

curl -XPOST https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/OriginationUrls \
  -d "origination_urls=sip:200@somedomain.com" \
  -u '{twilio account sid}:{twilio auth token}'

但那失败了。我也尝试过:

curl -XPOST https://trunking.twilio.com/v1/Trunks/TKfa1e5a85f63bfc475c2c753c0f289932/OriginationUrls \
  -d "origination_urls=['someUrl']" \
  -u '{twilio account sid}:{twilio auth token}'

那也失败了。 如何更新origination_urls?

1 个答案:

答案 0 :(得分:0)

我错过了在我的帖子请求中添加Priority,FriendlyName,SipUrl,Weight和Enabled。我终于通过这样做得到了它:

curl -XPOST "https://trunking.twilio.com/v1/Trunks/TKfae10...../OriginationUrls"   -d "Priority=10" -d "FriendlyName=Org1"  -d "Enabled=true" -d "SipUrl=sip:test@domain.com" -d "Weight=10" -u '{twilio account sid}:{twilio auth token}'