I'm trying to use JSON over HTTP to communicate with the Twilio API (I'm running on asp.net vNext - and their C# library doesn't yet support coreclr)
I've got the following code, but every time I call the API I get the same 400 - Bad request response:
{"code": 21603, "message": "A 'From' phone number is required.", "more_info": "https://www.twilio.com/docs/errors/21603", "status": 400}
I'm using the following code to setup the request and make the call - the auth succeeds and I get the above error:
var byteArray = Encoding.ASCII.GetBytes("{AccountSid}:{AuthToken}");
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray));
var jsonStr = JsonConvert.SerializeObject(new {
From = WebUtility.UrlEncode("+15005550003"), // A test number twilio supply
To = WebUtility.UrlEncode("{my phone number}"),
Body = WebUtility.UrlEncode("Hi there from a pure json rest client...")
});
var response = await client.PostAsync("https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/SMS/Messages.json", new StringContent(jsonStr));