使用图形 API 订阅 Webhook 通知时的资源值



我正在尝试订阅 Web hook 通知的 Microsoft 图形 API,以跟踪 SharePoint 文档库中文件夹中的更改。我只能通过应用访问此 SharePoint 网站,并且能够查看和下载与文档库关联的驱动器中的所有内容。我还可以使用 API 上传新文件。

调用订阅终结点时,收到内部服务器错误。

这是我提出的要求

curl -X POST 
https://graph.microsoft.com/v1.0/drive/root/subscriptions 
-H 'Accept: */*' 
-H 'Accept-Encoding: gzip, deflate' 
-H 'Authorization: Bearer TOKEN' 
-H 'Cache-Control: no-cache' 
-H 'Connection: keep-alive' 
-H 'Content-Length: 303' 
-H 'Content-Type: application/json' 
-H 'Host: graph.microsoft.com' 
-d '{
"changeType": "updated",
"notificationUrl": "https://c.ngrok.io/sp-hook",
"resource": "drives/{{DRIVE-ID}}/root",
"expirationDateTime": "2019-09-18T11:23:00.000",
"clientState": "test"
}'

这是我得到的回复

{
"error": {
"code": "InternalServerError",
"message": "Unable to find target address",
"innerError": {
"request-id": "c8e66e50-5b94-4593-88d5-3111e5c5c6c7",
"date": "2019-09-13T09:50:12"
}
}
}

我相信这可能是由于资源值错误,但我找不到有关资源价值应该是什么的文档。我已经过去了:https://learn.microsoft.com/en-us/graph/webhooks 和 https://learn.microsoft.com/en-us/graph/api/resources/webhooks?view=graph-rest-1.0。所有文档似乎都指向"me/drives/root"的资源值,但是仅使用应用程序访问未定义我的站点,因此调用失败。

这些是我在请求 json 正文中尝试过的资源的不同值

drives('DRIVE-ID')/root
drives/DRIVE-ID/root
DRIVE-ID
drive/DRIVE-ID
drive/DRIVE-ID/root
me/drive("DRIVE-ID")/root
DRIVE-ITEM-ID-FOR-ROOT

不同的文档似乎指向不同的订阅终结点。这些是我尝试过的不同端点 https://graph.microsoft.com/v1.0/subscriptions https://graph.microsoft.com/v1.0/drive/root/subscriptions https://graph.microsoft.com/beta/drives/{{drive-id}}/root/subscriptions

该错误还让我怀疑在订阅注册期间,它无法找到我的 webhook。但是,在测试了端点后,我确信它是可访问的。

其他信息

我使用以下调用来获取共享点网站的驱动器 ID

curl -X GET 
'https://graph.microsoft.com/v1.0/sites/SITE-ID/drive' 
-H 'Accept: */*' 
-H 'Accept-Encoding: gzip, deflate' 
-H 'Authorization: Bearer TOKEN' 
-H 'Cache-Control: no-cache' 
-H 'Connection: keep-alive' 
-H 'Content-Type: application/json' 
-H 'Host: graph.microsoft.com' 

我看到您正在 https://graph.microsoft.com/v1.0/drive/root/subscriptions 端点上执行 POST

预期的订阅终结点为 https://graph.microsoft.com/v1.0/subscriptions

请注意,URL 路径中没有"/drive/root"。

最新更新