代码的主要*问题是缺少必需的
properties
领域
如中所述
Microsoft Graph doc on creating schema extensions
,您必须提供
id
,则,
description
,则,
targetTypes
和
属性
创建新
schemaExtension
。(The
owner
属性是可选的。)
以下代码应该可以工作。(请注意,我还切换到使用v1.0端点,因为这已经超出了beta版。)
$token = $this->getToken(); // Assume this does what the name implies
$headers = [
'Authorization: Bearer ' . $token,
'Content-Type: application/json'
];
$data = json_encode([
'id' => 'size',
'description' => 'Height and shoe size',
'targetTypes' => ['User'],
'properties' => [
[
'id' => 'shoeSize',
'type' => 'Integer',
],
[
'id' => 'height',
'type' => 'Integer',
],
[
'id' => 'tShirtSize',
'type' => 'String',
],
]
]);
$ch = curl_init('https://graph.microsoft.com/v1.0/schemaExtensions');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$schemaExtension = json_decode(curl_exec($ch));
return $schemaExtension->id;
如果您想使用
Microsoft Graph SDK for PHP
,代码看起来非常相似:
use Microsoft\Graph\Graph;
use Microsoft\Graph\Model;
$token = $this->getToken(); // Assume this does what the name implies
$graph = new Graph();
$graph->setAccessToken($token);
$newSchemaExtension = new Model\SchemaExtension([
'id' => 'sizes',
'description' => 'Height, shoe and shirt size',
'targetTypes' => ['User'],
'properties' => [
[
'name' => 'shoeSize',
'type' => 'Integer',
],
[
'name' => 'height',
'type' => 'Integer',
],
[
'name' => 'shirtSize',
'type' => 'String',
],
]
]);
$schemaExtension = $graph->createRequest('POST', '/schemaExtensions')
->attachBody($newSchemaExtension)
->setReturnType(Model\SchemaExtension::class)
->execute();
return $schemaExtension->getId();
*失踪者
属性
财产是主要问题,但你还有几个其他问题:
-
您正在尝试引用
id号
具有的属性
$arr->id
但是
json_decode($string, true)
返回关联数组,以便使用
$arr['id']
相反
-
您正在尝试设置
status
创建过程中的架构扩展,这也会导致错误(尽管是另一个错误)。首次创建架构扩展时,请忽略
地位
字段,并在准备就绪后进行更新。