0

I have to create multiple user permissions for a single folder by using Drive REST API. If I do requests (more than one) continuously for each user (because Document List API batchACL deprecated) It returns permissionIds for every user but most of the time only one user granted the permission. This caused errors in my application. I moved to Google Batch Requests and my request postBody is generated like this,

        var postBody = "";
        dataObj.users.forEach(function (entry) {

            var batchBody = {role: entry.role, type: "user", value: entry.email };
            batchBody = JSON.stringify(batchBody);
            postBody = postBody.concat("--batch_", collectionId, "\n");
            postBody = postBody.concat("Content-Type: application/http \n");
            postBody = postBody.concat("Content-ID: ", entry.email, "\n");
            postBody = postBody.concat("Content-Transfer-Encoding: binary \n");
            postBody = postBody.concat("POST /drive/v2/files/", collectionId, "/permissions \n");
            postBody = postBody.concat("Content-Type: application/json \n");
            postBody = postBody.concat("Content-Length: ", batchBody.length, " \n");
            postBody = postBody.concat(batchBody, " \n");
        });

        postBody = postBody.concat("--batch_", collectionId, "--");

it returns success with 200 and response body is like this,

--batch_vfFEpoYZl9Q_AAYPEVhdVNI--

--batch_vfFEpoYZl9Q_AAYPEVhdVNI--

but no permission granted for any user. And the response body shouldn't like this as per the Google documentation. Can someone help me to find the problem or any guidance to use "google-api-nodejs-client" to do the same batch request?

0 Answers0