Hi, I’m trying to use the rest_command to use Twilio service to fire a call for notification purpose.
Trying with curl or with a rest client for Chrome is working but putting the same values in Home Assistant result in an error 400 BAD REQUEST.
in my configuration.yaml I have:
rest_command:
call_me:
url: 'https://api.twilio.com/2010-04-01/Accounts/[ACCOUNTSID]/Calls.json'
method: post
username: [ACCOUNTSID]
password: [AUTHTOKEN]
payload: From=+391234567890&To=+391234567890&Url=http://twimlets.com/message?Message=Hi
In home-assistant.log I find:
17-01-26 18:36:28 homeassistant.components.rest_command: Error 400 on call https://api.twilio.com/2010-04-01/Accounts/[ACCOUNTSID]/Calls.json.
I modified the rest_command.py source file adding some extra logging to better understand and got:
17-01-26 18:36:27 homeassistant.components.rest_command: Payload b'From=+39123456789&To=+39123456789&Url=http://twimlets.com/message?Message=Hi'.
17-01-26 18:36:28 homeassistant.components.rest_command: Error response <ClientResponse(https://api.twilio.com/2010-04-01/Accounts/[ACCOUNTSID]/Calls.json) [400 BAD REQUEST]>
<CIMultiDictProxy('Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Headers': 'Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since', 'Access-Control-Allow-Methods': 'GET, POST, DELETE, OPTIONS', 'Access-Control-Allow-Origin': '*', 'Access-Control-Expose-Headers': 'ETag', 'Content-Type': 'application/json', 'Date': 'Thu, 26 Jan 2017 18:36:27 GMT', 'Twilio-Request-Duration': '0.079', 'Twilio-Request-Id': 'RQ7c2e060e3b584426aed99f603afaa8ad', 'X-Powered-By': 'AT-5000', 'X-Shenanigans': 'none', 'Content-Length': '129', 'Connection': 'keep-alive')>
with
_LOGGER.info("Payload %s.", payload)
and
_LOGGER.warning("Error response %s.", request.json())
I’m pretty sure there is something I’m doing wrong but the payload seems good to me.
Twilio API documentation says that the Content-Type header must be set to “application/x-www-form-urlencoded”, don’t know how to set this header in HA anyhow.
Any help is more then welcome