0

I am trying to write a program that transfers users drive and docs files from one user to another. It looks like I can do it using this documentation Documentation.

I created the data transfer object, which looks like this:

datatransfer = {
        'kind': 'admin#datatransfer#DataTransfer',
        'oldOwnerUserId': 'somenumberhere',
        'newOwnderUserId': 'adifferentnumberhere',
        'applicationDataTransfers':[
            {
                'applicationId': '55656082996', #the app id for drive and docs
                'applicationTransferParams': [
                    {
                        'key': 'PRIVACY_LEVEL',
                        'value': [
                            {
                                'PRIVATE',
                                'SHARED'
                            }
                        ]
                    }
                
                ]
            
            
            }
         ]
        
    }

I have some code here for handling Oauth and then I bind the service with:

service = build('admin', 'datatransfer_v1', credentials=creds)

Then I attempt to call insert() with

results = service.transfers().insert(body=datatransfer).execute()

and I get back an error saying that it 'missing required field: resource'.

I tried nesting all of this inside a field called resource and I get the same message. I tried passing in JUST a json structure that looked like this {'resource': 'test'} and I get the same message. So I tried using the "Try this method" live tool on the documentation website, If I pass in no arguments at all, or just pass in the old and new user, I get the same message 'missing required nested field: resource'. If I put in 'id':'55656082996' with ANY other arguments it just says error code 500 backend error. I tried manually adding a field named "resource" to the live tool and it says 'property 'resource' does not exist in object specification"

1 Answers1

0

I finally got this to work. If anyone else is struggling with this and stumbles on this, "applicationId" is a number, not a string. Also, the error message is misleading - there is no nested field called "resource." This is what worked for me:

datatransfer = {
        "newOwnerUserId": "SomeNumber",
        "oldOwnerUserId": "SomeOtherNumber",
        "kind": "admin#datatransfer#DataTransfer",
        "applicationDataTransfers": [
            {
                "applicationId": 55656082996,
                "applicationTransferParams": [
                    {
                        "key": "PRIVACY_LEVEL"
                    },
                    {
                        "value": [
                            "{PRIVATE, SHARED}"
                           ]
                    }
                ]
            }
        ]
    }

service = build('admin', 'datatransfer_v1', credentials=creds)
results = service.transfers().insert(body=datatransfer).execute()
print(results)

To get the user's Id's I'm first using the Directory API to query all users who are suspended, and getting their ID from that. Then passing their ID into this to transfer their files to another user before deleting them.