GoToWebinar - Create Registrant

May 5, 2014 at 5:46 PM
Hi,
I Have implemented the Create Registrant procedure for GoToWebinar using the simple version that only accepts Firstname, LastName, and Email. The Code is below. I would like to also pass a custom field. The documentation says:
To use the second version you must pass the additional header value "Accept: application/vnd.citrix.g2wapi-v1.1+json"
Does anyone know how to do this? The code below also passes an ID value that I setup in my webinar but I can't get it to work.

Thanks
Rut Scarborough
    public class Webinar
    {
       const string BaseUrl = "https://api.citrixonline.com";

       private string oAuthToken { get; set; }

       /// <summary>
       /// Use when JSON serialization to properties is needed
       /// </summary>
       /// <typeparam name="T"></typeparam>
       /// <param name="request"></param>
       /// <returns></returns>
       protected T Execute<T>(RestRequest request) where T : new()
       {
          var client = new RestClient();
          client.BaseUrl = BaseUrl;
          request.AddHeader("Authorization", "OAuth oauth_token=" + oAuthToken);

          var response = client.Execute<T>(request);

          if (response.ErrorException != null || response.ErrorMessage != null)
          {
             var ConnectionException = new Exception(response.ErrorMessage);
             throw ConnectionException;
          }

          var RestException = new Exception(response.StatusCode.ToString());
          switch (response.StatusCode)
          {
             case System.Net.HttpStatusCode.OK:
                break;
             case System.Net.HttpStatusCode.Created:
                break;
             case System.Net.HttpStatusCode.BadGateway:
                throw RestException;
             case System.Net.HttpStatusCode.BadRequest:
                throw RestException;
             case System.Net.HttpStatusCode.Forbidden:
                throw RestException;
             case System.Net.HttpStatusCode.InternalServerError:
                throw RestException;
             case System.Net.HttpStatusCode.NotFound:
                throw RestException;
             case System.Net.HttpStatusCode.Unauthorized:
                throw RestException;
             case System.Net.HttpStatusCode.RequestTimeout:
                throw RestException;
             case System.Net.HttpStatusCode.Conflict:
                throw RestException;
             default:
                break;
          }
          return response.Data;
       }

       /// <summary>
       /// Use when no JSON serialization is needed
       /// </summary>
       /// <param name="request"></param>
       /// <returns>System.Net.HttpStatusCode</returns>
       protected System.Net.HttpStatusCode Execute(RestRequest request)
       {
          var client = new RestClient();
          client.BaseUrl = BaseUrl;
          request.AddHeader("Authorization", "OAuth oauth_token=" + oAuthToken);

          var response = client.Execute(request);

          if (response.ErrorException != null || response.ErrorMessage != null)
          {
             var ConnectionException = new Exception(response.ErrorMessage);
             throw ConnectionException;
          }

          var RestException = new Exception(response.StatusCode.ToString());
          switch (response.StatusCode)
          {
             case System.Net.HttpStatusCode.OK:
                break;
             case System.Net.HttpStatusCode.Created:
                break;
             case System.Net.HttpStatusCode.BadGateway:
                throw RestException;
             case System.Net.HttpStatusCode.BadRequest:
                throw RestException;
             case System.Net.HttpStatusCode.Forbidden:
                throw RestException;
             case System.Net.HttpStatusCode.InternalServerError:
                throw RestException;
             case System.Net.HttpStatusCode.NotFound:
                throw RestException;
             case System.Net.HttpStatusCode.RequestTimeout:
                throw RestException;
             case System.Net.HttpStatusCode.Conflict:
                throw RestException;
             default:
                break;
          }

          return response.StatusCode;
       }

       public enum ConferenceCallTypes { PSTN, Hybrid, Private, VOIP }
       public enum ProductTypes { G2M, G2W, G2T, OPENVOICE }
       public enum Statuses { active, suspended }

       private RestRequest GTWrequest(Method method)
       {

          //Method reserved for future use

          var request = new RestRequest(method);
          return request;
       }
       public class CreateRegistrant : Webinar
       {
          public class Response
          {
             public Uri joinURL { get; set; }
             public string uniqueMeetingId { get; set; }

             public string int_err_code { get; set; }
             public string msg { get; set; }
          }

          public string FirstName { get; set; }
          public string LastName { get; set; }
          public string Email { get; set; }
          public string ID { get; set; }
          public string OrganizerKey { get; set; }
          public string WebinarKey { get; set; }

          /// <summary>
          /// Create a new meeting based on the parameters specified. 
          /// </summary>
          /// <param name="oauth">OAuth Token String</param>
          public CreateRegistrant(string oauth, string orgKey, string webinarKey)
          {
             FirstName = "FirstName";
             LastName = "LastName";
             Email = "rut@rscentral.org";
             ID = "ZZ9999";
             oAuthToken = oauth;
             OrganizerKey = orgKey;
             WebinarKey = webinarKey;
          }
          /// <summary>
          /// Send Request
          /// </summary>
          /// <returns>Response</returns>
          public List<Response> Go()
          {
             var request = GTWrequest(Method.POST);
             request.Resource = "G2W/rest/organizers/" + OrganizerKey + "/webinars/" + WebinarKey + "/registrants";
             request.RequestFormat = DataFormat.Json;
             request.AddBody(new { firstName = FirstName, lastName = LastName, email = Email, ID = ID });
             return Execute<List<Response>>(request);
          }
       }
    }
Jan 7, 2015 at 9:58 PM
Below this line in the Execute method:
request.AddHeader("Authorization", "OAuth oauth_token=" + oAuthToken);
put this code:
request.AddHeader("Accept", "application/vnd.citrix.g2wapi-v1.1+json")
That is how to set to use the 1.1 API.