{"library":"sp-request","title":"Simplified SharePoint HTTP Client","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install sp-request"],"cli":null},"imports":["import * as sprequest from 'sp-request';","import * as sprequest from 'sp-request';\nconst spr = sprequest.create(credentialOptions);","const sprequest = require('sp-request');\nconst spr = sprequest.create(credentialOptions);"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/s-KaiNet/sp-request","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sp-request","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import * as sprequest from 'sp-request';\nimport * as process from 'process';\n\n// In a real application, retrieve these securely, e.g., from environment variables or a config service.\n// This example uses dummy values for demonstration. For specific auth types and options,\n// refer to the `node-sp-auth` documentation (https://github.com/s-KaiNet/node-sp-auth#params).\nconst credentialOptions = {\n  // Example for SharePoint Online App-Only via Client ID/Secret:\n  // clientId: process.env.SP_CLIENT_ID ?? 'your-client-id',\n  // clientSecret: process.env.SP_CLIENT_SECRET ?? 'your-client-secret',\n\n  // Example for SharePoint Online with ADFS/Forms auth via username/password:\n  username: process.env.SP_USERNAME ?? 'user@yourtenant.onmicrosoft.com',\n  password: process.env.SP_PASSWORD ?? 'YourSecurePassword123!',\n  siteUrl: process.env.SP_SITE_URL ?? 'https://yourtenant.sharepoint.com/sites/dev' // Your SharePoint site URL\n};\n\n// Create an authenticated sprequest instance\nconst spr = sprequest.create(credentialOptions);\n\n// Example: Get a SharePoint list by its title\nconst listTitle = 'Announcements'; // Replace with an actual list title in your site\nconst sharePointSiteUrl = credentialOptions.siteUrl; \n\nspr.get(`${sharePointSiteUrl}/_api/web/lists/GetByTitle('${listTitle}')`)\n  .then(response => {\n    if (response.body && response.body.d) {\n      console.log(`Successfully retrieved list: '${listTitle}'`);\n      console.log('List Id: ' + response.body.d.Id);\n      console.log('List Title: ' + response.body.d.Title);\n    } else {\n      console.log('Unexpected response structure:', response.body);\n    }\n  })\n  .catch(err => {\n    console.error(`Failed to retrieve list '${listTitle}':`);\n    if (err.response) {\n      console.error(`Status Code: ${err.response.statusCode}`);\n      console.error(`Response Body: ${JSON.stringify(err.response.body, null, 2)}`);\n    } else {\n      console.error(err);\n    }\n  });\n","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}