ServiceNow Table API Read Only
Use this skill to read data from ServiceNow via the Table API. Do not create or update or delete records.
Configuration
Set these environment variables in the .env file in this folder.
- - SERVICENOWDOMAIN instance domain such as myinstance.service-now.com
- SERVICENOWUSERNAME username for basic auth
- SERVICENOW_PASSWORD password for basic auth
If your domain already includes https:// then use it as is. Otherwise requests should be made to:
CODEBLOCK0
Allowed Operations GET only
Use only the GET endpoints from these files.
- - openapi.yaml for Table API
- references/attachment.yaml for Attachment API
- references/aggregate-api.yaml for Aggregate API
- references/service-catalog-api.yaml for Service Catalog API
List records
- - GET /api/now/table/{tableName}
Get a record by sys_id
- - GET /api/now/table/{tableName}/{sys_id}
Never use POST or PUT or PATCH or DELETE.
Common Query Params Table API
- - sysparmquery encoded query such as active=true^priority=1
- sysparmfields comma separated fields to return
- sysparmlimit limit record count to keep small for safety
- sysparmdisplayvalue true or false or all
- sysparmexcludereferencelink true to reduce clutter
See openapi.yaml for the full list of parameters.
CLI
Use the bundled CLI for all reads. It pulls auth from .env by default. You can override with flags.
Command overview
- - list table lists records from a table
- get table sysid fetches one record by sysid
- batch file.json runs multiple read requests in one call
- attach reads attachments and file content
- stats table aggregates stats
- schema table lists valid field names and types
- history table sys_id reads full comment and work note timeline
- sc endpoint Service Catalog GET endpoints
Auth flags
- - --domain domain instance domain
- --username user
- --password pass
Query flags
Use any of these as --sysparm_* flags.
- - --sysparmquery
- --sysparmfields
- --sysparmlimit
- --sysparmdisplayvalue
- --sysparmexcludereferencelink
- --sysparmsuppresspaginationheader
- --sysparmview
- --sysparmquerycategory
- --sysparmquerynodomain
- --sysparmno_count
Attachment API params
- - --sysparmquery
- --sysparmsuppresspaginationheader
- --sysparmlimit
- --sysparmquery_category
Aggregate API params
- - --sysparmquery
- --sysparmavgfields
- --sysparmcount
- --sysparmminfields
- --sysparmmaxfields
- --sysparmsumfields
- --sysparmgroupby
- --sysparmorderby
- --sysparmhaving
- --sysparmdisplayvalue
- --sysparmquery_category
Service Catalog params
- - --sysparmview
- --sysparmlimit
- --sysparmtext
- --sysparmoffset
- --sysparmcategory
- --sysparmtype
- --sysparmcatalog
- --sysparmtoplevelonly
- --recordid
- --templateid
- --mode
Output
- - --pretty pretty print JSON output
- --out path save binary attachment content to a file
Examples
List recent incidents.
CODEBLOCK1
Query with a filter.
CODEBLOCK2
Fetch a single record.
CODEBLOCK3
Override auth on the fly.
CODEBLOCK4
Attachment metadata and file download.
CODEBLOCK5
Aggregate stats.
CODEBLOCK6
Service Catalog read only GETs.
CODEBLOCK7
Service Catalog endpoints GET only
- - cart
- delivery-address userid
- validate-categories
- on-change-choices entityid
- catalogs
- catalog sysid
- catalog-categories sysid
- category sysid
- items
- item sysid
- item-variables sysid
- item-delegation itemsysid usersysid
- producer-record producerid recordid
- record-wizard recordid wizardid
- generate-stage-pool quantity
- step-configs
- wishlist
- wishlist-item cartitemid
- wizard sysid
Schema Inspection
Use this if you are unsure of a field name.
CODEBLOCK8
Reading Ticket History
Use this to read the full conversation instead of just the current state.
CODEBLOCK9
Specialist presets
Create JSON batch files under specialists/ to run multiple reads at once.
- - specialists/incidents.json
Each entry supports sysparm_* fields plus these items.
- - name label in the batch output
- table target table
- sys_id optional single record fetch
Run a batch preset.
CODEBLOCK10
Output
The Table API returns JSON by default. Results appear under result.
Notes
- - Keep result sizes small with sysparmlimit.
- Use sysparmfields to avoid large payloads.
- This skill is read only by design.
Summary of the Agent Toolkit
- - list and get show the current state of records.
- attach shows files and screenshots.
- stats shows analytics and aggregates.
- sc shows requested item variables.
- schema shows the database map to correct errors.
- history shows the timeline of human conversations.
Observations & Notes (important)
- - Service Catalog endpoints may return empty arrays depending on catalog content and search text — try more specific
--sysparm_text terms or increase --sysparm_limit. - INLINECODE2 is enabled by default for table reads to return human-friendly values (e.g., user names instead of sysids). If you need raw system ids, pass
--sysparm_display_value false. - Keep
--sysparm_limit small for agent-initiated queries to avoid large payloads and timeouts. Prefer stats for counts or aggregates instead of downloading many rows. - Attachments: metadata is available via
attach list/attach get; use attach file <sys_id> --out <path> to download binary content for local analysis. - Schema inspection (
schema) avoids guessing field names and is the recommended first step before reading unknown tables. - History (
history) fetches journal entries (comments/worknotes) from sys_journal_field and is useful to read the full conversation thread for a ticket. - Use
--pretty to make JSON outputs readable for human review and to help the agent summarize long results.
Recommended Batch Presets
I recommend these specialist JSON presets under specialists/ to speed up common read workflows. They are safe (read-only) and demonstrate how to combine related reads.
1) specialists/inspect_incident_schema.json — schema inspection for incident:
CODEBLOCK11
2) specialists/incident_history_template.json — history template (replace <SYS_ID> with the target sys_id before running):
CODEBLOCK12
3) specialists/attachments_incident.json — recent attachments for incident table:
CODEBLOCK13
How to use these:
- - For schema: INLINECODE19
- For history: replace
<SYS_ID> then node cli.mjs batch specialists/incident_history_template.json --pretty (or run node cli.mjs history incident <SYS_ID> --pretty) - For attachments:
node cli.mjs batch specialists/attachments_incident.json --pretty, then node cli.mjs attach file <sys_id> --out /tmp/file to download a file.
These presets are intentionally read-only and conservative (limits set small). Feel free to ask for additional presets (P1 dashboards, recent changes, escalations).
ServiceNow 表 API 只读
使用此技能通过表 API 从 ServiceNow 读取数据。请勿创建、更新或删除记录。
配置
在此文件夹的 .env 文件中设置以下环境变量。
- - SERVICENOWDOMAIN 实例域名,例如 myinstance.service-now.com
- SERVICENOWUSERNAME 基本认证的用户名
- SERVICENOW_PASSWORD 基本认证的密码
如果您的域名已包含 https://,则直接使用。否则,请求应发送至:
https://$SERVICENOW_DOMAIN
允许的操作 仅 GET
仅使用以下文件中的 GET 端点。
- - openapi.yaml 用于表 API
- references/attachment.yaml 用于附件 API
- references/aggregate-api.yaml 用于聚合 API
- references/service-catalog-api.yaml 用于服务目录 API
列出记录
- - GET /api/now/table/{tableName}
通过 sys_id 获取记录
- - GET /api/now/table/{tableName}/{sys_id}
切勿使用 POST、PUT、PATCH 或 DELETE。
常用查询参数 表 API
- - sysparmquery 编码查询,例如 active=true^priority=1
- sysparmfields 逗号分隔的返回字段
- sysparmlimit 限制记录数量以确保安全
- sysparmdisplayvalue true、false 或 all
- sysparmexcludereferencelink true 以减少杂乱
请参阅 openapi.yaml 获取完整参数列表。
CLI
使用捆绑的 CLI 进行所有读取操作。默认情况下,它会从 .env 文件中提取认证信息。您可以使用标志覆盖。
命令概览
- - list table 列出表中的记录
- get table sysid 通过 sysid 获取一条记录
- batch file.json 一次调用执行多个读取请求
- attach 读取附件和文件内容
- stats table 聚合统计信息
- schema table 列出有效的字段名称和类型
- history table sys_id 读取完整的评论和工作备注时间线
- sc endpoint 服务目录 GET 端点
认证标志
- - --domain 域名实例域名
- --username 用户名
- --password 密码
查询标志
使用以下任一作为 --sysparm_* 标志。
- - --sysparmquery
- --sysparmfields
- --sysparmlimit
- --sysparmdisplayvalue
- --sysparmexcludereferencelink
- --sysparmsuppresspaginationheader
- --sysparmview
- --sysparmquerycategory
- --sysparmquerynodomain
- --sysparmno_count
附件 API 参数
- - --sysparmquery
- --sysparmsuppresspaginationheader
- --sysparmlimit
- --sysparmquery_category
聚合 API 参数
- - --sysparmquery
- --sysparmavgfields
- --sysparmcount
- --sysparmminfields
- --sysparmmaxfields
- --sysparmsumfields
- --sysparmgroupby
- --sysparmorderby
- --sysparmhaving
- --sysparmdisplayvalue
- --sysparmquery_category
服务目录参数
- - --sysparmview
- --sysparmlimit
- --sysparmtext
- --sysparmoffset
- --sysparmcategory
- --sysparmtype
- --sysparmcatalog
- --sysparmtoplevelonly
- --recordid
- --templateid
- --mode
输出
- - --pretty 美化打印 JSON 输出
- --out 路径 将二进制附件内容保存到文件
示例
列出最近的事件。
bash
node cli.mjs list incident --sysparmlimit 5 --sysparmfields number,shortdescription,priority,sysid
使用过滤器查询。
bash
node cli.mjs list cmdbci --sysparmquery operationalstatus=1^installstatus=1 --sysparm_limit 10
获取单条记录。
bash
node cli.mjs get incident id> --sysparmfields number,shortdescription,openedat
动态覆盖认证信息。
bash
node cli.mjs list incident --domain myinstance.service-now.com --username admin --password * --sysparm_limit 3
附件元数据和文件下载。
bash
node cli.mjs attach list --sysparmquery tablename=incident --sysparm_limit 5
node cli.mjs attach file --out /tmp/attachment.bin
聚合统计信息。
bash
node cli.mjs stats incident --sysparmquery active=true^priority=1 --sysparmcount true
服务目录只读 GET。
bash
node cli.mjs sc catalogs --sysparmtext laptop --sysparmlimit 5
node cli.mjs sc items --sysparmtext mac --sysparmlimit 5
node cli.mjs sc item
node cli.mjs sc item-variables
服务目录端点 仅 GET
- - cart
- delivery-address userid
- validate-categories
- on-change-choices entityid
- catalogs
- catalog sysid
- catalog-categories sysid
- category sysid
- items
- item sysid
- item-variables sysid
- item-delegation itemsysid usersysid
- producer-record producerid recordid
- record-wizard recordid wizardid
- generate-stage-pool quantity
- step-configs
- wishlist
- wishlist-item cartitemid
- wizard sysid
模式检查
如果您不确定字段名称,请使用此功能。
bash
node cli.mjs schema incident
读取工单历史记录
使用此功能读取完整对话,而不仅仅是当前状态。
bash
node cli.mjs history incident
专家预设
在 specialists/ 下创建 JSON 批处理文件,以一次执行多个读取操作。
- - specialists/incidents.json
每个条目支持 sysparm_* 字段以及以下项目。
- - name 批处理输出中的标签
- table 目标表
- sys_id 可选的单条记录获取
运行批处理预设。
bash
node cli.mjs batch specialists/incidents.json --pretty
输出
表 API 默认返回 JSON。结果出现在 result 下。
注意事项
- - 使用 sysparmlimit 保持结果集较小。
- 使用 sysparmfields 避免大型负载。
- 此技能设计为只读。
代理工具包摘要
- - list 和 get 显示记录的当前状态。
- attach 显示文件和截图。
- stats 显示分析和聚合数据。
- sc 显示请求的项目变量。
- schema 显示数据库映射以纠正错误。
- history 显示人工对话的时间线。
观察与备注(重要)
- - 服务目录端点可能根据目录内容和搜索文本返回空数组 — 尝试更具体的 --sysparmtext 术语或增加 --sysparmlimit。
- sysparmdisplayvalue 默认在表读取时启用,以返回人类友好的值(例如,用户名而非 sysid)。如果需要原始系统 ID,请传递 --sysparmdisplayvalue false。
- 对于代理发起的查询,保持 --sysparmlimit 较小,以避免大型负载和超时。对于计数或聚合数据,优先使用 stats,而不是下载多行数据。
- 附件:元数据可通过 attach list/attach get 获取;使用 attach file id> --out 下载二进制内容进行本地分析。
- 模式检查(schema)可避免猜测字段名称,是在读取未知表之前推荐的第一步。
- 历史记录(history)从 sysjournal_field 获取日志条目(评论/工作备注),对于读取工单的完整对话线程非常有用。
- 使用 --pretty 使 JSON 输出可读,便于人工审查,并帮助代理总结长结果。
推荐的批处理预设
我推荐 specialists/ 下的这些专家 JSON 预设,以加速常见的读取工作流程。它们是安全的(只读),并演示了如何组合相关读取。
1) specialists/inspectincidentschema.json — 事件模式检查:
json
[
{
name: schema-incident,
table: sys_dictionary,
sysparm_query: name=incident^elementISNOTEMPTY,
sysparmfields: element,columnlabel,internal_type,reference,
sysparm_limit: 500
}
]
2) specialists/incidenthistorytemplate.json — 历史记录模板(运行前将 ID> 替换为目标 sysid):
json
[
{
name: