Getting err: 400 Bad Request when creating a meeting

Description
I am using POST: https://api.zoom.us/v2/users/me/meetings to create a meeting using go, here’s my code

// Create ...
func (zm *ZoomMeeting) Create(data *model.Talk) (*ZoomMeetingResponse, error) {
	payloads := &ZoomMeetingRequest{
		Agenda:   data.Description,
		Duration: data.Duration,
		Password: "1234qwer",
		Timezone: data.TimeZone,
		Topic:    data.Title,
		Type:     int64(2),
		Settings: &ZoomMeetingSettingsRequest{
			ApprovalType:                 int64(0),
			Audio:                        "both",
			AutoRecording:                "none",
			CnMeeting:                    false,
			HostVideo:                    true,
			InMeeting:                    false,
			JoinBeforeHost:               false,
			MuteUponEntry:                true,
			ParticipantVideo:             true,
			RegistrationType:             int64(2),
			RegistrantsEmailNotification: false,
			UsePmi:                       false,
			Watermark:                    false,
		},
		StartTime: data.DateTimeStart.Format("2006-01-02T03:04:05Z"),
	}

	payloadsByte, err := json.Marshal(payloads)
	if err != nil {
		return nil, err
	}

	request, err := http.NewRequest(
		"POST",
		"https://api.zoom.us/v2/users/me/meetings",
		bytes.NewBuffer(payloadsByte),
	)
	if err != nil {
		return nil, err
	}
	request.Header.Add("content-type", "application/json")
	request.Header.Add("authorization", fmt.Sprintf("Bearer %s", zm.Provider.GetAccessToken()))

	resp, err := zm.Client.Do(request)
	if err != nil {
		return nil, err
	}

	if resp.StatusCode != 200 {
		a := fmt.Sprintf("Create zoom meeting err: %s", resp.Status)
		return nil, errors.New(a)

	}
	defer resp.Body.Close()

	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	result := ZoomMeetingResponse{}

	if err := json.Unmarshal(body, &result); err != nil {
		return nil, err
	}

	return &result, nil
}

Here’s the printed request

&{
Method:POST 
URL:https://api.zoom.us/v2/users/me/meetings 
Proto:HTTP/1.1 
ProtoMajor:1 
ProtoMinor:1 
Header:map[
   Authorization:[Bearer ...] 
   Content-Type:[application/json]] 
   Body:{
      Reader:{
         "agenda":"\u003cp\u003eZoom meeting creation example\u003c/p\u003e\n",
         "duration":30,
         "password":"1234qwer",
         "timezone":"Asia/Jakarta",
         "topic":"Zoom meeting creation example",
         "type":2,
         "settings":{
            "audio":"both",
            "auto_recording":"none",
            "host_video":true,
            "mute_upon_entry":true,
            "participant_video":true,
            "registration_type":2
         },
         "start_time":"2020-12-26T12:00:00Z"
      }
   }
   ...
}

Error
The error from this line

if resp.StatusCode != 200 {
   a := fmt.Sprintf("Create zoom meeting err: %s", resp.Status)
   return nil, errors.New(a)
}

Reads: [ERROR] Create zoom meeting err: 400 Bad Request

Which App Type (OAuth / Chatbot / JWT / Webhook)?

Oauth

Which Endpoint/s?

https://api.zoom.us/v2/users/me/meetings

Hey @littlechad,

Typically the 400 Bad Request error is thrown when the request body is invalid.

Can you help explain what the Reader object is? Are you sending the Reader object as apart of the request body? If you could log your request body in JSON format before you make the request, and share it here, we can debug further. :slight_smile:

Thanks,
Tommy

Hi Tommy,

the Reader thingy is golang io.Reader interface returned from this line bytes.NewBuffer(payloadsByte), since the http.NewRequest() method requires it as the third argument.

Anyway the actual issue turns out to be the zm *ZoomMeeting interface i initiated beforehand, and i actually manage to solve this issue, by rewriting the http.Client for ZoomMeeting.Client

Sorry to bother your holiday, thanks for taking your time to reply to this, Happy new year :slight_smile:

1 Like

Hey @littlechad,

Happy to hear you got it sorted out! :slight_smile:

Thanks for sharing the solution as well!

Happy near year!