Share docs between domain users

Google Apps Administrator have access control privilege for the documents of users in his/her domain. An administrator can share the document of one user to any other user in that domain. This is mostly required when you need to audit the documents of a domain user. Say, Bob's boss want to audit the documents of Bob and does not want to ask Bob to share the documents. In this case, Googe Apps Administrator can help Bob's boss.


Here is a little Google Apps Script code which will share the document of user 1 with user 2 in the same Google Apps Domain.

//This function will share the document of user1 with user2

//and return the status code

//To run this function, you must be having administrator priviledge in your domain

function shareDocument(){

  var base = '';


  //Bob's ID

  var user1 = '';


  //Bob's Boss's ID

  var user2 = '';


  //Doc ID which you want to share with Bob's Boss

  //In most of the cases administrator or Bob's boss will not be having the docID

  //You can use this tutorial to get the IDs of Documents of Bob


  var docId = 'DocumentID';



  var fetchArgs = googleOAuth_('docs', base);

  fetchArgs.method = 'POST';

  //Build the xml

  var rawXml = "<entry xmlns='' xmlns:gAcl=''>"

      +"<category scheme='' "


      +"<gAcl:role value='writer'/>"

      +"<gAcl:scope type='user' value='"+user2+"'/>"


  fetchArgs.payload = rawXml;

  fetchArgs.contentType = 'application/atom+xml';


  var url = base + user1+'/private/full/'+docId+'/acl?v=3&alt=json';//'+yourDocumentID+'/acl?v=3&alt=json';

  var urlFetch = UrlFetchApp.fetch(url, fetchArgs);

  return urlFetch.getResponseCode();


//Google oAuth

//Used by shareDocument() function

function googleOAuth_(name,scope) {

  var oAuthConfig = UrlFetchApp.addOAuthService(name);






  return {oAuthServiceName:name, oAuthUseToken:"always"};


Related tutorial: