Reputation: 439
When I'm trying to copy a Docs file from a template I have, I set the parents in the request body like so:
dummy_id = '17OGNsO6prLwjtaeVbfgQv41ogtrAawDqvPUOSm4B9bk'
target_folder_id = '0ALbScsczry1nUi9PVA'
file_metadata = {
'name': 'Test Project Quote',
'parents': [{'id': target_folder_id}] # This is where you set the target folder
}
test_file = self.drive_service.files().copy(fileId=dummy_id,
body=file_metadata,
supportsAllDrives=True, # TODO this is deprecated
fields='id,parents').execute()
However, it doesn't seem to create the copy in this folder but just performs the default operation of creating the copy in the same drive as the original - it inherits the parents. The odd thing is that this did seem to work once, but not every time. Is there something obviously wrong with the above? (I jumbled up the IDs)
Upvotes: 0
Views: 398
Reputation: 26836
Replace
'parents': [{'id': target_folder_id}]
by
'parents': [target_folder_id]
The variable parents
expects simply an array of 1 or more parent ids (comma separated), not a key - value object.
Upvotes: 2