命名空间:microsoft.graph
重要
Microsoft Graph /beta 版本下的 API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建新的 SharePoint 网站。
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
| 权限类型 |
最低特权权限 |
更高特权权限 |
| 委派(工作或学校帐户) |
Sites.Create.All |
Sites.FullControl.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
不支持。 |
| 应用程序 |
Sites.Create.All |
Sites.FullControl.All |
HTTP 请求
POST /sites
| 名称 |
说明 |
| Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
| Content-Type |
application/json. 必需。 |
请求正文
在请求正文中,提供 站点 对象的 JSON 表示形式。
创建 网站时,可以指定以下属性。
| 属性 |
类型 |
说明 |
| 说明 |
String |
网站的描述性文本。 继承自 baseItem。 |
| 区域设置 |
String |
网站的语言设置。 |
| name |
String |
站点的名称。 继承自 baseItem。 可选。 |
| ownerIdentityToResolve |
identityInput |
仅在创建网站时提供的网站所有者。 可选。 |
| shareByEmailEnabled |
布尔值 |
确定是否可以通过电子邮件共享网站及其内容。 可选。 |
| template |
siteTemplateType |
指定应用于网站的模板。 可能的值包括 sitepagepublishing、group、sts、unknownFutureValue。 可选。 |
| webUrl |
String |
只能在创建网站时提供的网站 URL。 继承自 baseItem。 可选。 |
响应
如果成功,此方法在 202 Created 响应正文中返回响应代码和 站点 对象。 响应还包含一个 Location 标头,其中包含为处理网站创建作而创建的 getOperationStatus 的位置。 通过对此位置发出 GET 请求来检查创建作的状态。
示例
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/beta/sites
Content-Type: application/json
{
"name": "Communication Site Test",
"webUrl": "https://contoso.sharepoint.com/sites/commsite1",
"locale": "en-US",
"shareByEmailEnabled": false,
"description": "Test Site Description",
"template": "sitepagepublishing",
"ownerIdentityToResolve": {
"email": "ryan@contoso.com"
}
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Beta.Models;
var requestBody = new Site
{
Name = "Communication Site Test",
WebUrl = "https://contoso.sharepoint.com/sites/commsite1",
Locale = "en-US",
ShareByEmailEnabled = false,
Description = "Test Site Description",
Template = SiteTemplateType.Sitepagepublishing,
OwnerIdentityToResolve = new IdentityInput
{
Email = "ryan@contoso.com",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Sites.PostAsync(requestBody);
// Code snippets are only available for the latest major version. Current major version is $v0.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-beta-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-beta-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewSite()
name := "Communication Site Test"
requestBody.SetName(&name)
webUrl := "https://contoso.sharepoint.com/sites/commsite1"
requestBody.SetWebUrl(&webUrl)
locale := "en-US"
requestBody.SetLocale(&locale)
shareByEmailEnabled := false
requestBody.SetShareByEmailEnabled(&shareByEmailEnabled)
description := "Test Site Description"
requestBody.SetDescription(&description)
template := graphmodels.SITEPAGEPUBLISHING_SITETEMPLATETYPE
requestBody.SetTemplate(&template)
ownerIdentityToResolve := graphmodels.NewIdentityInput()
email := "ryan@contoso.com"
ownerIdentityToResolve.SetEmail(&email)
requestBody.SetOwnerIdentityToResolve(ownerIdentityToResolve)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
sites, err := graphClient.Sites().Post(context.Background(), requestBody, nil)
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
Site site = new Site();
site.setName("Communication Site Test");
site.setWebUrl("https://contoso.sharepoint.com/sites/commsite1");
site.setLocale("en-US");
site.setShareByEmailEnabled(false);
site.setDescription("Test Site Description");
site.setTemplate(SiteTemplateType.Sitepagepublishing);
IdentityInput ownerIdentityToResolve = new IdentityInput();
ownerIdentityToResolve.setEmail("ryan@contoso.com");
site.setOwnerIdentityToResolve(ownerIdentityToResolve);
Site result = graphClient.sites().post(site);
const options = {
authProvider,
};
const client = Client.init(options);
const site = {
name: 'Communication Site Test',
webUrl: 'https://contoso.sharepoint.com/sites/commsite1',
locale: 'en-US',
shareByEmailEnabled: false,
description: 'Test Site Description',
template: 'sitepagepublishing',
ownerIdentityToResolve: {
email: 'ryan@contoso.com'
}
};
await client.api('/sites')
.version('beta')
.post(site);
<?php
use Microsoft\Graph\Beta\GraphServiceClient;
use Microsoft\Graph\Beta\Generated\Models\Site;
use Microsoft\Graph\Beta\Generated\Models\SiteTemplateType;
use Microsoft\Graph\Beta\Generated\Models\IdentityInput;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new Site();
$requestBody->setName('Communication Site Test');
$requestBody->setWebUrl('https://contoso.sharepoint.com/sites/commsite1');
$requestBody->setLocale('en-US');
$requestBody->setShareByEmailEnabled(false);
$requestBody->setDescription('Test Site Description');
$requestBody->setTemplate(new SiteTemplateType('sitepagepublishing'));
$ownerIdentityToResolve = new IdentityInput();
$ownerIdentityToResolve->setEmail('ryan@contoso.com');
$requestBody->setOwnerIdentityToResolve($ownerIdentityToResolve);
$result = $graphServiceClient->sites()->post($requestBody)->wait();
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph_beta import GraphServiceClient
from msgraph_beta.generated.models.site import Site
from msgraph_beta.generated.models.site_template_type import SiteTemplateType
from msgraph_beta.generated.models.identity_input import IdentityInput
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = Site(
name = "Communication Site Test",
web_url = "https://contoso.sharepoint.com/sites/commsite1",
locale = "en-US",
share_by_email_enabled = False,
description = "Test Site Description",
template = SiteTemplateType.Sitepagepublishing,
owner_identity_to_resolve = IdentityInput(
email = "ryan@contoso.com",
),
)
result = await graph_client.sites.post(request_body)
响应
以下示例显示了相应的响应。
HTTP/1.1 202 Accepted
Location: https://graph.microsoft.com/beta/sites/getOperationStatus(operationId='JXMnaHR0cHMlM0ElMkYlMkZncmFwaC5taWNyb3NvZnQuY29tJTJGc2l0ZXMlMkZ0ZWFtc2l0ZTE=')