I'm trying to move a file that I uploaded separately to Google Drive from one folder to another.
When I do:
my $url = 'https://www.googleapis.com/drive/v3/files/' . $id;
my $tx = $ua->patch(
$url,
json => {
addParents => '0ByFk4UawESNUcEhWdjBWTVRXZ1E',
}
);
The name of the file is changed, but the parent folder (which is the root folder for my Google Drive) is still the same.
I am doing something wrong for sure, but what?
My client is a Mojo::UserAgent
object, but it doesn't seem to matter much. Everything else works OK.
I am aware of similar questions for other languages such as this one but they don't seem to translate well for me.
The addParents
and removeParents
must be added as parameters, not in the JSON payload.
This works:
my $url = Mojo::URL->new('https://www.googleapis.com/drive/v3/files/fileID');
$url->query({ addParents => 'parentIdToBeAdded',
removeParents => 'parentIdToBeRemoved' });
my $tx = $ua->patch($url, json => { modifiedTime => '2017-06-04T10:00:00-02:00' });
Some other - as in the request above - are added in the JSON body.
Basically anything that in the documentation is under 'Required query parameters' and 'Optional query parameters' goes in as query, 'Optional Properties' go in the JSON request body.