0

I created a Google sheet using Google Sheets API which copied the content of spreadsheet present in one of my folder in Google Drive. Even the copied file did contain the code of App Script in it. So the file which was created using service account didn't allowed me to use the code of App Script. It throws the following error as shown in image below: Error while running the function

When I created the copy of this file from front end as shown in image below: Copy of Spreadsheet file In this case owner was not service account so I was able to use the App Script.

Can any one help me with this?

Community
  • 1
  • 1
Himesh
  • 31
  • 6

1 Answers1

1

You can programmatically make a Permissions.List using the service account credentials to make another user the owner of the file (the Spreadsheet in this case, you need its ID), you need to set the transferOwnership attribute to true and use a request body like this:

{
  "role": "owner",
  "type": "user",
  "emailAddress": "new-owner@email.com"
}
Andres Duarte
  • 3,166
  • 1
  • 7
  • 14
  • Can you please help me with the example because when I am trying this to do with my file created by **service account** It gives me this error **Bad Request. User message: "Sorry, you do not have permission to share.** And I want to transfer change owner from **service account** to **abc@gmail.com** – Himesh Mar 19 '20 at 11:19
  • Are you using the service account credentials? You need to do it programmatically using the service account credentials, the same way as you created the file. If you're doing so, please provide the code you're using in your question. – Andres Duarte Mar 19 '20 at 12:45
  • I have put a more complete answer to the oldest post mentionned by @ruben – ClementWalter Sep 04 '21 at 08:09