After migrating to new batch endpoint, batches stopped working
Environment details
- OS: Linux 4.9.0-13-amd64
- PHP version: 7.3.20
- Package name and version: google/apiclient v.2.7.0
Steps to reproduce
-
Setup a batch request, in my case to the Directory API, and execute the batch. I used the following example to create my code 2 years ago: https://github.com/googleapis/google-api-php-client/blob/master/examples/batch.php succesfully which worked until the global batch http endpoints were changed to their specific API's. I updated the endpoint in accordance with the Google blog post but no joy.
-
When I run the requests individually they do work.
Code example
//get the Google client
$this->google_client = Google::authenticate()->getClient();
//create a new Google directory service
$this->google_directory = Google::make('directory');
//5. Start a batch
//turn batch mode on
$this->google_client->setUseBatch(true);
//create a batch
$batch = new Google_Http_Batch($this->google_client, false, null, 'batch/directory/v1');
//6. Make a request for each email address to be removed
foreach ($email_addresses_to_remove as $email) {
//make a request
$request = $this->google_directory->members->delete($address, $email);
//add the request to the batch
$batch->add($request);
}
//7. Make a request for each email address to be added
foreach ($email_addresses_to_add as $email) {
//create a member
$group_member = new Google_Service_Directory_Member;
$group_member->setEmail($email);
$group_member->setRole('MEMBER');
$group_member->setType('EXTERNAL');
//make a request
$request = $this->google_directory->members->insert($address, $group_member);
//add the request to the batch
$batch->add($request);
}
//8. Execute the batch
$batch->execute();
//9. Stop batch mode
$this->google_client->setUseBatch(false);
The request produces no errors, doesn't throw exceptions. I have included a dump from the batch object, cleared of identity data.
I tried diving into the Guzzle request and the Google Batch but couldn't figure it out. Any help would be greatly appreciated!
batch/directory/v1 is probably not the correct endpoint. try batch/admin/directory_v1 coz that's what I see in Google_Service_Directory class.
That works indeed! Thanks. I did try other batch endpoints which returned errors but the one I had been using up to now did not return an error for invalid batchpoint. That might be useful. But either way, thanks a lot! Simple solution (-:
On Thu, Aug 27, 2020 at 10:59 PM Kiran Karnati [email protected] wrote:
batch/directory/v1 is probably not the correct endpoint. try batch/admin/directory_v1 coz that's what I see in Google_Service_Directory class.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/googleapis/google-api-php-client/issues/1910#issuecomment-682187598, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFAFN2LGMZABJF6QPGXOMG3SC3CLHANCNFSM4QBUWP3A .
Looking at the latest CloudStorageClient code (https://github.com/GoogleCloudPlatform/google-cloud-php/blob/v0.122.0/Storage/src/StorageClient.php#L91), there is no "setUseBatch" function. Is batching not supported in the new version, or is this function not necessary anymore?
Greetings, we're closing this. Looks like the issue got resolved. Please let us know if the issue needs to be reopened.