{"id":20859004,"url":"https://github.com/s-kainet/sp-request","last_synced_at":"2025-05-12T04:21:49.503Z","repository":{"id":7988640,"uuid":"57063320","full_name":"s-KaiNet/sp-request","owner":"s-KaiNet","description":"Simplified SharePoint HTTP client","archived":false,"fork":false,"pushed_at":"2024-07-06T12:53:39.000Z","size":581,"stargazers_count":53,"open_issues_count":9,"forks_count":9,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-31T22:02:12.427Z","etag":null,"topics":["javascript","node-sp","nodejs","request","sharepoint","sp-request","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/s-KaiNet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-25T17:51:10.000Z","updated_at":"2024-12-30T22:22:35.000Z","dependencies_parsed_at":"2024-11-18T04:48:26.975Z","dependency_job_id":"71ff088a-0160-4a0c-ad87-47961961d75a","html_url":"https://github.com/s-KaiNet/sp-request","commit_stats":{"total_commits":82,"total_committers":2,"mean_commits":41.0,"dds":"0.012195121951219523","last_synced_commit":"9f3b27dcc25cf3fe0deb266717fc38051d39909b"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-KaiNet%2Fsp-request","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-KaiNet%2Fsp-request/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-KaiNet%2Fsp-request/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/s-KaiNet%2Fsp-request/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/s-KaiNet","download_url":"https://codeload.github.com/s-KaiNet/sp-request/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253673321,"owners_count":21945584,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","node-sp","nodejs","request","sharepoint","sp-request","typescript"],"created_at":"2024-11-18T04:48:21.823Z","updated_at":"2025-05-12T04:21:49.476Z","avatar_url":"https://github.com/s-KaiNet.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sp-request - simplified SharePoint HTTP client\n\n[![npm version](https://badge.fury.io/js/sp-request.svg)](https://badge.fury.io/js/sp-request)\n\n---\n\u003e [!CAUTION]\n\u003e\n\u003e I don't use this module for many years and don't have time to actively maintain it. Thus no new versions are expected and no new features. Only your PR requests, if they are valid.\n\u003e\n\u003e Also, with Azure ACS and SharePoint Add-in model [retirement](https://techcommunity.microsoft.com/t5/microsoft-sharepoint-blog/sharepoint-add-in-retirement-in-microsoft-365/ba-p/3982035) some authentication methods for SharePoint Online will stop working after April, 2026.\n\n---\n\u003e [!IMPORTANT]\n\u003e This module doesn't work in browser. The only supported environment is nodejs. If you have a need to use it in browser, probably you're looking for [sp-rest-proxy](https://github.com/koltyakov/sp-rest-proxy) - a nodejs proxy, which redirects calls to real SharePoint.\n---\n `sp-request` is based on [got](https://github.com/sindresorhus/got/) (human-friendly and powerful HTTP request library for Node.js) and [node-sp-auth](https://github.com/s-KaiNet/node-sp-auth) modules. `node-sp-auth` implements different authentication options for unattended SharePoint authentication from nodejs. You can send REST queries to SharePoint (works with both on-prem and online) using `got` syntax with the same params that `got` supports, and `sp-request` (with help of `node-sp-auth`) takes care about authenticating you inside SharePoint.\n\n Versions supported:\n * SharePoint 2013 and onwards\n * SharePoint Online\n\n---\n\n## Upgrade from 2.x to 3.x\n\nIf you're upgrading to 3.x version, please read [Upgrade guide](/UpgradeTo3x.md)\n\n---\n\n### How to use:\n\n#### Install:\n\n```bash\nnpm install sp-request --save-dev\n```\n\n#### Create sprequest function:\n\n```javascript\nimport * as sprequest from 'sp-request';\nlet spr = sprequest.create(credentialOptions);\n```\n\n##### Get list by title:\n\n```javascript\nspr.get('http://sp2013dev/sites/dev/_api/web/lists/GetByTitle(\\'TestList\\')')\n  .then(response =\u003e {\n    console.log('List Id: ' + response.body.d.Id);\n  })\n  .catch(err =\u003e{\n    console.log('Ohhh, something went wrong...');\n  });\n```\n\n##### Update list title:\n\n```javascript\nspr.requestDigest('http://sp2013dev/sites/dev')\n  .then(digest =\u003e {\n    return spr.post('http://sp2013dev/sites/dev/_api/web/lists/GetByTitle(\\'TestList\\')', {\n      body: {\n        '__metadata': { 'type': 'SP.List' },\n        'Title': 'TestList'\n      },\n      headers: {\n        'X-RequestDigest': digest,\n        'X-HTTP-Method': 'MERGE',\n        'IF-MATCH': '*'\n      }\n    });\n  })\n  .then(response =\u003e {\n    if (response.statusCode === 204) {\n      console.log('List title updated!');\n    }\n  }, err =\u003e {\n    if (err.statusCode === 404) {\n      console.log('List not found!');\n    } else {\n      console.log(err);\n    }\n  });\n```\n\n... as simple as that! A bit more samples you can find under [integration tests](https://github.com/s-KaiNet/sp-request/blob/master/test/integration/integration.spec.ts)\n\n## API:\n\n### [main sp-request export].create(credentialOptions):\n\n- **_credentialOptions_:** optional, object containing credentials.\n  Since version 2.x `sp-request` relies on `node-sp-auth` module for authentication. You can find description for `credentialOptions` under [node-sp-auth](https://github.com/s-KaiNet/node-sp-auth#params).\n\nCall to `sprequest.create(credentialOption)` returns sprequest function with predefined authentication. You can use this function later to send REST queries (like in samples above) without specifying credentials again.\n### sprequest(options):\n\n - **_options_**: required, settings object for `got` module. For all available values refer to the original [got docs](https://github.com/sindresorhus/got)\n\nBy default `sp-request` sets following params for `got`:\n\n```\n{\n    responseType: 'json',\n    resolveBodyOnly: false,\n    rejectUnauthorized: false,\n    throwHttpErrors: true,\n    retry: 0,\n    headers: {\n        'Accept': 'application/json;odata=verbose',\n        'Content-Type': 'application/json;odata=verbose'\n    }\n}\n```\n\nas a result you can access `body.d` property as an object. You can provide your own headers and override defaults if it's required.\n\n### sprequest.requestDigest(url):\n\n - _url_ - required, string site url\n\nReturns request digest as string via promise.\n\n## Convenience methods:\n\n### sprequest(url, options):\n\n - _url_ - required, string\n - _options_ - optional, `got` options object\n\nThe same as `sprequest(options)` but `options.url` will be equal to the first param.\n\n### sprequest.get(url, options)\n\n - _url_ - required, string\n - _options_ - optional, `got` options object\n\nThe same as `sprequest(options)` but `options.url` will be equal to the first param and `options.method: 'GET'`.\n\n### sprequest.post(url, options)\n\n - _url_ - required, string\n - _options_ - optional, `got` options object\n\nThe same as `sprequest(options)` but `options.url` will be equal to the first param and `options.method: 'POST'`.\n\n## Supplying additional headers via environment variables\n\nSometimes you need to push additional headers for `sp-request` without direct access to `sp-request` object. For example from third party module, which uses `sp-request` internally. For that purpose you can use environmental variables. Provide it in a below way:\n\n```javascript\nprocess.env['_sp_request_headers'] = JSON.stringify({\n\t'X-FORMS_BASED_AUTH_ACCEPTED': 'f'\n});\n```\n## Default options set by `sp-request`\n\n```javascript\n{\n  responseType: 'json',\n  resolveBodyOnly: false,\n  rejectUnauthorized: false,\n  retry: 0\n}\n```\n\n## Development:\n\nI recommend using VS Code for development. Repository already contains some settings for VS Code editor.\n\nBefore creating Pull Request you need to create an appropriate issue and reference it from PR.\n\n1. `git clone https://github.com/s-KaiNet/sp-request.git`\n2. `npm run build` - restores dependencies and runs typescript compilation\n3. `gulp live-dev` - setup watchers and automatically runs typescript compilation, tslint and tests when you save files\n\n## Tests:\n\n1. `npm test`. As a result `/reports` folder will be created with test results in junit format and code coverage. Additionally test reports will be available in a console window.\n\n## Integration testing:\n\n1. Rename file `/test/integration/config.sample.ts` to `config.ts`.\n2. Update information in `config.ts` with appropriate values (urls, credentials, environment).\n3. Run `gulp test-int`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-kainet%2Fsp-request","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fs-kainet%2Fsp-request","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fs-kainet%2Fsp-request/lists"}