{"id":318,"date":"2023-06-01T11:17:56","date_gmt":"2023-06-01T08:17:56","guid":{"rendered":"https:\/\/kb.astrocroc.com\/?p=318"},"modified":"2023-06-01T11:17:56","modified_gmt":"2023-06-01T08:17:56","slug":"%d0%bf%d0%be%d0%b4%d0%ba%d0%bb%d1%8e%d1%87%d0%b8%d1%82%d1%8c%d1%81%d1%8f-%d0%ba-sharepoint-%d1%81-%d0%bf%d0%be%d0%bc%d0%be%d1%89%d1%8c%d1%8e-nodejs","status":"publish","type":"post","link":"https:\/\/kb.astrocroc.com\/?p=318","title":{"rendered":"\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a SharePoint \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e NodeJS"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/h4>\n\n\n\n<p>\u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c, \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-bash\" data-line=\"\">npm i node-sp-auth request-promise gd-sprest<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/github.com\/s-KaiNet\/node-sp-auth\">node-sp-auth<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0432 SharePoint.<\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/request\/request-promise\">\u0437\u0430\u043f\u0440\u043e\u0441-\u043e\u0431\u0435\u0449\u0430\u043d\u0438\u0435,<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/li>\n\n\n\n<li><a href=\"https:\/\/github.com\/gunjandatta\/sprest\">gd-sprest<\/a> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0444\u043e\u0440\u043c\u0430\u0442\u0430 HTTP-\u0437\u0430\u043f\u0440\u043e\u0441\u0430.<\/li>\n<\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">\u0418\u043c\u043f\u043e\u0440\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a<\/h4>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b \u0441\u043a\u0440\u0438\u043f\u0442\u0430.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\" data-line=\"\">var spauth = require(&#039;node-sp-auth&#039;);\nvar request = require(&#039;request-promise&#039;);\nvar $REST = require(&quot;gd-sprest&quot;);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a SharePoint<\/h4>\n\n\n\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b, \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a SharePoint. \u0441\u043c. \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 <a href=\"https:\/\/github.com\/s-KaiNet\/node-sp-auth\">.<\/a> \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0430\u043c \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a SPO.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\" data-line=\"\">\/\/ Log\nconsole.log(&quot;Connecting to SPO&quot;);\n\n\/\/ Connect to SPO\nvar url = &quot;https:\/\/[tenant].sharepoint.com\/sites\/dev&quot;;\nspauth.getAuth(url, {\n    username: &quot;[SPO Login]&quot;,\n    password: &quot;[SPO Password]&quot;,\n    online: true\n}).then(options =&gt; {\n    \/\/ Log\n    console.log(&quot;Connected to SPO&quot;);\n});\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441<\/h4>\n\n\n\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u0434\u0430 \u0431\u0443\u0434\u0443\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u044b \u0444\u0430\u0439\u043b\u044b, \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u043f\u043e\u0434\u043f\u0430\u043f\u043a\u0435 \u00absprest\u00bb \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u00ab\u0410\u043a\u0442\u0438\u0432\u044b \u0441\u0430\u0439\u0442\u0430\u00bb. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <a href=\"https:\/\/dattabase.com\">\u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 $REST gd-sprest<\/a> \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0435.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">API REST \u0434\u043b\u044f SharePoint Intellisense<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1001\" height=\"432\" src=\"https:\/\/kb.astrocroc.com\/wp-content\/uploads\/2023\/06\/intellisense.png\" alt=\"\" class=\"wp-image-319\" srcset=\"https:\/\/kb.astrocroc.com\/wp-content\/uploads\/2023\/06\/intellisense.png 1001w, https:\/\/kb.astrocroc.com\/wp-content\/uploads\/2023\/06\/intellisense-300x129.png 300w, https:\/\/kb.astrocroc.com\/wp-content\/uploads\/2023\/06\/intellisense-768x331.png 768w\" sizes=\"auto, (max-width: 1001px) 100vw, 1001px\" \/><\/figure>\n\n\n\n<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 <a href=\"https:\/\/dattabase.com\">gd-sprest<\/a> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 Intelliense.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\" data-line=\"\">\/\/ Get the web\nvar info = $REST.Web(url)\n\/\/ Get the &#039;Site Assets&#039; library\n.Lists(&quot;Site Assets&quot;)\n\/\/ Get the root folder\n.RootFolder()\n\/\/ Get the &#039;sprest&#039; sub-folder\n.Folders(&quot;sprest&quot;)\n\/\/ Get the files in the folder\n.Files()\n\/\/ Get the request information\n.getInfo();<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u0418\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u0430<\/h4>\n\n\n\n<p>\u0427\u0442\u043e\u0431\u044b \u0437\u0430\u043f\u0440\u043e\u0441 \u0431\u044b\u043b \u0443\u0441\u043f\u0435\u0448\u043d\u044b\u043c, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u043a\u043e\u043f\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430 \u0438\u0437 \u0430\u0443\u0442\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 SP.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\" data-line=\"\">\/\/ Copy the headers from the SP authentication\nfor (var key in options.headers) {\n    \/\/ Set the header\n    info.headers[key] = options.headers[key];\n}<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u0412\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441<\/h4>\n\n\n\n<p>\u041c\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u0437\u0430\u043f\u0440\u043e\u0441 Get\/Post \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u0442\u0438\u043f\u0430. \u0441\u043c. \u0432 <a href=\"https:\/\/github.com\/request\/request-promise\">\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438<\/a> \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 . \u041e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u043c JSON, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043b\u0435\u0433\u043a\u043e \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u0432 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0443\u044e. \u0412 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0435\u0442\u0441\u044f \u043d\u0430\u0431\u043e\u0440 \u0444\u0430\u0439\u043b\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u043c \u00ab\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b\u00bb \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0444\u0430\u0439\u043b \u043d\u0430 \u043a\u043e\u043d\u0441\u043e\u043b\u044c.<\/p>\n\n\n\n<pre class=\"wp-block-prismatic-blocks\"><code class=\"language-javascript\" data-line=\"\">\/\/ Execute the request, based on the method\nrequest[info.method == &quot;GET&quot; ? &quot;get&quot; : &quot;post&quot;]({\n    headers: info.headers,\n    url: info.url,\n    body: info.data\n}).then(\n    \/\/ Success\n    response =&gt; {\n        var obj = JSON.parse(response).d;\n        if (obj.results &amp;&amp; obj.results.length &gt; 0) {\n            \/\/ Parse the results\n            for (var i = 0; i &lt; obj.results.length; i++) {\n                \/\/ Log\n                console.log(obj.results[i]);\n            }\n        } else {\n            \/\/ Log\n            console.log(obj);\n        }\n    },\n    \/\/ Error\n    error =&gt; {\n        \/\/ Log\n        console.log(&quot;Error executing the request&quot;, error);\n    }\n);<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">\u041f\u0440\u0438\u043c\u0435\u0440 \u0432\u044b\u0432\u043e\u0434\u0430<\/h4>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"718\" height=\"522\" src=\"https:\/\/kb.astrocroc.com\/wp-content\/uploads\/2023\/06\/output.png\" alt=\"\" class=\"wp-image-320\" srcset=\"https:\/\/kb.astrocroc.com\/wp-content\/uploads\/2023\/06\/output.png 718w, https:\/\/kb.astrocroc.com\/wp-content\/uploads\/2023\/06\/output-300x218.png 300w\" sizes=\"auto, (max-width: 718px) 100vw, 718px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u041f\u0435\u0440\u0432\u043e\u0435, \u0447\u0442\u043e \u043c\u044b \u0441\u0434\u0435\u043b\u0430\u0435\u043c, \u044d\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0418\u043c\u043f\u043e\u0440\u0442 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u0432 \u0444\u0430\u0439\u043b \u0441\u043a\u0440\u0438\u043f\u0442\u0430. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a SharePoint \u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b, \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a SharePoint. \u0441\u043c. \u0432 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 . \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043a \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c \u0441\u0440\u0435\u0434\u0430\u043c \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043c\u044b \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c\u0441\u044f \u043a SPO. \u0421\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,11],"tags":[26,32,33],"class_list":["post-318","post","type-post","status-publish","format-standard","hentry","category-node-js","category-sharepoint","tag-node-js","tag-rest-api","tag-sharepoint"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/318","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=318"}],"version-history":[{"count":1,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions"}],"predecessor-version":[{"id":321,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=\/wp\/v2\/posts\/318\/revisions\/321"}],"wp:attachment":[{"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=318"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kb.astrocroc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}