Free Mason
Free Mason

Reputation: 107

Twilio REST API HTTP 400 error: "SendDigits must be less than 32 characters long"

One of my apps has been making Twilio REST API calls for more than a year without problems. For the last week, I consistently get this error now:

HTTP 400 error: {"message": "SendDigits must be less than 32 characters long", "status": 400}

My request looks like this (some information redacted): (method='POST', uri='https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxxxxx/Calls.json', **kwargs={'auth': ('xxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxx'), 'data': {'From': '+1415DDDDDDD', 'SendDigits': 'ww0w1234w16w6w415DDDDDDD#w415DDDDDDD#', 'To': '+1415DDDDDDD', 'Url': 'http://twimlets.com/holdmusic?Bucket=com.twilio.music.ambient'}, 'headers': {'Accept': 'application/json', 'Accept-Charset': 'utf-8', 'Content-Type': 'application/x-www-form-urlencoded', 'User-Agent': 'twilio-python/3.6.13 (Python 2.7.6)'}})

It's as if the maximum length of SendDigits was recently changed, although I can't find documentation of this anywhere.

How can I get around this? Changing the value of the SendDigits isn't really an option for me.

Upvotes: 0

Views: 628

Answers (2)

Megan Speir
Megan Speir

Reputation: 3811

Megan from Twilio here.

Thank you for your feedback, I'm sorry for the trouble you are experiencing.

There is a workaround, to use <Play digits=""> in TwiML instead of passing it as a POST param, this should also be able to reach an equivalent result. For examples using <Play>, check out:

https://www.twilio.com/docs/api/twiml/play#attributes-digits

And an example in Python (using your string from above) would look something like:

def play_digits():
    r = twiml.Response()
    r.play(digits="ww0w1234w16w6w415DDDDDDD#w415DDDDDDD#")

    return str(r)

Please let me know if you find this to be useful.

Upvotes: 2

Free Mason
Free Mason

Reputation: 107

From Twilio's support staff:

"We rolled out a change a few days ago that restricted the max length of SendDigits to 32 characters. For a number of reasons we had to implement this limit."

Update: Solved. Here is my Python code:

call=client.calls.create(to=dial_number,from_="+14159999999",url="http://twimlets.com/echo?Twiml=%3CResponse%3E%0A%20%20%20%20%3CPlay%20digits%3D%22"+urllib.quote_plus(send_digits)+"%22%3E%3C%2FPlay%3E%0A%3C%2FResponse%3E")

where send_digits is the string of digits you want to send (e.g. keypad entries). In this work-around, send_digits can be longer than 32 characters.

Upvotes: 1

Related Questions