2

I am trying to use the transfers:insert method of the Google Admin SDK Data Transfer API. I am performing this API call as the super admin account of my domain. I have verified that API access is enabled for our domain, and that the Super Admin admin role has permission to use the Data Transfer API.

I am testing this in the APIs Explorer on this page.

55656082996 is the ID string that I got for Google Drive from the applications:list APIs Explorer.

Request:

POST https://www.googleapis.com/admin/datatransfer/v1/transfers?key={YOUR_API_KEY}
{
 "oldOwnerUserId": "olduser@ourdomain.com",
 "newOwnerUserId": "newuser@ourdomain.com",
 "applicationDataTransfers": [
  {
   "applicationId": "55656082996"
  }
 ]
}

Response:

400 OK
- SHOW HEADERS -
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid value for: Invalid oldOwnerUserId."
   }
  ],
  "code": 400,
  "message": "Invalid value for: Invalid oldOwnerUserId."
 }
}

I get the same "Invalid value for: Invalid oldOwnerUserId." response no matter if I use email addresses or usernames. I also tried excluding the applicationDataTransfers array from the response, but that also didn't work.

Employee
  • 2,231
  • 3
  • 33
  • 60

2 Answers2

5

The documentation does not say this, but the Id cannot be the user's email address, like in all of the other Google APIs, but rather it needs to be a numeric ID for the user that you can get using the Users:get Directory API method.

I figured this out by Google searching and coming across this documentation, where they elaborate upon oldOwnerUserId by saying "# ID"

Employee
  • 2,231
  • 3
  • 33
  • 60
  • is that the correct syntax to pass API Key on HTTP Request? Also, can you use service account to for Data Transfer? Google Documentation is really lacking for beginner. – s2000coder Apr 20 '18 at 04:58
  • I'm not sure if passing an API key as a URL parameter is valid, but that's just how it appeared in their documentation at one point. Yes, you can use a service account with Domain-wide Delegation for this API. More information about setting it up [here](https://stackoverflow.com/questions/40936257/how-to-use-the-gmail-api-oauth2-for-apps-script-and-domain-wide-delegation-to/40936258#40936258) - the instructions are for a different API but the service account access token generation should be the same. – Employee Apr 23 '18 at 22:11
1

In addition to the answer above.

Here is how you can get the employee' IDs from Gsuite API in Python 3.*

def create_directory_service():
    credentials = cls.get_credentials(scopes=['https://www.googleapis.com/auth/admin.directory.user'])
    return build('admin', 'directory_v1', credentials=credentials, cache_discovery=Fals


service = create_directory_service()                                          

old_owner_google_id = service.users().get(userKey=old_owner).execute()['id']
new_owner_google_id = service.users().get(userKey=new_owner).execute()['id']