10

I am trying to call Google API method drive.files.insert to create a folder in Google Drive with a request like this (using Google APIs Client Library for JavaScript):

var request = gapi.client.drive.files.insert({'convert': 'false', 'ocr': 'false'});
request.execute(function(resp) { console.log(resp); });

The problem is that I need to specify some params in the request body, for example:

{
    "title":"testFolder",
    "description":"hello world",
    "mimeType":"application/vnd.google-apps.folder"
}

But I cannot figure it out how to specify these parameters with the Google APIs Client Library for JavaScript. Is there any suggestion of how I can achieve this?

3 Answers 3

9

Not necessarily gapi.client.request with body field.

You may try gapi.client.drive.files.insert({'convert': 'false', 'ocr': 'false','resource': resource}) where resource is actually what you want to send, e.g.

resource = {
    "title":"testFolder",
    "description":"hello world",
    "mimeType":"application/vnd.google-apps.folder"
}

I have not verified that but I have tried exactly the same scenario with sending request body for creating Google Task list (gapi.client.tasks.tasklists.insert)

1
  • 2
    Thanks a lot! Same thing applies for analytics api that needs to upload a request body. So for some reason they decided "resource" was a good keyword to delimit request body but didn't care about documenting it well.
    – Eduardo
    Dec 17, 2013 at 18:19
4

Use the "resource" keyword to send the body.

3

Pass the body field. See this example for more information.

2
  • Thank you so much, so we need to use gapi.client.request if we want to send a request with body
    – KiL
    Aug 7, 2012 at 5:24
  • Is there a solution without using gapi.client.request?
    – Eduardo
    Dec 17, 2013 at 18:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.