Create taskDefinition
命名空间:microsoft.graph
重要
Microsoft Graph版本下的 /beta API 可能会发生更改。 不支持在生产应用程序中使用这些 API。 若要确定 API 是否在 v1.0 中可用,请使用 版本 选择器。
创建新的任务定义。
有关如何使用此 API 向通用打印添加拉页打印支持的详细信息,请参阅扩展 通用打印以支持拉取打印。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限。
除了以下权限之外,用户的租户还必须具有活动的通用打印订阅。
| 权限类型 |
权限(从最低特权到最高特权) |
| 委派(工作或学校帐户) |
不支持。 |
| 委派(个人 Microsoft 帐户) |
不支持。 |
| 应用程序 |
PrintTaskDefinition.ReadWrite.All |
HTTP 请求
POST /print/taskDefinitions
| 名称 |
说明 |
| Authorization |
Bearer {token}。必需。 |
| Content-type |
application/json. Required. |
请求正文
在请求正文中,提供 printTaskDefinition 对象的 JSON 表示形式。
printTaskDefinition的 id 和 createdBy.appId 属性会在创建资源时自动设置。
响应
如果成功,此方法在响应 201 Created 正文中返回 响应代码和 printTaskDefinition 对象。
示例
请求
下面展示了示例请求。
POST https://graph.microsoft.com/beta/print/taskDefinitions
Content-type: application/json
{
"displayName": "Test TaskDefinitionName",
"createdBy": {
"displayName": "Requesting App Display Name"
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var printTaskDefinition = new PrintTaskDefinition
{
DisplayName = "Test TaskDefinitionName",
CreatedBy = new AppIdentity
{
DisplayName = "Requesting App Display Name"
}
};
await graphClient.Print.TaskDefinitions
.Request()
.AddAsync(printTaskDefinition);
const options = {
authProvider,
};
const client = Client.init(options);
const printTaskDefinition = {
displayName: 'Test TaskDefinitionName',
createdBy: {
displayName: 'Requesting App Display Name'
}
};
await client.api('/print/taskDefinitions')
.version('beta')
.post(printTaskDefinition);
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/beta/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/print/taskDefinitions"]]];
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphPrintTaskDefinition *printTaskDefinition = [[MSGraphPrintTaskDefinition alloc] init];
[printTaskDefinition setDisplayName:@"Test TaskDefinitionName"];
MSGraphAppIdentity *createdBy = [[MSGraphAppIdentity alloc] init];
[createdBy setDisplayName:@"Requesting App Display Name"];
[printTaskDefinition setCreatedBy:createdBy];
NSError *error;
NSData *printTaskDefinitionData = [printTaskDefinition getSerializedDataWithError:&error];
[urlRequest setHTTPBody:printTaskDefinitionData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
PrintTaskDefinition printTaskDefinition = new PrintTaskDefinition();
printTaskDefinition.displayName = "Test TaskDefinitionName";
AppIdentity createdBy = new AppIdentity();
createdBy.displayName = "Requesting App Display Name";
printTaskDefinition.createdBy = createdBy;
graphClient.print().taskDefinitions()
.buildRequest()
.post(printTaskDefinition);
//THE GO SDK IS IN PREVIEW. NON-PRODUCTION USE ONLY
graphClient := msgraphsdk.NewGraphServiceClient(requestAdapter)
requestBody := msgraphsdk.NewPrintTaskDefinition()
displayName := "Test TaskDefinitionName"
requestBody.SetDisplayName(&displayName)
createdBy := msgraphsdk.NewAppIdentity()
requestBody.SetCreatedBy(createdBy)
displayName := "Requesting App Display Name"
createdBy.SetDisplayName(&displayName)
result, err := graphClient.Print().TaskDefinitions().Post(requestBody)
Import-Module Microsoft.Graph.Devices.CloudPrint
$params = @{
DisplayName = "Test TaskDefinitionName"
CreatedBy = @{
DisplayName = "Requesting App Display Name"
}
}
New-MgPrintTaskDefinition -BodyParameter $params
响应
下面展示了示例响应。
注意: 为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 201 Created
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/beta/$metadata#print/taskDefinitions/$entity",
"id": "fab143fd-ee61-4358-8558-2c7dee953982",
"displayName": "Test TaskDefinitionName",
"createdBy": {
"appId": "815f204f-c791-4ee6-9098-614ecdb003f6",
"displayName": "Requesting App Display Name"
}
}