Create schemaExtension

Create a new schemaExtension definition to extend a supporting resource type.

Schema extensions let you add strongly-typed custom data to a resource. The app that creates a schema extension is the owner app. Depending on the state of the extension, the owner app, and only the owner app, may update or delete the extension.

See examples of how to define a schema extension that describes a training course, use the schema extension definition to create a new group with training course data, and add training course data to an existing group.

Prerequisites

The following scope is required to execute this API: Directory.AccessAsUser.All

HTTP request

POST /schemaExtensions

Request headers

Name Description
Authorization Bearer <token>. Required.
Content-Type application/json

Request body

In the request body, supply a JSON representation of schemaExtension object.

The following table shows the properties that are required when you create a schema extension.

Parameter Type Description
description String Description for the schema extension.
id String The unique identifier for the schema extension definition.
You can assign a value in one of two ways:
  • Concatenate the name of one of your verified domains with a name for the schema extension to form a unique string in this format, {domainName}_{schemaName}. As an example, contoso_mySchema.
  • Provide a schema name, and let Microsoft Graph use that schema name to complete the id assignment in this format: ext{8-random-alphanumeric-chars}_{schema-name}. An example would be extkvbmkofy_mySchema.
This property cannot be changed after creation.
properties extensionSchemaProperty collection The collection of property names and types that make up the schema extension definition.
targetTypes String collection Set of Microsoft Graph resource types (that support schema extensions) that this schema extension definition can be applied to.

Response

If successful, this method returns 201, Created response code and schemaExtension object in the response body.

Example

Request 1

The first example shows using a verified domain name, graphlearn, and a schema name, courses, to form a unique string for the id property of the schema extension definition. The unique string is based on this format, {domainName}_{schemaName}.

In the request body, supply a JSON representation of the schemaExtension object.

POST https://graph.microsoft.com/beta/schemaExtensions
Content-type: application/json

{
    "id":"graphlearn_courses",
    "description": "Graph Learn training courses extensions",
    "targetTypes": [
        "Group"
    ],
    "properties": [
        {
            "name": "courseId",
            "type": "Integer"
        },
        {
            "name": "courseName",
            "type": "String"
        },
        {
            "name": "courseType",
            "type": "String"
        }
    ]
}

Response 1

Here is an example of the response. Note: The response object shown here may be truncated for brevity. All of the properties will be returned from an actual call.

HTTP/1.1 201 Created
Content-type: application/json
Content-length: 420

{
    "id": "graphlearn_courses",
    "description": "Graph Learn training courses extensions",
    "targetTypes": [
        "Group"
    ],
    "status": "InDevelopment",
    "owner": "24d3b144-21ae-4080-943f-7067b395b913",
    "properties": [
        {
            "name": "courseId",
            "type": "String"
        },
        {
            "name": "courseName",
            "type": "String"
        },
        {
            "name": "courseType",
            "type": "String"
        }
    ]
}

Request 2

The second example shows specifying just a schema name, courses, in the id property in the request, together with the JSON representation of the rest of the properties in the schemaExtension object. Microsoft Graph will assign and return a unique string value in the response.

POST https://graph.microsoft.com/beta/schemaExtensions
Content-type: application/json

{
    "id":"courses",
    "description": "Graph Learn training courses extensions",
    "targetTypes": [
        "Group"
    ],
    "properties": [
        {
            "name": "courseId",
            "type": "Integer"
        },
        {
            "name": "courseName",
            "type": "String"
        },
        {
            "name": "courseType",
            "type": "String"
        }
    ]
}

Response 2

The response includes a unique string in the id property that is based on the schema name provided in the request, together with the rest of the newly created schema definition. The value in id in the response is based on the format, ext{8-random-alphanumeric-chars}_{schema-name}. Note: The response object shown here may be truncated for brevity. All of the properties will be returned from an actual call.

HTTP/1.1 201 Created
Content-type: application/json
Content-length: 420

{
    "id": "extk9eruy7c_courses",
    "description": "Graph Learn training courses extensions",
    "targetTypes": [
        "Group"
    ],
    "status": "InDevelopment",
    "owner": "24d3b144-21ae-4080-943f-7067b395b913",
    "properties": [
        {
            "name": "courseId",
            "type": "String"
        },
        {
            "name": "courseName",
            "type": "String"
        },
        {
            "name": "courseType",
            "type": "String"
        }
    ]
}

See also