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

后端 未结 1 1110
生来不讨喜
生来不讨喜 2021-01-07 11:03

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

   $headers = array(
 \'HTTP/1.1\',
  \'Accept: application/json\',
  \'Accept: application/vnd.ci         


        
1条回答
  •  感情败类
    2021-01-07 11:15

    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 '

    ' . $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 '

    ' . $newRegistrants . '

    '; //echo '
    '; print_r( $newRegistrantsArray ); echo '
    ';

    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;
        }
    

    0 讨论(0)
提交回复
热议问题