I use Project Online to host Sharepoint 2013 with MS Project Server 2013. When I try to access https://my_company.sharepoint.com/sites/pwa/_api/ProjectData/Projects from my Restful Jersey client and after providing the right credentials I get a response with status type 403. The String that corresponds to the text body of the response is the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<m:error xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<m:code>-2147024891, System.UnauthorizedAccessException</m:code>
<m:message xml:lang="en-US">Access denied. You do not have permission to perform this action or access this resource.</m:message>
</m:error>
The code I'm using in order to authenticate and access the Rest API is the following:
String url = "https://myCompany.sharepoint.com/sites/pwa/_api/ProjectData/Projects";
try {
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter(username, pass));
WebResource webResource = client.resource(url);
ClientResponse response = (ClientResponse)webResource.type(MediaType.APPLICATION_ATOM_XML).get(ClientResponse.class);
InputStream inputStream = response.getEntityInputStream();
try {
String output = IOUtils.toString(inputStream);
System.out.println("output: "+output);
} catch(IOException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
I guess that the problem is somehow related with the https protocol that Project Online uses but I'm not sure. Any help would be appreciated.
X-RequestDigest
into your request. For this header value, just consume API POST your.sharepoint.com/_api/contextinfo with auth details and read FormDigestValue and pass this value as header into your request. This may solve you issue – PKhode