wordpress site integration with rest API

I’m trying to integrate with zoom.us, they have their guides here – https://support.zoom.us/hc/en-us/articles/201363053-Meeting-API

When someone schedules a meeting, the scheduler creates a post, which I pick up and call this function:

Read More
function scheduler_zoom_integration($post_id) {
    $postdata = get_post($post_id);
    $appointment_id = get_post_meta( $post_id, '_birs_appointment_id', true );    
    if (!empty($appointment_id)) {      
        $conference_details = schedule_meeting();
         add_post_meta($appointment_id,'appointment_zoom_details', $conference_details, true);    
    }
 }

add_action('publish_post', 'scheduler_zoom_integration');

Inside that function I call the schedule_meeting function that is using the REST API from zoom to get the meeting details including the link people will click to join the meeting.

function schedule_meeting($coach_id, $appointment_id, $start_time) {
    $api_key = 'xxxxxxxxxxxxxxxxxxxxxxx';
    $api_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $coach_zoom_id = get_user_meta($coach_id, 'coachzoomid', true);
    $url = 'https://api.zoom.us/v1/meeting/create?api_key='.$api_key.'&api_secret='.$api_secret.'&data_type=JSON&host_id='.$coach_zoom_id.'&topic=health&type=2&start_time='.$start_time.'&duration=30&timezone=GMT-7:00&option_jbh=true&option_start_type=video';

    $opts = array(
      'http'=>array(
            'method'=>"GET",
            'header'=>"Accept-language: enrn" .
                  "Cookie: foo=barrn"
        )
    );
    $context  = stream_context_create($opts);
    $response = fopen($url, 'r', false, $context);
    fpassthru($response);
    $response = json_decode($response);
    fclose($response);
   return $response; 


 }

I’m looking to get feedback on how I’m performing this function as I’ve never done a REST API before. Should I use fopen / fclose? How do I make the call to begin with? Any help is appreciated.

Related posts

Leave a Reply

1 comment