调用PATCH/PUT更新Statuspage Incident时返回{"error":"incident is missing"}问题
解决Statuspage API更新Incident时返回{"error":"incident is missing"}的问题
我刚帮你定位到了问题的核心,你的请求JSON数据结构不符合API要求,这才导致了这个错误。
问题出在哪?
你当前的请求体里,把incident字段直接赋值成了事件名称的字符串:
{ "incident": "Requests Failed (500)", "status": "identified" }
但Statuspage的更新接口(不管是PATCH还是PUT)要求所有需要更新的字段都必须包裹在incident这个对象里,而不是把incident作为一个字符串值。
修正后的请求示例
把请求体改成嵌套结构,用name字段设置事件名称(这是API规定的字段名,不是直接用incident),所有更新字段放在incident对象内:
curl --location --request PATCH 'https://api.statuspage.io/v1/pages/xxxx/incidents/lf7****nf2?api_key=xxx' \ --header 'Content-Type: application/json' \ --data-raw '{ "incident": { "name": "Requests Failed (500)", "status": "identified" } }'
额外说明
- 你之前创建和查询能成功,应该是创建请求时用了正确的嵌套结构(比如
{"incident": {"name": "...", ...}}),但更新时疏忽了结构要求 - PATCH请求可以只传需要更新的字段(比如只改
status的话,就传{"incident": {"status": "identified"}}),而PUT需要传入完整的incident对象,但两者都必须遵守incident嵌套的结构规则
内容的提问来源于stack exchange,提问作者khinester




