-1

I cannot seem to figure out how to call a Twilio function correctly. I tried calling it by passing data via POST:

url = "https://xxxx-dev.twil.io/voicemail" 
data = {'event': {'id': '00141',
                  'RecordingUrl': 'https://api.twilio.com/2010-04-01/Accounts/ssssss/Recordings/xxxxxxx.mp3',
                  'From': '+12xxxxxxxxx',
                  'textTranslation': 'something here'}}
requests.post(url, data=data)

It doesn't seem to work. It returns 500 because it does not find the event object or the context object. How do I pass event, context, callback when calling a function directly?

elena
  • 3,740
  • 5
  • 27
  • 38
  • 1
    can you include the code or command with your Twilio Function URL? – lizziepika Dec 15 '22 at 05:30
  • 2
    You mean include url address into the post request? I will. I also found the solution for this issue and I will post the solution soon. – elena Dec 15 '22 at 18:00

1 Answers1

0

Turns out I was sending the data incorrectly. You also don't need to include context nor callback, those are provided by twilio. You need to send only data as json to that endpoint.

url = "https://xxxx-dev.twil.io/voicemail" 
data = {'id': '00141',
        'RecordingUrl': 'https://api.twilio.com/2010-04-01/Accounts/ssssss/Recordings/xxxxxxx.mp3',
        'From': '+12xxxxxxxxx',
        'textTranslation': 'something here'}
requests.post(url, json=data)
elena
  • 3,740
  • 5
  • 27
  • 38