Twilio HTTP ERROR 400 Bad Request

Recently, I’ve started to get errors returned from Twillio (last 4 of phone number removed) -

</body>
</html>
 Attempt (counter): 1. Sending to this number: 774287XXXX. This is the error: Error: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 400 Bad Request</title>
</head>
<body><h2>HTTP ERROR 400 Bad Request</h2>
<table>
<tr><th>URI:</th><td>/2010-04-01/Accounts/AC18d9727e2ef92c10b5c4aaf738c0169e/Messages.json</td></tr>
<tr><th>STATUS:</th><td>400</td></tr>
<tr><th>MESSAGE:</th><td>Bad Request</td></tr>
<tr><th>SERVLET:</th><td>jersey</td></tr>
</table>

</body>
</html>

This is the codeless section that sends the text -

I loop the send request in case there is an error, and on the second request, the message does get sent. This is from Twilio’s site -

Any idea why this would start happening?

Tim

Hi Tim,

It looks like the error is coming from Twilio. It would be hard for us to say what the root cause it. I recommend reaching out to them to see what they’d say.

Regards,
Mark

Thanks, @mark-piller.

I asked Twilio, and they asked if you could provide the full response to the calls. The error message alone is not enough for them to troubleshoot.

Thanks,
Tim

Hello @Tim_Jones

The following variable contains the full text of the error.

Regards,
Inna

Is there any way to get full headers?

Tim

Hi @Tim_Jones

Yes, if the error comes from the server as a response it contains response headers.
You can try with the following block:

It looks like the error being returned is an HTML string, not a JSON object.

Tim,

I am curious, wouldn’t Twilio Support be able to re-create an API call into their own system to see what their system responds with?

Mark

Twilio doesn’t see the errors on their end, and the error format doesn’t match what they’re expecting.

It seems like the call is getting stopped before getting to the API code. Maybe at the webserver level, hence the HTML being returned?

I think this is a Twilio problem, and it has stopped anyway, so I won’t ask for any more time on this now.

Thanks to everyone for the help!

Tim

2 Likes

Hi @Tim_Jones
Have you managed to resolve this issue? I started to get same error, right after I published my app. When I troubleshoot the cloud code, I receive the same error if invoking service with my custom domain, but when using BackendLess subdomain the call is successful.
@mark-piller is there anything that needs to be done additionally after publishing app?
There is no domain configuration on Twilio side.

Best regards,
Uldis

I never figured it out. The error comes and goes and I just accept it at this point because no one can tell me what’s happening.

Your testing makes me think it’s a backendless issue but I have no idea.

Tim

Hi @Uldis_Borkus

Do you also use the Twillio API Service?
It should not make any difference where you call the API service from because inside the service it just make a request to the twillio server

Hi @vladimir-upirov
Yes I’m using Twilio API service.
And similarly as for @Tim_Jones I no longer have this issue and API service works as expected (didn’t change anything either).
Will introduce error handling for end users to be aware if it repeats at some point.

Best Regards,
Uldis

Issue is back and unpredictable. Happens like 5-10 times in a row and then works once.
This is how the logic looks on api service side:

@vladimir-upirov While I’m waiting on Twilio support for more details, I also notice such error in logs:

10:20:32.787 | SERVER_CODE | INFO | [828834] Building ServerCode Model for path (/opt/backendless/repo/f001f3bf-4ccd-b35e-ffd0-23845dee6000/files/servercode/CODELESS/Phone/PRODUCTION)

10:20:32.788 | SERVER_CODE | INFO | [828834] ServerCode Model built in 6ms

10:20:32.792 | SERVER_CODE | INFO | [828834] [292A8B50-AAC2-876C-FF38-7089B88F7400] [INVOKE SERVICE] services.Phone.sendVerificationCode

10:20:33.817 | SERVER_CODE | ERROR | [828834] Error:

HTTP ERROR 400 Bad Request

URI: /2010-04-01/Accounts/AC62b8bd9124f38c403a4e66a1271d5677/Messages.json
STATUS: 400
MESSAGE: Bad Request
SERVLET: jersey

at checkStatus (/usr/local/lib/node_modules/backendless-coderunner/node_modules/backendless-request/lib/request.js:343:9) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

10:20:33.817 | SERVER_CODE | INFO | [828834] Processing finished in 1043.496ms

Could it have any useful information to undersatnd what actually is happening?

Best Regards,
Uldis

The API Service transfers everything it gets from the Twilio service.
Could you please

  • provide your appId
  • prepare a test API Service with minimum logic with an already specified target phone number

and will try to display more info from the error

Looks like I found the problem in the API Service, could you please reinstall the service and check how it works after upgrade

Great news! What do I need to do, if anything, for cloud code?

Thanks,
Tim

Thank you @vladimir-upirov
Uninstalled and reinstalled Twilio Api Service.
Tested with previously used phone number but looks like Twilio now is blocking outgoing SMS to that particular number.
So tried with another phone number and so far all works correct.

Thank you!

@Uldis_Borkus great, please let us know if you see any issues

@Tim_Jones just do the same as @Uldis_Borkus did, uninstall and reinstall the Twilio Api Service.

@vladimir-upirov Thank you for fast fix! For now, I think we can resolve this topic.