ServiceNow REST API获取KB文章的请求响应JSON格式咨询
ServiceNow REST API: Request & Response for KB Article Search by short_description
I’ve worked extensively with ServiceNow’s REST API for KB retrieval scenarios, so let’s break down exactly what you need for your POC.
Request Format
Your sample endpoint is on the right track—here’s how to structure the request properly, including critical details like authentication (required for all ServiceNow API calls):
Core Request Details
- Method: GET
- Endpoint:
https://myinstance.service-now.com/api/now/table/kb_knowledge - Key Query Parameters:
sysparm_query: Filters KB articles whereshort_descriptioncontains "VPN Access" (case sensitivity depends on your instance’s configuration)- Optional:
sysparm_fieldsto limit returned fields (e.g.,short_description,description,number,sys_idto only pull the data you need for your web display) - Optional:
sysparm_limitto control the number of results returned
Sample cURL Request
curl --location --request GET 'https://myinstance.service-now.com/api/now/table/kb_knowledge?sysparm_query=short_descriptionLIKE%20VPN%20Access&sysparm_fields=short_description,description,number,sys_id' \ --header 'Authorization: Basic YOUR_BASE64_ENCODED_CREDENTIALS' \ --header 'Accept: application/json'
Response Schema & Embedded KB Article Structure
The response wraps matching KB articles in a result array—this is where your target data lives. Each item in the array is a full KB record (or a subset if you used sysparm_fields), with fields directly mapped to ServiceNow’s KB table columns.
Sample JSON Response
{ "result": [ { "sys_id": "abc123xyz456", "number": "KB0010001", "short_description": "Troubleshoot VPN Access Issues", "description": "<p>Follow these steps to resolve VPN access problems:</p><ol><li>Check your internet connection stability</li><li>Verify your VPN client is running the latest version</li><li>Restart your device and attempt to reconnect</li></ol>" }, { "sys_id": "def789ghi012", "number": "KB0010002", "short_description": "Request New VPN Access", "description": "<p>To request VPN access for your role:</p><ol><li>Submit a ticket via the company Service Portal</li><li>Attach manager approval and your department ID</li><li>Allow 24-48 hours for IT to provision access</li></ol>" } ] }
Key Notes on Embedded KB Data
resultArray: This is the top-level property containing all matching KB articles. Each element represents a single KB record.- Solution Steps: The
descriptionfield holds the formatted solution content (usually HTML, as seen in the sample)—this is what you’ll want to render directly in your web page. - Additional Context Fields:
number(public KB article ID),sys_id(unique internal record ID), andactive(published status) are useful if you need to add extra context to your display.
Practical Considerations
- Authentication: You must include valid credentials (Basic Auth is standard for POCs). Encode your
username:passwordas Base64 for theAuthorizationheader. - Refined Filtering: Enhance the
sysparm_queryto get more relevant results (e.g., addactive=trueto only pull published articles:short_descriptionLIKE VPN%20Access^active=true). - Pagination: If there are many matching articles, use
sysparm_offsetandsysparm_limitto paginate through results efficiently.
内容的提问来源于stack exchange,提问作者kishore ilaka




