Microsoft Teams自适应卡片Webhook突发HTTP 400错误求助
Teams传入Webhook突然返回HTTP 400错误排查建议
问题概述
今日触发Microsoft Teams传入Webhook时收到报错:
Webhook消息投递失败,错误信息:Microsoft Teams端点返回HTTP错误400,ContextId为01=2..
Adaptive Card与Webhook已正常运行数月,近期未做改动,触发后无法发布到Teams。
卡片配置模板
{ "type": "message", "attachments": [ { "contentType": "application/vnd.microsoft.card.adaptive", "contentUrl": null, "content": { "$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.5", "body": [ { "type": "TextBlock", "text": "{{215595441__response__content}}", "wrap": true, "size": "Medium", "weight": "Medium", "separator": true }, { "type": "Container", "items": [ { "type": "ColumnSet", "columns": [ { "type": "Column", "width": "auto", "items": [ { "type": "Image", "url": "{{214806744__data__image__url}}", "size": "Medium", "style": "default" } ] }, { "type": "Column", "width": "stretch", "verticalContentAlignment": "center", "items": [ { "type": "TextBlock", "text": "{{214806744__data__title}}", "weight": "Bolder", "size": "Medium", "wrap": true } ] } ] }, { "type": "TextBlock", "text": "{{214806744__data__description}}", "wrap": true, "size": "Default" }, { "type": "TextBlock", "text": "Sent By: {{214806743__userName}}", "wrap": true, "size": "Small", "weight": "Lighter", "spacing": "Medium" } ], "style": "emphasis", "bleed": true } ], "actions": [ { "type": "Action.OpenUrl", "title": "Open URL", "url": "{{214806744__data__url}}", "style": "positive" } ] } } ] }
硬编码测试JSON
{"type": "message", "attachments": [{"contentType": "application/vnd.microsoft.card.adaptive", "contentUrl": null, "content": {"$schema": "http://adaptivecards.io/schemas/adaptive-card.json", "type": "AdaptiveCard", "version": "1.5", "body": [{"type": "TextBlock", "text": "lorem ipsum", "wrap": true, "size": "Medium", "weight": "Medium", "separator": true}, {"type": "Container", "items": [{"type": "ColumnSet", "columns": [{"type": "Column", "width": "auto", "items": [{"type": "Image", "url": "https://colourlex.com/wp-content/uploads/2021/02/vine-black-painted-swatch.jpg", "size": "Medium", "style": "default"}]}, {"type": "Column", "width": "stretch", "verticalContentAlignment": "center", "items": [{"type": "TextBlock", "text": "lorem ipsum", "weight": "Bolder", "size": "Medium", "wrap": true}]}]}, {"type": "TextBlock", "text": "lorem ipsum lorem ipsum", "wrap": true, "size": "Default"}, {"type": "TextBlock", "text": "Sent By: Benn, G", "wrap": true, "size": "Small", "weight": "Lighter", "spacing": "Medium"}], "style": "emphasis", "bleed": true}], "actions": [{"type": "Action.OpenUrl", "title": "Open URL", "url": "https://www.wsj.com/business/autos/a-free-world-champion-to-rival-china-nippon-chiefs-ambitions-for-u-s-steel-deal-598a9585?mod=hp_lead_pos3", "style": "positive"}]}]}]}
排查步骤
验证硬编码测试结果
- 先确认使用上述硬编码JSON调用Webhook是否成功。如果硬编码能正常发送,说明问题出在模板变量替换后的内容;如果硬编码也返回400,排查方向转向Webhook配置或Teams服务端。
检查变量替换后的JSON有效性
- 捕获变量替换后的完整JSON内容,用JSON校验工具检查格式是否合法(比如是否有未转义的引号、换行符等特殊字符)。
- 确认所有动态字段的值:
- 文本字段是否过长:Teams对Adaptive Card单段文本有长度限制,超长会触发400错误。
- URL字段是否为空或格式错误:图片URL、跳转URL必须是合法的HTTP/HTTPS地址,不能为空。
- 特殊字符是否转义:如果文本包含双引号、反斜杠等,需确保已正确转义。
确认Webhook端点有效性
- 重新生成Teams传入Webhook URL,替换原有URL测试。团队或频道的变更(如名称修改、权限调整)可能导致原有Webhook失效。
检查Adaptive Card版本兼容性
- 尝试将Adaptive Card的
version从1.5降级到1.4,部分Teams环境对高版本卡片的兼容性可能存在临时问题。
- 尝试将Adaptive Card的
排查Teams服务状态
- 确认Microsoft 365服务是否正常,Teams消息服务的临时故障也可能导致400错误。
内容的提问来源于stack exchange,提问作者Benn
相关产品推荐
相关产品推荐

