我正在使用Microsoft图形php sdk来操纵用户的联系人。我可以对单个联系人执行CRUD操作,但是我试图弄清楚是否可以在单个请求中处理多个联系人。这对于添加单个客户端很好用:
$graph=new Graph;
$graph->setAccessToken($token);
$graph->createRequest('POST', $url)
->attachBody($contact)
->setReturnType(Contact::class)
->execute();
我尝试过批量
->attachBody([$contact1, $contact2, $contact3]);
我收到400错误:
"code": "BadRequest",
"message": "Empty Payload. JSON content expected.",
尝试graph explorer并使用此正文发布到
https://graph.microsoft.com/v1.0/me/contacts
时遇到相同的错误:
[
{
"emailAddresses": [
{
"name": "John Doe",
"address": "jdoe@example.com"
}
],
"givenName": "John"
},
{
"emailAddresses": [
{
"name": "John Doe",
"address": "jdoe@example.com"
}
],
"givenName": "John"
}
]
有没有办法做到这一点?我在文档中都找不到提及它的方法。
有时候,我必须添加数千个联系人,并且每个请求要做1个,这看起来很乏味。
所有更新操作都存在相同的问题:发布,修补,删除。
答案 0 :(得分:1)
Microsoft Graph有一个专门用于这种情况的Batching feature。每个操作仍然针对单个记录,但是通过批处理,您可以调用一次以执行最多20个操作:
{
"requests": [
{
"id": "1",
"method": "POST",
"url": "/me/contacts",
"headers":{
"Content-Type":"application/json"
},
"body": {
"emailAddresses": [
{
"name": "John Doe",
"address": "jdoe@example.com"
}
],
"givenName": "John"
}
},
{
"id": "2",
"method": "POST",
"url": "/me/contacts",
"headers":{
"Content-Type":"application/json"
},
"body": {
"emailAddresses": [
{
"name": "John Doe",
"address": "jdoe@example.com"
}
],
"givenName": "John"
}
},
{
"id": "3",
"method": "POST",
"url": "/me/contacts",
"headers":{
"Content-Type":"application/json"
},
"body": {
"emailAddresses": [
{
"name": "John Doe",
"address": "jdoe@example.com"
}
],
"givenName": "John"
}
}
]
}