创建协议
命名空间:microsoft.graph
创建新的 协议 对象。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
Agreement.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
不支持。 |
HTTP 请求
POST /identityGovernance/termsOfUse/agreements
| 名称 |
说明 |
| Authorization |
持有者 {token}。必需。 |
| Content-type |
application/json. Required. |
请求正文
在请求正文中,提供协议对象的 JSON 表示 形式。
下表显示创建协议时所需的属性。
| 属性 |
类型 |
说明 |
| displayName |
字符串 |
协议的显示名称。 |
| isViewingBeforeAcceptanceRequired |
布尔值 |
指示用户在接受之前是否必须展开和查看协议。 |
| fileName |
String |
协议文件的名称 (例如,TOU.pdf) 。 |
| isDefault |
Boolean |
指示如果语言与客户端首选项匹配,这是否是默认协议文件。 如果未将任何文件标记为默认文件,则第一个文件将被视为默认文件。 |
| language |
String |
协议文件的语言,格式为"languagecode2-country/regioncode2"。 "languagecode2"是派生自 ISO 639-1 的两个字母小写代码,而"country/regioncode2"派生自 ISO 3166,通常包含两个小写字母或 BCP-47 语言标记。 例如,美国英语为 en-US。 |
| data |
Binary |
表示 PDF 文档的使用条款的数据。 |
响应
如果成功,此方法在响应201, Created正文中返回 响应代码和 agreement 对象。
示例
请求
在请求正文中,提供协议对象的 JSON 表示 形式。
POST https://graph.microsoft.com/v1.0/identityGovernance/termsOfUse/agreements
Content-type: application/json
{
"displayName": "Contoso ToU for guest users",
"isViewingBeforeAcceptanceRequired": true,
"files": [
{
"fileName": "TOU.pdf",
"language": "en",
"isDefault": true,
"fileData": {
"data": "SGVsbG8gd29ybGQ=//truncated-binary"
}
}
]
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var agreement = new Agreement
{
DisplayName = "Contoso ToU for guest users",
IsViewingBeforeAcceptanceRequired = true,
Files = new AgreementFilesCollectionPage()
{
new AgreementFileLocalization
{
FileName = "TOU.pdf",
Language = "en",
IsDefault = true,
FileData = new AgreementFileData
{
Data = Convert.FromBase64String("SGVsbG8gd29ybGQ=//truncated-binary")
}
}
}
};
await graphClient.IdentityGovernance.TermsOfUse.Agreements
.Request()
.AddAsync(agreement);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const agreement = {
displayName: 'Contoso ToU for guest users',
isViewingBeforeAcceptanceRequired: true,
files: [
{
fileName: 'TOU.pdf',
language: 'en',
isDefault: true,
fileData: {
data: 'SGVsbG8gd29ybGQ=//truncated-binary'
}
}
]
};
await client.api('/identityGovernance/termsOfUse/agreements')
.post(agreement);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/identityGovernance/termsOfUse/agreements"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphAgreement *agreement = [[MSGraphAgreement alloc] init];
[agreement setDisplayName:@"Contoso ToU for guest users"];
[agreement setIsViewingBeforeAcceptanceRequired: true];
NSMutableArray *filesList = [[NSMutableArray alloc] init];
MSGraphAgreementFileLocalization *files = [[MSGraphAgreementFileLocalization alloc] init];
[files setFileName:@"TOU.pdf"];
[files setLanguage:@"en"];
[files setIsDefault: true];
MSGraphAgreementFileData *fileData = [[MSGraphAgreementFileData alloc] init];
[fileData setData:@"SGVsbG8gd29ybGQ=//truncated-binary"];
[files setFileData:fileData];
[filesList addObject: files];
[agreement setFiles:filesList];
NSError *error;
NSData *agreementData = [agreement getSerializedDataWithError:&error];
[urlRequest setHTTPBody:agreementData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
Agreement agreement = new Agreement();
agreement.displayName = "Contoso ToU for guest users";
agreement.isViewingBeforeAcceptanceRequired = true;
LinkedList<AgreementFileLocalization> filesList = new LinkedList<AgreementFileLocalization>();
AgreementFileLocalization files = new AgreementFileLocalization();
files.fileName = "TOU.pdf";
files.language = "en";
files.isDefault = true;
AgreementFileData fileData = new AgreementFileData();
fileData.data = Base64.getDecoder().decode("SGVsbG8gd29ybGQ=//truncated-binary");
files.fileData = fileData;
filesList.add(files);
AgreementFileLocalizationCollectionResponse agreementFileLocalizationCollectionResponse = new AgreementFileLocalizationCollectionResponse();
agreementFileLocalizationCollectionResponse.value = filesList;
AgreementFileLocalizationCollectionPage agreementFileLocalizationCollectionPage = new AgreementFileLocalizationCollectionPage(agreementFileLocalizationCollectionResponse, null);
agreement.files = agreementFileLocalizationCollectionPage;
graphClient.identityGovernance().termsOfUse().agreements()
.buildRequest()
.post(agreement);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewAgreement()
displayName := "Contoso ToU for guest users"
requestBody.SetDisplayName(&displayName)
isViewingBeforeAcceptanceRequired := true
requestBody.SetIsViewingBeforeAcceptanceRequired(&isViewingBeforeAcceptanceRequired)
requestBody.SetFiles( []AgreementFileLocalization {
msgraphsdk.NewAgreementFileLocalization(),
SetAdditionalData(map[string]interface{}{
"fileName": "TOU.pdf",
"language": "en",
"isDefault": true,
}
}
result, err := graphClient.IdentityGovernance().TermsOfUse().Agreements().Post(requestBody)
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Identity.Governance
$params = @{
DisplayName = "Contoso ToU for guest users"
IsViewingBeforeAcceptanceRequired = $true
Files = @(
@{
FileName = "TOU.pdf"
Language = "en"
IsDefault = $true
FileData = @{
Data = [System.Text.Encoding]::ASCII.GetBytes("SGVsbG8gd29ybGQ=//truncated-binary")
}
}
)
}
New-MgIdentityGovernanceTermOfUseAgreement -BodyParameter $params
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档。
响应
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"displayName": "MSGraph Sample",
"isViewingBeforeAcceptanceRequired": true,
"id": "093b947f-8363-4979-a47d-4c52b33ee1be"
}