-1

I want to create a webinar event using zoom API, i create body data using php and format json in json_encode but when i send POST to zoom API it doesn't work. The result always like this:

[
    [code] => 300
    [message] => Request Body should be a valid JSON object.
]

this is my code in controller:

$id = Yii::$app->request->get('id');

$bodyparam = [
   "topic"       => "test webinar",
   "type"        => 5,
   "start_time"  => "2021-10-02T16:00:00Z",
   "duration"    => 60,
   "timezone"    => "Asia/Singapore",
   "password"    => "test123456",
   "agenda"      => "Test Webinar",
   "recurrence"  => [
       "type"            => 1,
       "repeat_interval" => 1,
       "end_date_time"   => "2021-10-02T16:00:00Z"
   ],
   "settings" => [
       "host_video"       => true,
       "panelists_video"  => true,
       "practice_session" => true,
       "hd_video"         => true,
       "approval_type"    => 0,
       "registration_type"=> 2,
       "audio"            => "both",
       "auto_recording"   => "none",
       "enforce_login"    => false,
       "close_registration" => true,
       "show_share_button"  => true,
       "allow_multiple_devices" => false,
       "email_language"         => "en-US",
       "panelists_invitation_email_notification" => true,
       "registrants_confirmation_email"          => true,
       "registrants_email_notification"          => true,
       "attendees_and_panelists_reminder_email_notification" => [
           "enable" => true,
           "type"   => 1
       ],
       "follow_up_attendees_email_notification" => [
           "enable" => true,
           "type"   => 1
       ],
       "follow_up_absentees_email_notification" => [
           "enable" => true,
           "type"   => 1
       ]
    ]
 ];

//using json_decode and double encode because if i just encode once the result always string
$body = json_encode(json_decode(json_encode($bodyparam)), JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);

$response = Yii::$app->zoom->doRequest('POST','/users/'.$id.'/webinars',['status'=>'active'], $body);
echo "<pre>";print_r($response);exit;

I used skwirrel zoom api wrapper to help me create this event. Is there something wrong?

chiper4
  • 303
  • 5
  • 18
  • Q: Is there something wrong? A: Yes. The server says the payload isn't valid JSON. SUGGESTION: echo $body before you send it. [Edit] your post with the actual JSON that's going over the wire. You can also copy/paste your PHP "echo" into a validator like https://jsonlint.com/ – paulsm4 Oct 12 '21 at 03:00
  • I think you just need to do ``$body = json_encode($bodyparam);`` – Dula Oct 12 '21 at 03:09
  • the result is ```valid JSON```, then what? – chiper4 Oct 12 '21 at 03:09
  • @Dula i have tried it but still ```Request Body should be a valid JSON object.``` – chiper4 Oct 12 '21 at 03:10

1 Answers1

0

According to the documentation, you have to pass an array as the third parameter for doRequest() method. Not a JSON string.

$response = $zoom->doRequest(<METHOD>, <endpoint_path> [,<query_parameter_array> [,<path_parameter_array> [,<request_body_array_or_string>] ] ]);

Simplified:

$params = [,<path_parameter_array> [,<request_body_array_or_string>] ] ];
$response = $zoom->doRequest('METHOD','ENDPOINT_PATH',$params);

Have a look at this example.

Dula
  • 1,276
  • 5
  • 14
  • 23