|
1 | 1 | <?php |
2 | 2 |
|
3 | | -require_once __DIR__ . '../../vendor/autoload.php'; |
4 | | -$settings = include(__DIR__ . '../../../tests/Settings.php'); |
| 3 | +require_once __DIR__ . '/../../vendor/autoload.php'; |
| 4 | +$settings = include(__DIR__ . '/../../../tests/Settings.php'); |
5 | 5 |
|
6 | 6 | use Office365\Runtime\Auth\ClientCredential; |
7 | | -use Office365\Runtime\Http\RequestOptions; |
8 | 7 | use Office365\SharePoint\ClientContext; |
| 8 | +use Office365\SharePoint\Portal\SPSiteManager; |
9 | 9 |
|
10 | 10 | try { |
11 | 11 | $credentials = new ClientCredential($settings['ClientId'], $settings['ClientSecret']); |
12 | 12 | $ctx = (new ClientContext($settings['Url']))->withCredentials($credentials); |
13 | 13 |
|
14 | | - $url = "{$ctx->getBaseUrl()}/_api/SPSiteManager/create"; |
15 | | - $request = new RequestOptions($url); |
16 | | - $payload = array( |
17 | | - "request" => array( |
18 | | - "Title" => "Communication Site 1", |
19 | | - "Url" => "{$ctx->getBaseUrl()}/sites/commsite2", |
20 | | - "Lcid" => 1033, |
21 | | - "ShareByEmailEnabled" => false, |
22 | | - "Classification" => "Low Business Impact", |
23 | | - "Description" => "Description", |
24 | | - "WebTemplate" => "SITEPAGEPUBLISHING#0", |
25 | | - "SiteDesignId" => "6142d2a0-63a5-4ba0-aede-d9fefca2c767", |
26 | | - "Owner" => $settings['TestAccounts'][0] |
27 | | - ) |
28 | | - ); |
29 | | - $request->Data = json_encode($payload); |
30 | | - $resp = $ctx->getPendingRequest()->executeQueryDirect($request); |
31 | | - $json = json_decode($resp->getContent(), true); |
32 | | - print("Site has been created: {$json["d"]["Create"]["SiteUrl"]} \n"); |
| 14 | + $siteManager = new SPSiteManager($ctx); |
| 15 | + //create communications site |
| 16 | + //refer https://docs.microsoft.com/en-us/sharepoint/dev/apis/site-creation-rest for docs |
| 17 | + $result = $siteManager->create("commsite127", $settings['TestAccountName'], "Low Business Impact"); |
| 18 | + $siteManager->executeQuery(); |
| 19 | + print("Site has been created: {$result->getValue()->SiteUrl} \n"); |
33 | 20 | } |
34 | 21 | catch (Exception $e) { |
35 | 22 | echo 'Failed: ', $e->getMessage(), "\n"; |
|
0 commit comments