GoToWebinar - Request not in expected format - RestSharp

Similar to this forum post:

However he didn't really explain what he found was wrong with his code.

I'm using RestSharp to make API calls. I've been able to get it to work great to pull an list of upcoming webinars however when I try to register participant I keep getting a 400/Request not in expected format error.

Following this documentation, here is my code:

var client = new RestClient(string.Format("{0}/webinars/{1}/registrants", "300000000000xxxxxx", btn.CommandArgument));
var request = new RestRequest(Method.POST);
request.RequestFormat = DataFormat.Json;

request.AddHeader("Accept", "application/json");
request.AddHeader("Accept", "application/vnd.citrix.g2wapi-v1.1+json");
request.AddHeader("Authorization", "OAuth oauth_token=" + System.Configuration.ConfigurationManager.AppSettings["GoToWebinar"]);

request.AddParameter("firstName", LoggedInUser.FirstName);
request.AddParameter("lastName", LoggedInUser.LastName);
request.AddParameter("email", LoggedInUser.Email);

var response = client.Execute(request);
var statusCode = response.StatusCode;

Any insights on how I can figure out why I keep getting that error?

Thank you!


Instead of using AddParamter (which adds key/value parameters to the request body), you need to write JSON instead:

request.DataFormat = DataFormat.Json;
request.AddBody(new {
    firstName = LoggedInUser.FirstName,
    lastName = LoggedInUser.LastName,
    email = LoggedInUser.Email

You'll also need to clear the handlers (which automatically set the Accept header) if you want to specify them directly:


Need Your Help

How to Open a CSV or XLS with Jet OLEDB and attain Table Lock?

c# csv locking oledb

I am trying to figure out how to read/write lock a CSV or XLS file when I read it as a Database via Jet OLEDB.