Issue with Migrating of zoom api v1 to v2 API

120 Views Asked by At

I wanted to create zoom user using zoom API , this was working in my code with version 1 zoom API but after zoom has changed its API in April 2020 I am facing few issues.Please find my both API code below For migrating I am following this blog : Click Here

CODE for migration of zoom API version 1 to version 2

Version 1 code:

function createAUser() {
        $createAUserArray          = array();
        $createAUserArray['email'] = $_POST['userEmail'];
        $createAUserArray['type']  = $_POST['userType'];

        return $this->sendRequest( 'user/create', $createAUserArray );
    }

    /*Functions for management of users*/

    function sendRequest( $calledFunction, $data ) {
        /*Creates the endpoint URL*/
        $request_url = $this->api_url . $calledFunction;

        /*Adds the Key, Secret, & Datatype to the passed array*/
        $data['api_key']    = $this->api_key;
        $data['api_secret'] = $this->api_secret;
        $data['data_type']  = 'JSON';

        $postFields = http_build_query( $data );
        /*Check to see queried fields*/
        /*Used for troubleshooting/debugging*/
        if ( $this->debug ) {
            echo $postFields;
        }

        /*Preparing Query...*/
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt( $ch, CURLOPT_URL, $request_url );
        curl_setopt( $ch, CURLOPT_POST, 1 );
        curl_setopt( $ch, CURLOPT_POSTFIELDS, $postFields );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
        $response = curl_exec( $ch );

        /*Check for any errors*/
        $errorMessage = curl_exec( $ch );
        if ( $this->debug ) {
            echo $errorMessage; die();
        }
        curl_close( $ch );

        /*Will print back the response from the call*/
        /*Used for troubleshooting/debugging        */
        if ( $this->debug ) {
            echo $request_url;
            var_dump( $data );
            var_dump( $response );
        }
        if ( ! $response ) {
            return false;
        }

        return $response;
        /*Return the data in JSON format*/
        //return json_encode($response);
    }

Version 2 code:

$curl = curl_init();


$postData = [
    'action'=> 'create',
    'email'=> '[email protected]',
    'type'=> 1,
    'first_name'=> 'Haku',
    'last_name'=> 'Dhakhada'
];
  
  curl_setopt_array($curl, array(
  CURLOPT_POST => true,
  CURLOPT_URL => "https://api.zoom.us/v2/users/",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS, json_encode($postData),
  CURLOPT_HTTPHEADER => array(
    "authorization: Bearer Key",
    "content-type: application/json"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

ERROR in zoom api version 2 code :

<error>
    <code>300</code>
    <message>Request Body should be a valid JSON object.</message>
</error>

Thanks in advance

1

There are 1 best solutions below

0
On

https://github.com/MalikHamzaJaved/ZoomClient

here complete zoom api is integrated in c# .net standard , you can leverage it.