I am trying to access sharepoint site documents using SP REST API in java. I am able to authenticate and get a response for the below URL
http://sharepoint_server_url/_api/lists/getbytitle('Documents')
But I want to get the list of folders and files inside my site. I tried the following URL, but it gives me 401 Unauthorized.
http://sharepoint_server_url/sites/mysitename/_api/lists/getbytitle('Documents')
I am using the NTCredentials class, to authenticate. Please let me know if
- I have to make some setting in the Sharepoint server for mysite, so that I can access it through API?
- Or, The URL above is wrong, I have to change it?
This is the code used for authentication :
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(
new AuthScope(AuthScope.ANY),
new NTCredentials("username", "password", "http://server_DNS", "DOMAIN"));
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credsProvider)
.build();
HttpGet httpget = new HttpGet(url);
httpclient.execute(httpget);
I am sure someone must have done this already. Thanks in advance.