Skip to content

Version 2.5.0

Compare
Choose a tag to compare
@vgrem vgrem released this 15 May 19:52
· 113 commits to master since this release

Changelog

  • introduced a support for Teams API
  • performance improvements and better support for Fluent API syntax
  • introduced ClientRuntimeContext.executeQueryRetry method to submit queries which supports transparently retrying a failed operation (retry pattern)

Working with Teams API

Example: create a Team

The following is an example of a minimal request to create a Team (via delegated permissions)

use Office365\GraphServiceClient;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\UserCredentials;

function acquireToken()
{
    $tenant = "{tenant}.onmicrosoft.com";
    $resource = "https://graph.microsoft.com";
  
    $provider = new AADTokenProvider($tenant);
    return $provider->acquireTokenForPassword($resource, "{clientId}",
        new UserCredentials("{UserName}", "{Password}"));
}

$client = new GraphServiceClient("acquireToken");
$teamName = "My Sample Team";
$newTeam = $client->getTeams()->add($teamName)->executeQuery();

Example: list all Teams

use Office365\GraphServiceClient;
use Office365\Runtime\Auth\AADTokenProvider;
use Office365\Runtime\Auth\UserCredentials;

function acquireToken()
{
    $tenant = "{tenant}.onmicrosoft.com";
    $resource = "https://graph.microsoft.com";
  
    $provider = new AADTokenProvider($tenant);
    return $provider->acquireTokenForPassword($resource, "{clientId}",
        new UserCredentials("{UserName}", "{Password}"));
}

$client = new GraphServiceClient("acquireToken");
$teams = $client->getTeams()->getAll(array("displayName"))->executeQuery();

ClientRuntimeContext.executeQueryRetry method usage

Once Team is created, it might not be immediately available due to replication delay and calling getting team endpoint could fail with a 404 error, the recommended pattern is to retry the get team call three times, with a 10 second delay between calls:

$team = $graphClient->getTeams()->getById($Id)->get()->executeQueryRetry();