sp-request is a Node.js-specific HTTP client designed for simplified interaction with SharePoint REST APIs, supporting SharePoint 2013, SharePoint Online, and later versions. It is currently at version 3.0.0. The library abstracts SharePoint authentication using `node-sp-auth` and leverages the `got` library for making HTTP requests, providing a consistent API similar to `got`. This combination allows developers to send REST queries with various authentication options without manually managing authentication flows or request digests. It is strictly for server-side (Node.js) usage and does not support browser environments. While a specific release cadence isn't detailed, the presence of a 3.x upgrade guide indicates ongoing development. Key differentiators include its focus on Node.js, seamless integration with `node-sp-auth` for diverse authentication strategies, and a `got`-like request syntax.
npm install sp-requestVerified import paths — ran on the pinned version, not inferred.
Demonstrates installation, creating an authenticated `sp-request` instance, and performing a basic GET request to retrieve a SharePoint list by title using environment variables for credentials.
Refer to the official `sp-request` upgrade guide for detailed instructions on migrating your codebase from 2.x to 3.x.
For browser-based SharePoint interactions, consider using `sp-rest-proxy` in conjunction with `PnPjs` or similar client-side libraries. `sp-request` is server-side only.
Carefully review the `node-sp-auth` documentation (https://github.com/s-KaiNet/node-sp-auth#params) to ensure `credentialOptions` are correctly configured for your specific SharePoint environment and desired authentication method.
For production deployments, ensure `rejectUnauthorized` is explicitly set to `true` (if possible for your environment) or that proper certificate trust is established. Be aware that this default simplifies initial setup but should be addressed for security.
Double-check all `credentialOptions` (siteUrl, username, password, client ID/secret), verify network connectivity to the SharePoint instance, and ensure the SharePoint URL is correct and accessible from the Node.js host.
Verify the SharePoint REST API endpoint and object identifiers (e.g., list title, item ID) are accurate. Confirm the authenticated user has appropriate permissions to the resource.
Review the SharePoint ULS logs (for on-prem) or SharePoint diagnostic logs (for Online) to get more details about the server error. Ensure the request body, headers, and API calls conform to SharePoint's expectations. Regenerate `X-RequestDigest` if applicable.