Dharshni
Dharshni

Reputation: 191

Sharepoint REST Api in Java: Unable to access site documents

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

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.

Upvotes: 0

Views: 812

Answers (1)

Francisco Valle
Francisco Valle

Reputation: 643

You can take a look of this project i've created for using the ShareopintRestAPI from java. I decided to make my own implementation as I've struggled a lot with other APIs i found and i was not able to make them work.

You can take a look here

https://github.com/kikovalle/PLGSharepointRestAPI-java

Upvotes: 0

Related Questions