{"id":3840,"date":"2018-02-24T23:11:48","date_gmt":"2018-02-24T19:11:48","guid":{"rendered":"https:\/\/nayarweb.com\/blog\/?p=3840"},"modified":"2018-02-24T23:11:53","modified_gmt":"2018-02-24T19:11:53","slug":"playing-with-microsofts-sharepoint-rest-api","status":"publish","type":"post","link":"https:\/\/nayarweb.com\/blog\/2018\/playing-with-microsofts-sharepoint-rest-api\/","title":{"rendered":"Playing with Microsoft&#8217;s Sharepoint REST API"},"content":{"rendered":"<p>I couldn&#8217;t get Sharepoint to be loaded as an External Storage in Nextcloud. I had find a way to use the old school `curl` to debug the problem.<\/p>\n<p>To properly authenticate, you will have to add some extra parameters to curl<\/p>\n<blockquote>\n<p class=\"p1\"><span class=\"s1\">$ curl &#8211;ntlm &#8211;negotiate -u &lt;Domain&gt;\/&lt;Username&gt;:&lt;Password&gt; &#8220;http:\/\/&lt;url&gt;\/&lt;site&gt;\/_api\/Web\/getfolderbyserverrelativeurl(&#8216;%2F&lt;site&gt;\/&lt;Folder&gt;&#8217;)?$select=Length,TimeLastModified&#8221; -v<\/span><\/p>\n<\/blockquote>\n<p>Notice the `<span class=\"s1\">&#8211;ntlm &#8211;negotiate`. These parameters enable &#8220;NTLM Authentication Scheme for HTTP&#8221; rather that the usual HTTP Basic Auth. This in turns make lots of back and forth between the curl and MS Sharepoint. <\/p>\n<p><a href=\"https:\/\/nayarweb.com\/blog\/2018\/playing-with-microsofts-sharepoint-rest-api\/screen-shot-2018-02-24-at-23-05-45\/\" rel=\"attachment wp-att-3846\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-24-at-23.05.45.png\" alt=\"\" width=\"549\" height=\"242\" class=\"aligncenter size-full wp-image-3846\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-24-at-23.05.45.png 549w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-24-at-23.05.45-300x132.png 300w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/a><\/p>\n<p>The logs of my HAProxy looks like this. We can see that the curl request has made 3 HTTP requests.<\/p>\n<p><code><\/p>\n<pre>\r\nweb sharepoint\/sharepoint 0\/0\/1\/8\/9 <strong>401<\/strong> 503 - - ---- 2\/2\/0\/1\/0 0\/0 \"GET \/my\/_api\/Web\/getfolderbyserverrelativeurl('%2Fmy\/MeraDocs')?=Length,TimeLastModified HTTP\/1.1\"\r\nweb sharepoint\/sharepoint 0\/0\/0\/8\/8 <strong>401<\/strong> 830 - - ---- 2\/2\/0\/1\/0 0\/0 \"GET \/my\/_api\/Web\/getfolderbyserverrelativeurl('%2Fmy\/MeraDocs')?=Length,TimeLastModified HTTP\/1.1\"\r\nweb sharepoint\/sharepoint 0\/0\/0\/15\/18 <strong>200<\/strong> 3314 - - ---- 2\/2\/0\/1\/0 0\/0 \"GET \/my\/_api\/Web\/getfolderbyserverrelativeurl('%2Fmy\/MeraDocs')?=Length,TimeLastModified HTTP\/1.1\"\r\n<\/pre>\n<p><\/code><\/p>\n<p>However I was getting a 404 response in the third response initially. Turns out the API endpoints are different for OneDrive, SharePoint Online and SharePoint Server 2016:<\/p>\n<p><a href=\"https:\/\/nayarweb.com\/blog\/2018\/playing-with-microsofts-sharepoint-rest-api\/screen-shot-2018-02-24-at-23-04-57\/\" rel=\"attachment wp-att-3845\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-24-at-23.04.57.png\" alt=\"\" width=\"717\" height=\"200\" class=\"aligncenter size-full wp-image-3845\" srcset=\"https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-24-at-23.04.57.png 717w, https:\/\/nayarweb.com\/blog\/wp-content\/uploads\/2018\/02\/Screen-Shot-2018-02-24-at-23.04.57-300x84.png 300w\" sizes=\"auto, (max-width: 717px) 100vw, 717px\" \/><\/a><\/p>\n<p>Since I was using SharePoint Server locally, I chose the 2nd endpoint and it worked perfect. <\/p>\n<p>[1]\u00a0http:\/\/www.commandlinefu.com\/commands\/view\/7005\/get-a-file-from-sharepoint-with-curl<\/p>\n<p>[2]\u00a0https:\/\/stackoverflow.com\/questions\/15697157\/using-curl-with-ntlm-auth-to-make-a-post-is-failing<\/p>\n<p>[3]\u00a0https:\/\/docs.microsoft.com\/en-us\/onedrive\/developer\/rest-api\/getting-started\/sharepoint-server-2016<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I couldn&#8217;t get Sharepoint to be loaded as an External Storage in Nextcloud. I had find a way to use the old school `curl` to debug the problem. To properly authenticate, you will have to add some extra parameters to curl $ curl &#8211;ntlm &#8211;negotiate -u &lt;Domain&gt;\/&lt;Username&gt;:&lt;Password&gt; &#8220;http:\/\/&lt;url&gt;\/&lt;site&gt;\/_api\/Web\/getfolderbyserverrelativeurl(&#8216;%2F&lt;site&gt;\/&lt;Folder&gt;&#8217;)?$select=Length,TimeLastModified&#8221; -v Notice the `&#8211;ntlm &#8211;negotiate`. These parameters &hellip; <a href=\"https:\/\/nayarweb.com\/blog\/2018\/playing-with-microsofts-sharepoint-rest-api\/\" class=\"continue-reading\">Continue reading <span class=\"screen-reader-text\">Playing with Microsoft&#8217;s Sharepoint REST API<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[210,1],"tags":[],"class_list":["post-3840","post","type-post","status-publish","format-standard","hentry","category-technology","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/3840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/comments?post=3840"}],"version-history":[{"count":9,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/3840\/revisions"}],"predecessor-version":[{"id":3851,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/posts\/3840\/revisions\/3851"}],"wp:attachment":[{"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/media?parent=3840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/categories?post=3840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nayarweb.com\/blog\/wp-json\/wp\/v2\/tags?post=3840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}