命名空间:microsoft.graph
创建新的目录扩展定义,由 extensionProperty 对象表示。
此 API 可用于以下国家级云部署。
全局服务 |
美国政府 L4 |
美国政府 L5 (DOD) |
由世纪互联运营的中国 |
✅ |
✅ |
✅ |
✅ |
权限
为此 API 选择标记为最低特权的权限。
只有在应用需要它时,才使用更高的特权权限。 有关委派权限和应用程序权限的详细信息,请参阅权限类型。 要了解有关这些权限的详细信息,请参阅 权限参考。
权限类型 |
最低特权权限 |
更高特权权限 |
委派(工作或学校帐户) |
Application.ReadWrite.All |
Directory.ReadWrite.All |
委派(个人 Microsoft 帐户) |
Application.ReadWrite.All |
不可用。 |
应用程序 |
Application.ReadWrite.OwnedBy |
Application.ReadWrite.All、Directory.ReadWrite.All |
HTTP 请求
POST /applications/{application ObjectId}/extensionProperties
POST /applications(appId='{appId}')/extensionProperties
名称 |
说明 |
Authorization |
持有者 {token}。 必填。 详细了解 身份验证和授权。 |
Content-Type |
application/json. 必需。 |
请求正文
在请求正文中,提供具有以下属性的 extensionProperty 对象。
属性 |
类型 |
说明 |
DataType |
String |
指定扩展属性可以容纳的值的数据类型。 支持以下值。 -
Binary - 最大 256 字节 Boolean -
DateTime - 必须以 ISO 8601 格式指定。 存储为 UTC 格式。 -
Integer - 32 位值。 -
LargeInteger - 64 位值。 -
String - 最多 256 个字符 不可为 null。 对于多值目录扩展,这些限制适用于集合中的每个值。 |
name |
String |
扩展属性的名称。 不可为 null。 |
isMultiValued |
布尔值 |
将目录扩展定义为多值属性。 当为 时 true ,目录扩展属性可以存储 dataType 的对象集合;例如,字符串类型的集合,例如 "extension_b7b1c57b532f40b8b5ed4b7a7ba67401_jobGroupTracker": ["String 1", "String 2"] 。 默认值为 false 。 |
targetObjects |
字符串集合 |
可以使用扩展属性的 Microsoft Graph 资源。 所有值都必须在 PascalCase 中。 支持以下值。 不可为 null。 User Group AdministrativeUnit Application Device Organization
|
响应
如果成功,此方法在响应正文中返回响应 201 Created
代码和新的 extensionProperty 对象。
示例
请求
以下示例显示了一个请求。
POST https://graph.microsoft.com/v1.0/applications/fd918e4b-c821-4efb-b50a-5eddd23afc6f/extensionProperties
Content-type: application/json
{
"name": "jobGroup",
"dataType": "String",
"isMultiValued": true,
"targetObjects": [
"User"
]
}
// Code snippets are only available for the latest version. Current version is 5.x
// Dependencies
using Microsoft.Graph.Models;
var requestBody = new ExtensionProperty
{
Name = "jobGroup",
DataType = "String",
IsMultiValued = true,
TargetObjects = new List<string>
{
"User",
},
};
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=csharp
var result = await graphClient.Applications["{application-id}"].ExtensionProperties.PostAsync(requestBody);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
mgc applications extension-properties create --application-id {application-id} --body '{\
"name": "jobGroup",\
"dataType": "String",\
"isMultiValued": true,\
"targetObjects": [\
"User"\
]\
}\
'
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest major version. Current major version is $v1.*
// Dependencies
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
requestBody := graphmodels.NewExtensionProperty()
name := "jobGroup"
requestBody.SetName(&name)
dataType := "String"
requestBody.SetDataType(&dataType)
isMultiValued := true
requestBody.SetIsMultiValued(&isMultiValued)
targetObjects := []string {
"User",
}
requestBody.SetTargetObjects(targetObjects)
// To initialize your graphClient, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=go
extensionProperties, err := graphClient.Applications().ByApplicationId("application-id").ExtensionProperties().Post(context.Background(), requestBody, nil)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
// Code snippets are only available for the latest version. Current version is 6.x
GraphServiceClient graphClient = new GraphServiceClient(requestAdapter);
ExtensionProperty extensionProperty = new ExtensionProperty();
extensionProperty.setName("jobGroup");
extensionProperty.setDataType("String");
extensionProperty.setIsMultiValued(true);
LinkedList<String> targetObjects = new LinkedList<String>();
targetObjects.add("User");
extensionProperty.setTargetObjects(targetObjects);
ExtensionProperty result = graphClient.applications().byApplicationId("{application-id}").extensionProperties().post(extensionProperty);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
const options = {
authProvider,
};
const client = Client.init(options);
const extensionProperty = {
name: 'jobGroup',
dataType: 'String',
isMultiValued: true,
targetObjects: [
'User'
]
};
await client.api('/applications/fd918e4b-c821-4efb-b50a-5eddd23afc6f/extensionProperties')
.post(extensionProperty);
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
<?php
use Microsoft\Graph\GraphServiceClient;
use Microsoft\Graph\Generated\Models\ExtensionProperty;
$graphServiceClient = new GraphServiceClient($tokenRequestContext, $scopes);
$requestBody = new ExtensionProperty();
$requestBody->setName('jobGroup');
$requestBody->setDataType('String');
$requestBody->setIsMultiValued(true);
$requestBody->setTargetObjects(['User', ]);
$result = $graphServiceClient->applications()->byApplicationId('application-id')->extensionProperties()->post($requestBody)->wait();
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
Import-Module Microsoft.Graph.Applications
$params = @{
name = "jobGroup"
dataType = "String"
isMultiValued = $true
targetObjects = @(
"User"
)
}
New-MgApplicationExtensionProperty -ApplicationId $applicationId -BodyParameter $params
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
# Code snippets are only available for the latest version. Current version is 1.x
from msgraph import GraphServiceClient
from msgraph.generated.models.extension_property import ExtensionProperty
# To initialize your graph_client, see https://learn.microsoft.com/en-us/graph/sdks/create-client?from=snippets&tabs=python
request_body = ExtensionProperty(
name = "jobGroup",
data_type = "String",
is_multi_valued = True,
target_objects = [
"User",
],
)
result = await graph_client.applications.by_application_id('application-id').extension_properties.post(request_body)
有关如何将 SDK 添加到项目并创建 authProvider 实例的详细信息,请参阅 SDK 文档。
响应
如果成功,此方法在 201 Created
响应正文中返回响应代码和 extensionProperty 对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications('fd918e4b-c821-4efb-b50a-5eddd23afc6f')/extensionProperties/$entity",
"id": "da38c7b1-133e-4a79-abcd-e2fd586ce621",
"deletedDateTime": null,
"appDisplayName": "b2c-extensions-app. Do not modify. Used by AADB2C for storing user data.",
"dataType": "String",
"isMultiValued": true,
"isSyncedFromOnPremises": false,
"name": "extension_25883231668a43a780b25685c3f874bc_jobGroup",
"targetObjects": [
"User"
]
}