|
| 1 | +## 1. LIST ALL GROUPS IN THE TENANT (GET /groups) |
| 2 | + |
| 3 | +```php |
| 4 | +$graphServiceClient = new GraphServiceClient($tokenRequestContext); |
| 5 | + |
| 6 | +try { |
| 7 | + $groups = $graphServiceClient->groups()->get()->wait(); |
| 8 | + if ($groups && $groups->getValue()) { |
| 9 | + foreach ($groups->getValue() as $group) { |
| 10 | + echo "Group ID: {$group->getId()}<br>"; |
| 11 | + echo "Group Display Name: {$group->getDisplayName()}<br><br>"; |
| 12 | + } |
| 13 | + } |
| 14 | +} catch (ApiException $ex) { |
| 15 | + echo "Error: " . $ex->getResponseStatusCode() . "\n"; |
| 16 | + echo "Error: " .$ex->getError()->getMessage();"; |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +## 2. GET A SPECIFIC GROUP (GET /groups/{id}) |
| 21 | + |
| 22 | + |
| 23 | +```php |
| 24 | + |
| 25 | +$graphServiceClient = new GraphServiceClient($tokenRequestContext); |
| 26 | + |
| 27 | +$groupId = "<Group-ID>"; |
| 28 | + |
| 29 | +try { |
| 30 | + $group = $graphServiceClient->groups()->byGroupId($groupId)->get()->wait(); |
| 31 | + if ($group) { |
| 32 | + echo "Group ID: {$group->getId()}<br>"; |
| 33 | + echo "Group Display Name: {$group->getDisplayName()}<br>"; |
| 34 | + echo "Group Description: {$group->getDescription()}<br>"; |
| 35 | + echo "Group Types: " . json_encode($group->getGroupTypes()) . "<br>"; |
| 36 | + echo "Security Enabled: " . ($group->getSecurityEnabled() ? 'true' : 'false') . "<br>"; |
| 37 | + } |
| 38 | +} catch (ApiException $ex) { |
| 39 | + echo "Error: " . $ex->getResponseStatusCode() . "\n"; |
| 40 | + echo "Error: " . $ex->getError()->getMessage();"; |
| 41 | +} |
| 42 | +``` |
| 43 | + |
| 44 | +## 3. LIST ALL MEMBERS IN A GROUP (GET /groups/{id}/members) |
| 45 | + |
| 46 | +```php |
| 47 | +$graphServiceClient = new GraphServiceClient($tokenRequestContext); |
| 48 | + |
| 49 | +$groupId = "<GROUP-ID>"; |
| 50 | + |
| 51 | +try { |
| 52 | + $members = $graphServiceClient->groups()->byGroupId($groupId)->members()->get()->wait(); |
| 53 | + if ($members && $members->getValue()) { |
| 54 | + foreach ($members->getValue() as $member) { |
| 55 | + $user = $graphServiceClient->users()->byUserId($member->getId())->get()->wait(); |
| 56 | + if ($user) { |
| 57 | + echo "User Display Name: {$user->getDisplayName()}<br>"; |
| 58 | + echo "User Mail: {$user->getMail()}<br><br>"; |
| 59 | + } |
| 60 | + } |
| 61 | + } |
| 62 | +} catch (ApiException $ex) { |
| 63 | + echo "Error: " . $ex->getResponseStatusCode() . "\n"; |
| 64 | + echo "Error: " .$ex->getError()->getMessage();"; |
| 65 | +} |
| 66 | +``` |
| 67 | + |
| 68 | +## 4. LIST A GROUP TEAM SHAREPOINT SITES (GET /groups/{id}/sites) |
| 69 | +```php |
| 70 | +$graphServiceClient = new GraphServiceClient($tokenRequestContext); |
| 71 | + |
| 72 | +$groupId = "<GROUP-ID>c"; |
| 73 | + |
| 74 | +try { |
| 75 | + $sites = $graphServiceClient->groups()->byGroupId($groupId)->sites()->get()->wait(); |
| 76 | + if ($sites && $sites->getValue()) { |
| 77 | + foreach ($sites->getValue() as $site) { |
| 78 | + echo "Site ID: {$site->getId()}<br>"; |
| 79 | + echo "Site Web URL: {$site->getWebUrl()}<br><br>"; |
| 80 | + } |
| 81 | + } |
| 82 | +} catch (ApiException $ex) { |
| 83 | + echo "Error: " . $ex->getResponseStatusCode() . "\n"; |
| 84 | + echo "Error: " .$ex->getError()->getMessage();"; |
| 85 | +} |
| 86 | +``` |
| 87 | + |
| 88 | + |
| 89 | +## 5. LIST A GROUP'S TRANSITIVE MEMBERS (GET /groups/{id}/transitiveMembers) |
| 90 | + |
| 91 | +```php |
| 92 | +$graphServiceClient = new GraphServiceClient($tokenRequestContext); |
| 93 | + |
| 94 | +$groupId = "<GROUP-ID>"; |
| 95 | +try { |
| 96 | + $members = $graphServiceClient->groups()->byGroupId($groupId)->transitiveMembers()->get()->wait(); |
| 97 | + if ($members && $members->getValue()) { |
| 98 | + foreach ($members->getValue() as $member) { |
| 99 | + $obj = $graphServiceClient->directoryObjects()->byDirectoryObjectId($member->getId())->get()->wait(); |
| 100 | + if ($obj && $obj->getOdataType() === '#microsoft.graph.user') { |
| 101 | + $user = $graphServiceClient->users()->byUserId($obj->getId())->get()->wait(); |
| 102 | + if ($user) { |
| 103 | + echo "User ID: {$user->getId()}<br>"; |
| 104 | + echo "User Display Name: {$user->getDisplayName()}<br>"; |
| 105 | + echo "User Mail: {$user->getMail()}<br><br>"; |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + } |
| 110 | +} catch (ApiException $ex) { |
| 111 | + echo "Error: " . $ex->getResponseStatusCode() . "\n"; |
| 112 | + echo "Error: " .$ex->getError()->getMessage();"; |
| 113 | +} |
| 114 | +``` |
| 115 | + |
| 116 | +## 6. LIST ALL GROUP DRIVES (GET /groups/{id}/drives) |
| 117 | + |
| 118 | +```php |
| 119 | + |
| 120 | +$graphServiceClient = new GraphServiceClient($tokenRequestContext); |
| 121 | + |
| 122 | +$groupId = "<GROUP-ID>"; |
| 123 | + |
| 124 | +try { |
| 125 | + $drives = $graphServiceClient->groups()->byGroupId($groupId)->drives()->get()->wait(); |
| 126 | + if ($drives && $drives->getValue()) { |
| 127 | + foreach ($drives->getValue() as $drive) { |
| 128 | + echo "Drive ID: {$drive->getId()}<br>"; |
| 129 | + echo "Drive Name: {$drive->getName()}<br><br>"; |
| 130 | + } |
| 131 | + } |
| 132 | +} catch (ApiException $ex) { |
| 133 | + echo "Error: " . $ex->getResponseStatusCode() . "\n"; |
| 134 | + echo "Error: " .$ex->getError()->getMessage();"; |
| 135 | +} |
| 136 | +``` |
| 137 | + |
| 138 | +## 7. GET A GROUP DRIVE (GET /groups/{id}/drives/{id}) |
| 139 | +```php |
| 140 | +$graphServiceClient = new GraphServiceClient($tokenRequestContext); |
| 141 | + |
| 142 | +$groupId = "<GROUP-ID>"; |
| 143 | +$driveId = "<DRIVE-ID>"; |
| 144 | + |
| 145 | +try { |
| 146 | + $drive = $graphServiceClient->groups()->byGroupId($groupId)->drives()->byDriveId($driveId)->get()->wait(); |
| 147 | + if ($drive) { |
| 148 | + echo "Drive ID: {$drive->getId()}<br>"; |
| 149 | + echo "Drive Type: {$drive->getDriveType()}<br>"; |
| 150 | + echo "Drive Name: {$drive->getName()}<br>"; |
| 151 | + echo "Drive Web URL: {$drive->getWebUrl()}<br>"; |
| 152 | + echo "Drive Items: " . json_encode($drive->getItems()) . "<br><br>"; |
| 153 | + } |
| 154 | +} catch (ApiException $ex) { |
| 155 | + echo $ex->getError()->getMessage(); |
| 156 | +} |
| 157 | +``` |
0 commit comments