google-api-php-client icon indicating copy to clipboard operation
google-api-php-client copied to clipboard

After migrating to new batch endpoint, batches stopped working

Open bramcou opened this issue 6 years ago • 4 comments

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

  1. 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.

  2. 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.

response.zip

I tried diving into the Guzzle request and the Google Batch but couldn't figure it out. Any help would be greatly appreciated!

bramcou avatar Aug 17 '20 13:08 bramcou

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.

kirankarnati avatar Aug 27 '20 20:08 kirankarnati

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 .

bramcou avatar Aug 30 '20 21:08 bramcou

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?

acmwallace avatar Oct 05 '20 18:10 acmwallace

Greetings, we're closing this. Looks like the issue got resolved. Please let us know if the issue needs to be reopened.

fhinkel avatar Dec 08 '20 10:12 fhinkel