Create an open extension (openTypeExtension object) and add custom properties in a new or existing instance of a resource. You can create an open extension in a resource instance and store custom data to it all in the same operation, except for specific resources. See known limitations of open extensions for more information.
The table in the Permissions section lists the resources that support open extensions.
Note: If you're creating open extensions on Outlook resources, see Outlook-specific considerations in openTypeExtension resource type.
Permissions
Depending on the resource you're creating the extension in and the permission type (delegated or application) requested, the permission specified in the following table is the least privileged required to call this API. To learn more, including taking caution before choosing more privileged permissions, search for the following permissions in Permissions.
Use the same REST request that you use to create the instance.
POST /users/{id|userPrincipalName}/events
POST /users/{id|userPrincipalName}/messages
POST /groups/{id}/events
POST /groups/{id}/threads/{id}/posts/{id}/reply
POST /users/{id|userPrincipalName}/contacts
POST /users/{id|userPrincipalName}/todo/lists/{id}/tasks
POST /users/{id|userPrincipalName}/todo/lists
Note: This syntax shows some common ways to create the supported resource instances. All other POST syntaxes
that allows you to create these resource instances supports creating open extensions in them in a similar way.
See the Request body section about including the properties of the new resource instance and the extension in the request body.
Create an extension in an existing resource instance
Identify the resource instance in the request and do a POST to the extensions navigation property.
POST /devices/{id}/extensions
POST /users/{id|userPrincipalName}/events/{id}/extensions
POST /groups/{id}/extensions
POST /groups/{id}/events/{id}/extensions
POST /groups/{id}/threads/{id}/posts/{id}/extensions
POST /users/{id|userPrincipalName}/messages/{id}/extensions
POST /organization/{id}/extensions
POST /users/{id|userPrincipalName}/contacts/{id}/extensions
POST /users/{id|userPrincipalName}/extensions
POST /users/{id|userPrincipalName}/todo/lists/{id}/tasks/{id}/extensions
POST /users/{id|userPrincipalName}/todo/lists/{id}/extensions
Note: This syntax shows some common ways to identify a resource instance, in order to create an
extension in it. All other syntaxes that allows you to identify these resource instances supports creating open extensions in them in a similar way.
See the Request body section about including the extension in the request body.
Path parameters
Parameter
Type
Description
id
string
A unique identifier for an object in the corresponding collection. Required.
Request headers
Name
Value
Authorization
Bearer {token}. Required.
Content-Type
application/json
Request body
Provide a JSON body of an openTypeExtension, with the following required
name-value pairs, and any additional custom data. The data in the JSON payload can be primitive types, or arrays of
primitive types.
Name
Value
@odata.type
microsoft.graph.openTypeExtension
extensionName
%unique_string%
When creating an extension in a new resource instance, in addition to the
new openTypeExtension object, provide a JSON representation of the relevant properties to create such a resource instance.
Response
Response code
Depending on the operation, the response code can be 201 Created or 202 Accepted.
When you create an extension using the same operation that you use to create a resource instance, the operation returns the same response code that it returns when you use the operation to create the resource instance without the extension.
Refer to the corresponding topics for creating the instance, as listed above.
Response body
Scenario
Resource
Response body
Creating an extension while explicitly creating a new resource instance
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Message();
$requestBody->setSubject('Annual review');
$body = new ItemBody();
$body->setContentType(new BodyType('html'));
$body->setContent('You should be proud!');
$requestBody->setBody($body);
$toRecipientsRecipient1 = new Recipient();
$toRecipientsRecipient1EmailAddress = new EmailAddress();
$toRecipientsRecipient1EmailAddress->setAddress('rufus@contoso.com');
$toRecipientsRecipient1->setEmailAddress($toRecipientsRecipient1EmailAddress);
$toRecipientsArray []= $toRecipientsRecipient1;
$requestBody->setToRecipients($toRecipientsArray);
$extensionsExtension1 = new Extension();
$extensionsExtension1->set@odatatype('microsoft.graph.openTypeExtension');
$additionalData = [
'extensionName' => 'Com.Contoso.Referral',
'companyName' => 'Wingtip Toys',
'expirationDate' => '2015-12-30T11:00:00.000Z',
'dealValue' => 10000,
];
$extensionsExtension1->setAdditionalData($additionalData);
$extensionsArray []= $extensionsExtension1;
$requestBody->setExtensions($extensionsArray);
$requestResult = $graphServiceClient->me()->messages()->post($requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Extension();
$requestBody->set@odatatype('microsoft.graph.openTypeExtension');
$additionalData = [
'extensionName' => 'Com.Contoso.Referral',
'companyName' => 'Wingtip Toys',
'dealValue' => 500050,
'expirationDate' => '2015-12-03T10:00:00.000Z',
];
$requestBody->setAdditionalData($additionalData);
$requestResult = $graphServiceClient->me()->messagesById('message-id')->extensions()->post($requestBody);
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new Extension();
$requestBody->set@odatatype('microsoft.graph.openTypeExtension');
$additionalData = [
'extensionName' => 'Com.Contoso.Deal',
'companyName' => 'Alpine Skis',
'dealValue' => 1010100,
'expirationDate' => '2015-07-03T13:04:00.000Z',
];
$requestBody->setAdditionalData($additionalData);
$requestResult = $graphServiceClient->groupsById('group-id')->eventsById('event-id')->extensions()->post($requestBody);
The fourth example creates an extension in a new group post, using the same reply action call to an existing group post. The reply action
creates a new post, and a new extension embedded in the post. The request body includes a post property, which in turn contains
the body of the new post, and the following data for the new extension:
The type microsoft.graph.openTypeExtension.
The extension name "Com.Contoso.HR".
Additional data to be stored as 3 custom properties in the JSON payload: companyName, expirationDate, and the array of strings topPicks.
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new ReplyPostRequestBody();
$post = new Post();
$postBody = new ItemBody();
$postBody->setContentType(new BodyType('html'));
$postBody->setContent('<html><body><div><div><div><div>When and where? </div></div></div></div></body></html>');
$post->setBody($postBody);
$extensionsExtension1 = new Extension();
$extensionsExtension1->set@odatatype('microsoft.graph.openTypeExtension');
$additionalData = [
'extensionName' => 'Com.Contoso.HR',
'companyName' => 'Contoso',
'expirationDate' => '2015-07-03T13:04:00.000Z',
'topPicks' => ['Employees only', 'Add spouse or guest', 'Add family', ],
];
$extensionsExtension1->setAdditionalData($additionalData);
$extensionsArray []= $extensionsExtension1;
$post->setExtensions($extensionsArray);
$requestBody->setPost($post);
$graphServiceClient->groupsById('group-id')->threadsById('conversationThread-id')->postsById('post-id')->reply()->post($requestBody);
The fifth example creates an extension in a new group post using the same POST operation to create a conversation. The POST operation
creates a new conversation, thread and post, and a new extension embedded in the post. The request body includes the
Topic and Threads properties, and a child post object for the new conversation. The post object
in turn contains the body of the new post, and the following data for the extension:
The type microsoft.graph.openTypeExtension.
The extension name "Com.Contoso.HR".
Additional data to be stored as 3 custom properties in the JSON payload: companyName, expirationDate, and the array of strings topPicks.
Here is the response from the fifth example which contains the new conversation and a thread ID. This new thread contains an automatically
created post, which in turn contains the new extension.
Note: The response object shown here might be shortened for readability.
To get the new extension, first get all the posts in this
thread, and initially there should be only one. Then apply the post ID and the extension name Com.Contoso.Benefits to
get the extension.