Try ERPNext Buy Support Partners Foundation

SMS integration - requests.post issue with auth

Hi All,
I am trying to integrate twilio with erpnext for sending SMS. It fails due to the auth issue
Below is frappe code where it fails link
gateway_url = https://[API KEY]:[TOKEN]@api.twilio.com/2010-04-01/Accounts/[API KEY]/Messages.json
headers = {u’From’: u’+1234567890’, u’Accept’: u’text/plain, text/html, /’}
params = {u’Body’: ‘Example Message’, u’To’: u’91987654321’}
response = requests.post(gateway_url, headers=headers, data=params)
This fails with following error

‘HTTPError: 400 Client Error: BAD REQUEST for url’

To make it work, auth has to be corrected , following code worked
gateway_url=‘https://api.twilio.com/2010-04-01/Accounts/[API KEY]/Messages.json’
data = [(‘To’,’+91987654321’),(‘From’,’+1234567890’),(‘Body’,‘Success Test’),]

response = requests.post(gateway_url,data=data, auth=([API KEY],[TOKEN]))

To things required is To number has to have ‘+’ and auth to be passed to requests.post

My question, (a) How can i override requests.post of frappe link from my custom app
(b) Is there any way to correct frappe’s requests.post

Thanks!
@revant_one, any suggestions?! thanks

2 Likes

Try stringify the post params instead of sending dict.

Also add header for content type x-www-form-urlencoded if necessary.

1 Like

Greetings, I have successfully bought an SMS enabled number and SMS credit from Twilio.
Now I’m failing to integrate as I’m not sure what to fill out at SMS Settings in ERPNext. [Newbie]

Welcome to ERPNext,

These may help

https://erpnext.com/docs/user/manual/en/setting-up/sms-setting

@clarkej I tried following the tutorial and this is what happens. There is no even an error of SMS sending attempt on my Twilio dashboard but ERPNext has logged that an SMS has been sent.

See attached.

@jayfiro did you end up managing to implement Twilio?
@System19 You mentioned you switched providers, mind sharing which one is it?

To troubleshoot, access to report logs on either end will give clues and eliminate guesswork!

HI @ashish-greycube may you share SMS settings Twilio.?

Thanks