Twilio Missing required parameter To in the post body

Viewed 953

I get this error whenever im sending POST to Twilio

Dim request = HttpWebRequest.Create("https://studio.twilio.com/v1/Flows/FWxxxxx/Executions")

"code": 20001, "message": "Missing required parameter To in the post body", "more_info": "https://www.twilio.com/docs/errors/20001", "status": 400

What's wrong with my code?

request.ContentType = "application/x-www-form-urlencoded"

newinput = "{""param1"":""12345"",""param2"":""test""}"

Dim myData As String = "body {to: +123344\ from: ++122233\ MessagingServiceSid:SomeSID1234\"
myData = myData + "parameters:" + newinput + 
"}"

request.ContentLength = Encoding.UTF8.GetBytes(myData).Length
'POST
Using streamWriter As New StreamWriter(request.GetRequestStream())
        streamWriter.Write(myData)
        streamWriter.Flush()
        streamWriter.Close()
End Using
1 Answers

If you'd like to use Twilio's package to trigger a flow you could in your project folder run:

dotnet add package Twilio

then try this code:

Imports System
Imports Twilio
Imports Twilio.Types
Imports Twilio.Rest.Studio.V1.Flow

Module Program
    Sub Main(args As String())
    
        Console.WriteLine("Trigger a flow with VisualBasic.NET")
        
        Const accountSid = "AC..."
        Const authToken = "4f..."

        TwilioClient.Init(accountSid, authToken)

        Dim execution = ExecutionResource.Create(
            to := New PhoneNumber("+17781234567"),
            from := New PhoneNumber("+17787654321"), 
            pathFlowSid:= "FW..."
        )

        Console.WriteLine(execution.Sid)    
            
    End Sub
End Module

Related