Create agreement
Article
03/10/2022
3 minutes to read
2 contributors
In this article
Namespace: microsoft.graph
Create a new agreement object.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
Agreement.ReadWrite.All
Delegated (personal Microsoft account)
Not supported.
Application
Not supported.
HTTP request
POST /identityGovernance/termsOfUse/agreements
Name
Description
Authorization
Bearer {token}. Required.
Content-type
application/json. Required.
Request body
In the request body, supply a JSON representation of an agreement object.
The following table shows the properties that are required when you create an agreement.
Property
Type
Description
displayName
String
Display name of the agreement.
isViewingBeforeAcceptanceRequired
Boolean
Indicates whether the user has to expand and view the agreement before accepting.
fileName
String
Name of the agreement file (for example, TOU.pdf).
isDefault
Boolean
Indicates whether this is the default agreement file if the language matches the client preference. If none of the files are marked as default, the first one is treated as default.
language
String
The language of the agreement file in the format "languagecode2-country/regioncode2". "languagecode2" is a lowercase two-letter code derived from ISO 639-1, while "country/regioncode2" is derived from ISO 3166 and usually consists of two uppercase letters, or a BCP-47 language tag. For example, U.S. English is en-US
.
data
Binary
Data that represents the terms of use for the PDF document.
Response
If successful, this method returns a 201, Created
response code and an agreement object in the response body.
Example
Request
In the request body, supply a JSON representation of the agreement object.
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);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
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);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
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];
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
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);
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
//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)
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
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
Read the SDK documentation for details on how to add the SDK to your project and create an authProvider instance.
Response
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-type: application/json
{
"displayName": "MSGraph Sample",
"isViewingBeforeAcceptanceRequired": true,
"id": "093b947f-8363-4979-a47d-4c52b33ee1be"
}