如何通过ServiceNow REST API对Request Item执行Cancel操作?
ServiceNow通过REST API取消请求项(sc_req_item)的方法
我们的ServiceNow请求项(Request Item)上有一个Cancel按钮,点击后会将Stage设置为"Request Cancelled",State设置为"Closed Incomplete"。

想通过ServiceNow的REST API实现相同效果,尝试发送POST请求到:
"$instanceURL/api/now/table/sc_req_item/$ritmSysID/cancel"
但收到错误:
Error: The remote server returned an error: (400) Bad Request.
Response Content: {"error":{"message":"Requested URI does not represent any resource","detail":null},"status":"failure"}
正确实现步骤
ServiceNow没有内置/cancel这个REST端点,直接更新sc_req_item记录即可实现Cancel按钮的效果:
- 发送PATCH请求到以下端点:
$instanceURL/api/now/table/sc_req_item/$ritmSysID
- 请求头需包含:
Content-Type: application/json- 有效的认证信息(如Basic Auth或OAuth令牌)
- 请求体(JSON格式):
{ "stage": "Request Cancelled", "state": "Closed Incomplete" }
注意:如果你的实例中Stage或State字段的内部存储值不是显示文本(比如用数字编码),需要替换为对应的有效值。可以在ServiceNow的表字典(Dictionary)中查看
sc_req_item表的stage和state字段获取这些值。
如果需要复用Cancel按钮的后台业务逻辑(比如触发关联事件、通知),可以自定义Scripted REST API端点来调用原UI Action的脚本,但直接更新字段是最简便的方式。
内容的提问来源于stack exchange,提问作者TripToBelize
相关产品推荐
相关产品推荐

