You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过SharePoint webhooks获取通知中的操作类型信息

如何获取SharePoint Webhook通知中的操作类型信息

嗨,我明白你的困扰——目前打印的日志确实只包含了订阅和资源的基础标识,完全看不出具体是啥操作。别担心,SharePoint Webhook的通知 payload 里其实自带了操作类型信息,只是你需要解析完整的请求体才能拿到它。

核心:解析完整的Webhook请求Payload

当SharePoint触发webhook通知时,会发送一个JSON格式的请求体,里面的value数组包含了所有触发的通知条目。每个条目里的resourceData.eventType字段,就是你要找的操作类型标识。

常见的eventType值对应操作如下:

  • Microsoft.SharePoint.ListItemAdded:添加列表项
  • Microsoft.SharePoint.ListItemUpdated:更新列表项
  • Microsoft.SharePoint.ListItemDeleted:删除列表项
  • Microsoft.SharePoint.FileAdded:文档库中添加文件
  • Microsoft.SharePoint.FileUpdated:文档库中更新文件
  • Microsoft.SharePoint.FileDeleted:文档库中删除文件

修改代码获取操作类型

以ASP.NET为例,你可以调整接收webhook的端点代码,读取并解析完整请求内容,提取eventType:

using System.Web.Mvc;
using Newtonsoft.Json.Linq;

public class WebhookController : Controller
{
    [HttpPost]
    public ActionResult Receive()
    {
        // 读取完整的请求JSON内容
        var jsonContent = Request.Content.ReadAsStringAsync().Result;
        var payload = JObject.Parse(jsonContent);
        
        // 遍历所有通知条目
        foreach (var notification in payload["value"])
        {
            // 提取操作类型
            var eventType = notification["resourceData"]["eventType"].ToString();
            // 打印操作类型+你之前的基础信息
            System.Diagnostics.Trace.WriteLine($"EventType: {eventType}");
            System.Diagnostics.Trace.WriteLine($"Resource: {notification["resource"]}");
            System.Diagnostics.Trace.WriteLine($"SubscriptionId: {notification["subscriptionId"]}");
            System.Diagnostics.Trace.WriteLine($"TenantId: {notification["tenantId"]}");
            System.Diagnostics.Trace.WriteLine($"SiteUrl: {notification["siteUrl"]}");
            System.Diagnostics.Trace.WriteLine($"WebId: {notification["webId"]}");
            System.Diagnostics.Trace.WriteLine($"ExpirationDateTime: {notification["expirationDateTime"]}");
        }
        
        // 返回200状态码确认接收
        return new HttpStatusCodeResult(System.Net.HttpStatusCode.OK);
    }
}

小提醒

  • 确保你的项目引入了JSON解析库(比如Newtonsoft.Json或System.Text.Json)
  • 首次配置webhook时的验证请求不会包含操作类型,只有实际事件触发时才会发送带eventType的通知

这样修改后,你就能在日志里清晰看到具体是添加、更新还是删除这类操作了!

内容的提问来源于stack exchange,提问作者Abhi Singh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 12:52:50