msgraph-sdk-php
msgraph-sdk-php copied to clipboard
Batch Request Support
I'm trying to convert my application to the new fluent API. I specifically want to download profile photos for all the users in my organization, and was able to do individual photos using
$photoContent = $this->graphServiceClient->usersById($user->id)->photo()->content()->get()->wait();
But in previous versions I could make an array of requests and send them all at once like
$data = $this->graph
->createRequest('POST', '/$batch')
->attachBody(json_encode(['requests' => $requests]))
->execute();
I can't for the life of me figure out how to do this now. Is this even possible with the fluent API? I am tempted to go back to the old API and lock my composer.json at msgraph-sdk-php RC4 so my old code works.
Any advice on how I could approach this would be appreciated!
Originally posted by @jdlien in https://github.com/microsoftgraph/msgraph-sdk-php/issues/951#issuecomment-1198775010
We are yet to provide batch request support via the fluent API in 2.0-RC5.
However, in the meantime you can create a Graph-configured guzzle client and configure batch requests on the guzzle client.
There is a limitation however that you'll be unable to leverage the models provided i.e. serializing models to the request payload or deserialization.
$guzzleClient = GraphClientFactory::create();
$response = $guzzleClient->post('/$batch', ...);
Refer to the Guzzle docs on how to add the request body, headers etc