0

I want to insert a new parent for my file in Google Drive. This allows the file to be in two different folders at the same time with the same FileID. This is my code: (I'm running this on Node.js and using request Node package but this shouldn't make any difference anyways).

var request_url = 'https://www.googleapis.com/drive/v2/files/' + FILE_ID + '/parents/';
 request.post({
   "url": request_url,
   'headers': {
     'Authorization': 'Bearer ' + accessToken
   },
   'body': JSON.stringify({
     id: PARENT_FOLDER_ID
   })

 }, function(response, body) {
   console.log(body);
 });

However, I'm getting the following error:

{
  "error": {
    "errors": [{
      "domain": "global",
      "reason": "resourceRequired",
      "message": "Resource metadata required"
    }],
    "code": 400,
    "message": "Resource metadata required"
  }
}

I've search Google Drive's API documentations but didn't find any relevant solutions.

Google Drive Parents insert API reference: https://developers.google.com/drive/v2/reference/parents/insert

Google Drive API parents resource schema: https://developers.google.com/drive/v2/reference/parents#resource

any help would be greatly appreciated :)

1 Answer 1

1

Instead of

 'body': JSON.stringify({
     id: PARENT_FOLDER_ID
   })

try

'json': {
         id: PARENT_FOLDER_ID
       }
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for the help! One questions though, wouldn't "body" of a request be the "body" that Google Drive expects? does this mean that "json" is actually the body of the request?
you'll need to read the API docs for node request to understand the difference. In both cases, the body of the http request is (probably) the same. The difference is the setting of the Content-Type http header which tells the server (G Drive in this case) how to interpret that body.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.