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

如何通过ServiceNow REST API对Request Item执行Cancel操作?

ServiceNow通过REST API取消请求项(sc_req_item)的方法

我们的ServiceNow请求项(Request Item)上有一个Cancel按钮,点击后会将Stage设置为"Request Cancelled",State设置为"Closed Incomplete"。

点击Cancel按钮

想通过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按钮的效果:

  1. 发送PATCH请求到以下端点:
$instanceURL/api/now/table/sc_req_item/$ritmSysID
  1. 请求头需包含:
    • Content-Type: application/json
    • 有效的认证信息(如Basic Auth或OAuth令牌)
  2. 请求体(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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 14:52:36