sn-http-request is a specialized JavaScript HTTP client designed specifically for interacting with ServiceNow instances. It aims to simplify common HTTP operations within the ServiceNow ecosystem by providing features such as automatic user token refresh, asynchronous request queuing, request cancellation, request/response interceptors, and efficient request batching (defaulting to batch requests within a 50ms window). The current stable version is 24.0.3, though its public release cadence might be slower as it's primarily intended for internal ServiceNow development. Its key differentiators compared to generic HTTP clients like Axios or the Fetch API include built-in XSRF token handling and request compression, making it optimized for ServiceNow's API landscape and reducing boilerplate for common tasks in that environment.
npm install sn-http-requestVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to create an `sn-http-request` client instance, configure it with base URL, authentication, and interceptors, and then perform a GET request to fetch a ServiceNow incident. It also includes an example for creating a new incident via a POST request.
Review the npm page and GitHub repository regularly for updates and consider this context when planning long-term dependencies. For general JavaScript HTTP needs outside of a ServiceNow context, alternatives like Axios or the native Fetch API might be more suitable.
Always consult ServiceNow API documentation for the specific API version you are targeting. Implement robust error handling and defensive programming (e.g., checking for property existence before access) to gracefully handle unexpected API changes. Keep `sn-http-request` updated to leverage any compatibility fixes.
To disable batching for a client instance, set `batching: false` in the `snHttpFactory` options. For individual requests, set `batch: false` within the request config (e.g., `snHttp.post('/users/1', { data: {fName: 'Fred'}, batch: false });`).Increase the `timeout` setting in your request configuration or `snHttpFactory` options. Verify network connectivity to the ServiceNow instance and check the instance's availability. Ensure the target API endpoint is correct and accessible. For server-side issues, check ServiceNow instance logs.
Verify that the `username` and `password` provided to `snHttpFactory` are correct for your ServiceNow instance and have the 'itil' role or other required permissions for the target API. Ensure any `xsrfToken` is correctly configured and still valid. Review ServiceNow security rules and API access policies.
Double-check the `baseURL` configured in `snHttpFactory` and the relative paths provided to `get`, `post`, etc. Ensure the ServiceNow API endpoint exists and is correctly spelled. Verify that the user account has access to the table or API being queried.