title: Creating a okhttp3 request body to create a folder in google drive
body: <p>In my android app I am using okhttp:3.10.0 to create a httpclient to make a request to google drive (REST V3) api. I want to create a folder in users google drive. I read <a href="https://developers.google.com/drive/api/v3/folder" rel="nofollow noreferrer">google documentation</a> to create a folder. This documentation suggest to have something like this</p>
  <pre><code>File fileMetadata = new File();
  fileMetadata.setName(&quot;Invoices&quot;);
  fileMetadata.setMimeType(&quot;application/vnd.google-apps.folder&quot;);
  </code></pre>
  <p>I went through <a href="https://stackoverflow.com/questions/54176209/create-new-folder-in-google-drive-with-rest-api">this question</a> as well. I am making the okhttpclient like this</p>
  <pre><code>OkHttpClient client = new OkHttpClient();
                          RequestBody body = ????????
                          Request request = new Request.Builder()
                                  .url(&quot;https://www.googleapis.com/drive/v3/files&quot;)
                                  .addHeader(&quot;Authorization&quot;, String.format(&quot;Bearer %s&quot;, tokens[0]))
                                  .post(body)
                                  .build();
  
                          try {
                              Response response = client.newCall(request).execute();
                              String jsonBody = response.body().string();
                              Log.i(LOG_TAG, String.format(&quot;User Info Response %s&quot;, jsonBody));
                              return new JSONObject(jsonBody);
                          } catch (Exception exception) {
                              Log.w(LOG_TAG, exception);
                          }
                          return null;
  </code></pre>
  <p>I am trying to use a json object but it is not converting to request body because it can not resolve companion</p>
  <pre><code>import okhttp3.MediaType.Companion.toMediaTypeOrNull;
  import okhttp3.RequestBody.Companion.toRequestBody;
  
  JSONObject jsonObject = new JSONObject();
                          try {
                              jsonObject.put(&quot;title&quot;, &quot;Ancd test&quot;);
                              jsonObject.put(&quot;mimeType&quot;, &quot;application/vnd.google-apps.folder&quot;);
                          } catch (JSONException e) {
                              e.printStackTrace();
                          }
  
                          String body = jsonObject.toString().toRequestBody(&quot;application/json; charset=utf-8&quot;.toMediaTypeOrNull());
  </code></pre>
  <p>Now I am not sure how to add that meta data in request body. Anyone knows how to do this?</p>