SB2055
SB2055

Reputation: 12862

Twilio Error - 12300 - Invalid Content Type only sometimes

I have a C# / .NET WebApi endpoint tied to a number. When that number receives a text, it's forwarded to my API via webhook.

Sometimes (not all the time), I get an error in my debugger with the following:

Error - 12300

Invalid Content-Type

Twilio is unable to process the Content-Type of the provided URL. Please see the Twilio Markup XML Documentation for more information on valid Content-Types. You must return a Content-Type for all requests. Requests without a Content-Type will appear in the App Monitor as a 502 Bad Gateway error.

In the response that triggered this, I see the following:

enter image description here

With the following headers:

Content-Type application/json; charset=utf-8 
Pragma no-cache 
Date Sat, 14 Jan 2017 02:57:45 GMT 
X-AspNet-Version 4.0.30319 
X-Powered-By ASP.NET

What might be causing this, and how do I address it?

Upvotes: 5

Views: 6944

Answers (2)

lucky.expert
lucky.expert

Reputation: 793

I too was sending a json response and getting this error. Using the answer by Frederic Torres got me on the right track. It looks like Twilio is looking for XML in TwiML format. But if you basically just return an empty "Response" element in text/xml format, that satisfies Twilio. So here is a simplified answer for anybody else that runs into this:

    public ContentResult IncomingSMS(string To, string From, string Body)
    {
            //do stuff
            //...
            return Content("<Response/>", "text/xml");
    }

Upvotes: 3

Frederic Torres
Frederic Torres

Reputation: 699

After some research from TWIML MESSAGE: YOUR RESPONSE this code seems to work

[HttpGet]
public HttpResponseMessage SmsAnswerCallBack(string id)
{
    _smsAnswerCallBackCallIndex++;
    var r = new SmsApiResult();

    r.SetStatus(true, _smsSendCallIndex, _smsAnswerCallBackCallIndex);
    r.DataList  = _answers;

    var res     = Request.CreateResponse(HttpStatusCode.OK);
    res.Content = new StringContent("<Response/>", Encoding.UTF8, "text/xml");
    return res;
}

Upvotes: 8

Related Questions