Use The GoToWebinar API To Create Registration Form

By March 1, 2016Miscellaneous

The GoToWebinar API, while thoroughly documented, is not so easy to implement. It’s just a standard REST API, but some parts of the documentation lack clear examples. Although I was able to work through my issues, I thought it would be helpful for others to see my final code samples in order to accomplish their goal of creating a webinar registration form on their website.

Getting Your GoToWebinar Auth Token

Before you can implement the GoToWebinar API, you must first secure an auth token. This can be done with a few methods, but we are looking for an implementation that doesn’t require the user to navigate a dialogue confirmation box. To begin, visit https://developer.citrixonline.com/ and create your free developer account.

Once you’ve registered, go to “My Apps” in the developer portal and click the “Add a New App” button. There are only a few fields to fill out, and you’re golden. Once you’ve been approved, you’ll be given a few credentials: a Consumer Key and a Consumer Secret. For now, we’ll use the Consumer Key.

Take your Consumer Key and use it in this format: https://api.citrixonline.com/oauth/authorize?client_id={consumerKey}. Put the URL in your browser and you’ll be given back some data in JSON format. Copy this and save it. We’ll specifically need the “Auth Token” and “Organizer Key” fields that it provides.

Making The Form

Although there are more than a dozen fields you can submit to the registration API, we’re going to just use three for simplicity: first name, last name, and email address.

<form action="" method="POST" id="registration-form" class="webinar-signup">
			<input name="webinar_key" type="hidden" value="34455776288xxxx" />
			<input name="organizer_key" type="hidden" value="828835101434139xxxx" />
			<input name="firstName" type="text" placeholder="First Name">
			<input name="lastName" type="text" placeholder="Last Name">
			<input name="email" type="text" size="30" maxlength="50" placeholder="Email">
			<input type="submit" value="Register For Event" name="registration-submission" />
			</form>

We’ve left “action” blank so it submits to itself for processing, but you can also change the action to be to a different script that will handle the processing. You’ll want to fill in the “webinar_key” and “organizer_key” hidden fields here. To get your webinar key, go into GoToWebinar, edit a webinar, and copy out the long numerical sting at the end of the URL.

At the top of your PHP document, let’s add the processing portion of the script.

if (isset($_POST['registration-submission'])) {
$base_url = 'https://api.citrixonline.com/G2W/rest';
$org_key = $_POST['organizer_key'];
$web_key = $_POST['webinar_key'];
$vals['body'] = (object) array(
'firstName' => $_POST['firstName'],
'lastName' => $_POST['lastName'],
'email' => $_POST['email']
);
$long_url = $base_url.'/organizers/'.$org_key.'/webinars/'.$web_key.'/registrants';
$header = array();
$header[] = 'Accept: application/json';
$header[] = 'Content-type: application/json';
$header[] = 'Accept: application/vnd.citrix.g2wapi-v1.1+json';
$header[] = 'Authorization: OAuth oauth_token=[put your auth token here]';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $long_url);
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($vals['body']));
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$decoded_response = json_decode($response);
if ($decoded_response->status == 'APPROVED') {
$register_result = true;
} else {
$register_result = false;
}
}

Notice the part above that says “[put your auth token here]” — use the auth token obtained the previous step.

Go ahead and test it to see if it works. I haven’t provided any type of “confirmation” here, but you can use the $register_result variable to do something with that.

Good luck!

Allen Gingrich

Author Allen Gingrich

Allen has worked on the web for over a dozen years. Like many young entrepreneurs, he began with a small workspace in his basement, where he eventually formed Ideas and Pixels. The rest, well, is history. Allen enjoys fine wines, weight training, and beautiful, semantic code.

More posts by Allen Gingrich