@@ -109,25 +109,28 @@ func flagOptions(
109109 }
110110 }
111111
112- switch bodyType {
113- case MultipartFormEncoded :
114- buf := new (bytes.Buffer )
115- writer := multipart .NewWriter (buf )
116- if err := apiform .MarshalWithSettings (body , writer , apiform .FormatComma ); err != nil {
117- return nil , err
118- }
119- if err := writer .Close (); err != nil {
120- return nil , err
121- }
122- options = append (options , option .WithRequestBody (writer .FormDataContentType (), buf ))
123- case ApplicationJSON :
124- bodyBytes , err := json .Marshal (body )
125- if err != nil {
126- return nil , err
112+ // Only send request body if there's actual data
113+ if len (body ) > 0 {
114+ switch bodyType {
115+ case MultipartFormEncoded :
116+ buf := new (bytes.Buffer )
117+ writer := multipart .NewWriter (buf )
118+ if err := apiform .MarshalWithSettings (body , writer , apiform .FormatComma ); err != nil {
119+ return nil , err
120+ }
121+ if err := writer .Close (); err != nil {
122+ return nil , err
123+ }
124+ options = append (options , option .WithRequestBody (writer .FormDataContentType (), buf ))
125+ case ApplicationJSON :
126+ bodyBytes , err := json .Marshal (body )
127+ if err != nil {
128+ return nil , err
129+ }
130+ options = append (options , option .WithRequestBody ("application/json" , bodyBytes ))
131+ default :
132+ panic ("Invalid body content type!" )
127133 }
128- options = append (options , option .WithRequestBody ("application/json" , bodyBytes ))
129- default :
130- panic ("Invalid body content type!" )
131134 }
132135
133136 return options , nil
0 commit comments