我正在使用 microsoft graph 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": "[email protected]"
}
],
"givenName": "John"
},
{
"emailAddresses": [
{
"name": "John Doe",
"address": "[email protected]"
}
],
"givenName": "John"
}
]
有办法做到这一点还是不支持?我在文档中找不到任何提及它的内容。
有时我必须添加数千个联系人,而每个请求添加 1 个联系人似乎很乏味。
所有更新操作都有同样的问题:发布、修补、删除。
Microsoft Graph 有专门针对此类场景的批处理功能。每个操作仍然针对单个记录,但批处理允许您进行一次调用来执行最多 20 个操作:
{
"requests": [
{
"id": "1",
"method": "POST",
"url": "/me/contacts",
"headers":{
"Content-Type":"application/json"
},
"body": {
"emailAddresses": [
{
"name": "John Doe",
"address": "[email protected]"
}
],
"givenName": "John"
}
},
{
"id": "2",
"method": "POST",
"url": "/me/contacts",
"headers":{
"Content-Type":"application/json"
},
"body": {
"emailAddresses": [
{
"name": "John Doe",
"address": "[email protected]"
}
],
"givenName": "John"
}
},
{
"id": "3",
"method": "POST",
"url": "/me/contacts",
"headers":{
"Content-Type":"application/json"
},
"body": {
"emailAddresses": [
{
"name": "John Doe",
"address": "[email protected]"
}
],
"givenName": "John"
}
}
]
}
我正在尝试通过邮递员使用以下 API 调用来更新 SP 文档库元数据。 但出现以下错误,它与我想要实现的目标不符。
请分享对此的想法,
发布 - https://graph.microsoft.com/v1.0/$batch 有效的不记名令牌 但得到以下回应
"body": {
"error": {
"code": "invalid Request",
"message": "Files and folders should only be added to a Document Library via the One Drive API",
}
}
我的样品请求正文:
{
"requests": [
{
"id": "1",
"method": "POST",
"URL": "/sites/xxxxx.sharepoint.com:/sites/testsplist:/lists/9b2e99d1-c067-4122-bcb5-b5b00c413153/items/",
"headers": {
"Content-Type": "application/JSON"
},
"body": {
"Dept_No": "5Z3dd96869",
"Case_Name": "CONNIE-ESBTest001",
"Client": "Humane Treatment",
"Open_Date": "02/24/2016",
"Initial_Court_Date": "04/12/2016",
}
},
{
"id": "2",
"method": "POST",
"URL": "/sites/xxxxx.sharepoint.com:/sites/testsplist:/lists/9b2e99d1-c067-4122-bcb5-b5b00c413153/items/",
"headers": {
"Content-Type": "application/JSON"
},
"body": {
"Dept_No": "4Z4qq90233",
"Case_Name": "BBB ",
"Client": "Animal",
"Open_Date": "02/16/2017",
"Initial_Court_Date": "04/11/2017"
},
},
{
"id": "3",
"method": "POST",
"URL": "/sites/xxxxx.sharepoint.com:/sites/testsplist:/lists/9b2e99d1-c067-4122-bcb5-b5b00c413153/items/",
"headers": {
"Content-Type": "application/JSON"
},
"body": {
"Dept_No": "0Z4uu803",
"Case_Name": "ABIMALEK-ESBTest002",
"Client": "Health",
"Open_Date": "07/07/2020",
"Initial_Court_Date": "10/21/2020"
}
}
]
}