How do I call CITRIX (LogMeIn) API via PHP to register new GotoWebinar attendee?

2.9k Views Asked by At

I am using the below code to register user to the webinar:

   $headers = array(
 'HTTP/1.1',
  'Accept: application/json',
  'Accept: application/vnd.citrix.g2wapi-v1.1+json',
  'Content-Type: application/json',
  'Authorization: OAuth oauth_token='.$access_token,
  'Name_First:test',
  'Name_Last:ank',
  'Email:[email protected]',
   );

 $gtw_url = "https://api.citrixonline.com/G2W/rest/organizers/{organizerkey}/webinars/{webinarkey}/registrants";
 $curl = @curl_init();
 @curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
     @curl_setopt($curl, CURLOPT_URL, $gtw_url);
      @curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
     @curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
     @curl_exec($curl);
     @curl_close($curl);

I have passed webinar key and organizer key. I am supposed to get the output like:

HTTP/1.1 201 OK Content-Type: application/json
{
    "registrantKey":5678,
    "joinUrl":"https://www1.gotomeeting.com/join/123456789/5678"
}

The problem is that when i run the file i got output

[
    {
        "registrantKey":106660361,
        "firstName":"test",
        "lastName":"1",
        "email":"[email protected]",
        "status":"WAITING",
        "registrationDate":"2012-06-29T21:07:10Z",
        "joinUrl":"https://www1.gotomeeting.com/join/141654337/106660361",
        "timeZone":"America/Denver"
    }
]

I am using the create webinar URL, so why am I getting the info of the user that is already registered?

1

There are 1 best solutions below

0
On

The question is 3 years old, but considering the present dismal state of the CITRIX (now LogMeIn) API documentation, I'm offering the following snippet as a possible solution:

Obviously, we'll need the Organizer Key and Access Token data for our account...

    $organizer_key= '10000000000XXXXXXX';
    $access_token = 'GwsiiPWaJbHIiaIiocxxxxxxxxxx';

Get the minimum required fields for a webinar (for example from an HTML form) and JSON encode the data...

    $newRegFields = (object) array(
        'firstName' => $_POST[ 'FirstName' ],
        'lastName'  => $_POST[ 'LastName'  ],
        'email'     => $_POST[ 'Email'     ],
    );

    $newRegistrantFields = json_encode( $newRegFields );

    //echo '<br><br>' . $newRegistrantFields;

Get the Webinar...

    $webinarID = preg_replace( "/[^0-9]/", "", $_POST[ "WebinarKey" ] );

Set the URL to the LogMeIn API (the resendConfirmation option is not required)...

    $gtw_url = "https://api.citrixonline.com/G2W/rest/organizers/" . $organizer_key . "/webinars/" . $webinarID . "/registrants?resendConfirmation=false";

Format our POST headers...

    $headers = array(
        "HTTP/1.1",
        "Accept: application/json",
        "Content-Type: application/json",
        "Authorization: OAuth oauth_token=$access_token",
        "Content-Length: " . strlen( $newRegistrantFields )
    );

Set our cURL options, ensuring we specify a POST with CURLOPT_POST, 1 ...

    $curl = curl_init();

    curl_setopt( $curl, CURLOPT_URL, $gtw_url                       );
    curl_setopt( $curl, CURLOPT_HTTPHEADER, $headers                );
    curl_setopt( $curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0 );
    curl_setopt( $curl, CURLOPT_SSL_VERIFYPEER, 0                   );
    curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1                   );
    curl_setopt( $curl, CURLOPT_POST, 1                             );
    curl_setopt( $curl, CURLOPT_POSTFIELDS, $newRegistrantFields    );

    $newRegistrants = curl_exec( $curl );
    curl_close( $curl );

Our cURL call has returned with JSON encoded data, whether it's a server error message or a confirmation of registration. Now let's turn the reply into a handy associative array...

    $newRegistrantsArray = json_decode( $newRegistrants, true );

    //echo '<br><br>' . $newRegistrants . '<br><br>';
    //echo '<pre>'; print_r( $newRegistrantsArray ); echo '</pre>';

If the errorCode key was returned, then the registration bombed out. All I'm doing here is grabbing the actual error description from the server and loading it up to return to my calling HTML page, but this is totally optional...

    if( array_key_exists( 'errorCode', $newRegistrantsArray )) {
        $form_data[ 'status' ] = false;
        $form_data[ 'code'   ] = $newRegistrantsArray[ 'description' ];
        $form_data[ 'error'  ] = 'E200';
        //echo json_encode( $form_data );
        //exit;
    }

Now, if a registration was successful, the server will return something like...

(
  [registrantKey] => 2.5022062212198E+18
  [joinUrl] => https://global.gotowebinar.com/join/6552167171182613761/103193261
) 

...and so I'm just checking to see if those keys were returned, and if so, I know the registration was good.

    if( array_key_exists( 'registrantKey', $newRegistrantsArray ) && array_key_exists( 'joinUrl', $newRegistrantsArray ) ) {
        $form_data[ 'status' ] = true;
        $form_data[ 'code'   ] = $_POST[ 'Email' ] . ' successfully registered with webinar';
        $form_data[ 'error'  ] = 'E300';
        //echo json_encode( $form_data );
        //exit;
    }