Skip to content

Commit a0e5e6d

Browse files
shemogumbebaywet
authored andcommitted
update samples for drives, groups, applications and sharepoint
1 parent 1eaeead commit a0e5e6d

File tree

4 files changed

+404
-0
lines changed

4 files changed

+404
-0
lines changed

docs/application_samples.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
## List all applications in a tenant
2+
3+
```php
4+
5+
6+
7+
// Create a new GraphServiceClient instance
8+
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
9+
10+
try {
11+
$applications = $graphServiceClient->applications()->get()->wait();
12+
if ($applications && $applications->getValue()) {
13+
foreach ($applications->getValue() as $app) {
14+
echo "Application ID: {$app->getId()}<br>";
15+
}
16+
}
17+
} catch (ApiException $ex) {
18+
echo "Error: " . $ex->getResponseStatusCode() . "\n";
19+
echo "Error: " .$ex->getError()->getMessage();";
20+
}
21+
```

docs/drives_samples.md

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
2+
## 1. LIST ALL DRIVES (GET /drives)
3+
4+
```php
5+
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
6+
7+
try {
8+
$drives = $graphServiceClient->drives()->get()->wait();
9+
if ($drives && $drives->getValue()) {
10+
foreach ($drives->getValue() as $drive) {
11+
echo "Drive ID: {$drive->getId()}<br>";
12+
echo "Drive Type: {$drive->getDriveType()}<br>";
13+
echo "Drive Name: {$drive->getName()}<br>";
14+
echo "Drive Description: {$drive->getDescription()}<br>";
15+
echo "Drive Web URL: {$drive->getWebUrl()}<br><br>";
16+
}
17+
}
18+
} catch (ApiException $ex) {
19+
echo "Error: " . $ex->getResponseStatusCode() . "\n";
20+
echo "Error: " .$ex->getError()->getMessage();";
21+
}
22+
```
23+
24+
## 2. GET DRIVE BY ID (GET /drives/{id})
25+
26+
```php
27+
$driveId = "DRIVE-ID";
28+
29+
try {
30+
$drive = $graphServiceClient->drives()->byDriveId($driveId)->get()->wait();
31+
if ($drive) {
32+
echo "Drive ID: {$drive->getId()}<br>";
33+
echo "Drive Type: {$drive->getDriveType()}<br>";
34+
echo "Drive Name: {$drive->getName()}<br>";
35+
echo "Drive Description: {$drive->getDescription()}<br>";
36+
echo "Drive Web URL: {$drive->getWebUrl()}<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 THE ITEMS IN A DRIVE (GET /drives/{id}/items)
45+
```php
46+
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
47+
48+
$driveId = "DRIVE-ID";
49+
50+
try {
51+
$requestConfig = new ItemsRequestBuilderGetRequestConfiguration();
52+
$requestConfig->queryParameters = ItemsRequestBuilderGetRequestConfiguration::createQueryParameters();
53+
$requestConfig->queryParameters->filter = "startswith(name, 'B')";
54+
55+
$items = $graphServiceClient->drives()->byDriveId($driveId)->items()->get($requestConfig)->wait();
56+
if ($items && $items->getValue()) {
57+
foreach ($items->getValue() as $item) {
58+
echo "Item ID: {$item->getId()}<br>";
59+
echo "Item Name: {$item->getName()}<br>";
60+
echo "Item Size: {$item->getSize()}<br>";
61+
echo "Item Folder: " . json_encode($item->getFolder()) . "<br>";
62+
echo "Item File: " . json_encode($item->getFile()) . "<br><br>";
63+
}
64+
}
65+
} catch (ApiException $ex) {
66+
echo "Error: " . $ex->getResponseStatusCode() . "\n";
67+
echo "Error: " .$ex->getError()->getMessage();";
68+
}
69+
```
70+
71+
## 4. GET AN ITEM IN THE DRIVE (GET /drives/{id}/items/{id})
72+
73+
```php
74+
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
75+
76+
$driveId = "DRIVE-ID";
77+
78+
try {
79+
$items = $graphServiceClient->drives()->byDriveId($driveId)->items()->get()->wait();
80+
if ($items && $items->getValue()) {
81+
foreach ($items->getValue() as $item) {
82+
echo "Item ID: {$item->getId()}<br>";
83+
echo "Item Name: {$item->getName()}<br>";
84+
echo "Item Size: {$item->getSize()}<br>";
85+
echo "Item Folder: " . json_encode($item->getFolder()) . "<br>";
86+
echo "Item File: " . json_encode($item->getFile()) . "<br><br>";
87+
}
88+
}
89+
} catch (ApiException $ex) {
90+
echo "Error: " . $ex->getResponseStatusCode() . "\n";
91+
echo "Error: " .$ex->getError()->getMessage();";
92+
}
93+
```
94+
95+
## 5. GET THE ROOT FOLDER OF THE DRIVE (GET /drives/{id}/root)
96+
```php
97+
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
98+
99+
$driveId = "DRIVE-ID"; // Replace with the actual drive ID
100+
101+
try {
102+
$root = $graphServiceClient->drives()->byDriveId($driveId)->root()->get()->wait();
103+
if ($root) {
104+
echo "Root ID: {$root->getId()}<br>";
105+
echo "Root Name: {$root->getName()}<br>";
106+
echo "Folder Child Count: " . ($root->getFolder() ? $root->getFolder()->getChildCount() : 'N/A') . "<br>";
107+
echo "Root: " . json_encode($root->getRoot()) . "<br>";
108+
echo "Root Size: {$root->getSize()}<br>";
109+
}
110+
} catch (ApiException $ex) {
111+
echo "Error: " . $ex->getResponseStatusCode() . "\n";
112+
echo "Error: " .$ex->getError()->getMessage();";
113+
}
114+
```
115+
116+
## 6. GET ITEMS IN THE ROOT FOLDER OF THE DRIVE (GET drives/{id}/items/root/children)
117+
```php
118+
$graphServiceClient = new GraphServiceClient($tokenRequestContext);
119+
120+
$driveId = "DRIVE-ID";
121+
122+
try {
123+
$items = $graphServiceClient->drives()->byDriveId($driveId)->items()->byDriveItemId('root')->children()->get()->wait();
124+
if ($items && $items->getValue()) {
125+
foreach ($items->getValue() as $item) {
126+
echo "Item ID: {$item->getId()}<br>";
127+
echo "Item Name: {$item->getName()}<br>";
128+
echo "Item Size: {$item->getSize()}<br>";
129+
echo "Item Folder: " . json_encode($item->getFolder()) . "<br>";
130+
echo "Item File: " . json_encode($item->getFile()) . "<br><br>";
131+
}
132+
}
133+
} catch (ApiException $ex) {
134+
echo "Error: " . $ex->getResponseStatusCode() . "\n";
135+
echo "Error: " .$ex->getError()->getMessage();";
136+
}
137+
```

docs/groups_samples.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
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

Comments
 (0)