创建 externalItem
命名空间:microsoft.graph.externalConnectors
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建新的 externalItem。
此 API 可用于创建自定义项。 包含 的 externalConnection 必须注册相应类型的 架构 。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
ExternalItem.ReadWrite.OwnedBy、ExternalItem.ReadWrite.All |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
ExternalItem.ReadWrite.OwnedBy、ExternalItem.ReadWrite.All |
HTTP 请求
PUT /external/connections/{connection-id}/items/{item-id}
路径参数
| 参数 |
类型 |
说明 |
| connection-id |
string |
id包含 externalConnection 的属性 |
| item-id |
string |
externalItem 的开发人员提供的id属性。 如果此 id项中尚不存在任何项,则会创建一个新项。 如果此项已存在 id,则由在正文中发送的对象覆盖该项。 |
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-Type |
application/json. Required. |
请求正文
在请求正文中,提供 externalItem 对象的 JSON 表示形式。 有效负载限制为 4 MB。
创建 externalItem
创建某个externalItem字段时,需要以下字段: acl``properties 该 properties 对象必须至少包含一个属性。
所有 DateTime 类型属性都必须采用 ISO 8601 格式。
在以下方案中,某个属性 externalItem 应在有效负载中使用类型说明符:
对于 String 类型属性,如果该值包含非 ASCII 字符。
"description@odata.type": "String",
"description": "Kandierte Äpfel"
对于所有集合类型。
"categories@odata.type": "Collection(String)"
"categories": [
"red",
"blue"
]
重要
包括类型的 Collection(DateTime)属性时,必须使用类型说明符 Collection(DateTimeOffset)。
响应
如果成功,此方法返回 200 OK 响应代码。
示例
示例:创建自定义项
请求
下面展示了示例请求。
PUT https://graph.microsoft.com/beta/external/connections/contosohr/items/TSP228082938
Content-type: application/json
{
"acl": [
{
"type": "user",
"value": "e811976d-83df-4cbd-8b9b-5215b18aa874",
"accessType": "grant",
"identitySource": "azureActiveDirectory"
},
{
"type": "group",
"value": "14m1b9c38qe647f6a",
"accessType": "deny",
"identitySource": "external"
}
],
"properties": {
"title": "Error in the payment gateway",
"priority": 1,
"assignee": "john@contoso.com"
},
"content": {
"value": "Error in payment gateway...",
"type": "text"
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var externalItem = new Microsoft.Graph.ExternalConnectors.ExternalItem
{
Acl = new List<Microsoft.Graph.ExternalConnectors.Acl>()
{
new Microsoft.Graph.ExternalConnectors.Acl
{
Type = Microsoft.Graph.ExternalConnectors.AclType.User,
Value = "e811976d-83df-4cbd-8b9b-5215b18aa874",
AccessType = Microsoft.Graph.ExternalConnectors.AccessType.Grant,
IdentitySource = Microsoft.Graph.ExternalConnectors.IdentitySourceType.AzureActiveDirectory
},
new Microsoft.Graph.ExternalConnectors.Acl
{
Type = Microsoft.Graph.ExternalConnectors.AclType.Group,
Value = "14m1b9c38qe647f6a",
AccessType = Microsoft.Graph.ExternalConnectors.AccessType.Deny,
IdentitySource = Microsoft.Graph.ExternalConnectors.IdentitySourceType.External
}
},
Properties = new Microsoft.Graph.ExternalConnectors.Properties
{
AdditionalData = new Dictionary<string, object>()
{
{"title", "Error in the payment gateway"},
{"priority", "1"},
{"assignee", "john@contoso.com"}
}
},
Content = new Microsoft.Graph.ExternalConnectors.ExternalItemContent
{
Value = "Error in payment gateway...",
Type = Microsoft.Graph.ExternalConnectors.ExternalItemContentType.Text
}
};
await graphClient.External.Connections["{externalConnectors.externalConnection-id}"].Items["{externalConnectors.externalItem-id}"]
.Request()
.PutAsync(externalItem);
const options = {
authProvider,
};
const client = Client.init(options);
const externalItem = {
acl: [
{
type: 'user',
value: 'e811976d-83df-4cbd-8b9b-5215b18aa874',
accessType: 'grant',
identitySource: 'azureActiveDirectory'
},
{
type: 'group',
value: '14m1b9c38qe647f6a',
accessType: 'deny',
identitySource: 'external'
}
],
properties: {
title: 'Error in the payment gateway',
priority: 1,
assignee: 'john@contoso.com'
},
content: {
value: 'Error in payment gateway...',
type: 'text'
}
};
await client.api('/external/connections/contosohr/items/TSP228082938')
.version('beta')
.put(externalItem);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/external/connections/contosohr/items/TSP228082938"]]];
[urlRequest setHTTPMethod:@"PUT"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphExternalConnectorsExternalItem *externalItem = [[MSGraphExternalConnectorsExternalItem alloc] init];
NSMutableArray *aclList = [[NSMutableArray alloc] init];
MSGraphExternalConnectorsAcl *acl = [[MSGraphExternalConnectorsAcl alloc] init];
[acl setType: [MSGraphExternalConnectorsAclType user]];
[acl setValue:@"e811976d-83df-4cbd-8b9b-5215b18aa874"];
[acl setAccessType: [MSGraphExternalConnectorsAccessType grant]];
[acl setIdentitySource: [MSGraphExternalConnectorsIdentitySourceType azureActiveDirectory]];
[aclList addObject: acl];
MSGraphExternalConnectorsAcl *acl = [[MSGraphExternalConnectorsAcl alloc] init];
[acl setType: [MSGraphExternalConnectorsAclType group]];
[acl setValue:@"14m1b9c38qe647f6a"];
[acl setAccessType: [MSGraphExternalConnectorsAccessType deny]];
[acl setIdentitySource: [MSGraphExternalConnectorsIdentitySourceType external]];
[aclList addObject: acl];
[externalItem setAcl:aclList];
MSGraphExternalConnectorsProperties *properties = [[MSGraphExternalConnectorsProperties alloc] init];
[properties setTitle:@"Error in the payment gateway"];
[properties setPriority: 1];
[properties setAssignee:@"john@contoso.com"];
[externalItem setProperties:properties];
MSGraphExternalConnectorsExternalItemContent *content = [[MSGraphExternalConnectorsExternalItemContent alloc] init];
[content setValue:@"Error in payment gateway..."];
[content setType: [MSGraphExternalConnectorsExternalItemContentType text]];
[externalItem setContent:content];
NSError *error;
NSData *externalItemData = [externalItem getSerializedDataWithError:&error];
[urlRequest setHTTPBody:externalItemData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.New()
requestBody.SetAdditionalData(map[string]interface{}{
"acl": []Object {
}
}
externalConnectionId := "externalConnection-id"
externalItemId := "externalItem-id"
graphClient.External().ConnectionsById(&externalConnectionId).ItemsById(&externalItemId).Put(requestBody)
响应
下面展示了示例响应。
HTTP/1.1 200 OK