3
votes

I am trying to create new Projects within Microsoft Project Server 2013 from a java app, using the Project Server 2013 REST API, but am having troubles.

I can successfully get an atom+xml file of all the projects using the following (GET) :

String url = "http://<servername>/PWA/_api/ProjectServer/Projects";
HttpDigestAuthFilter filter = new HttpDigestAuthFilter("<username>", "<password>");
Client client = ClientBuilder.newClient(new ClientConfig());
client.register(filter);
WebTarget target = client.target(url);
Builder builder = target.request();
builder.accept(MediaType.APPLICATION_ATOM_XML);
InputStream inputStream = builder.get(InputStream.class);
try {
    String body = IOUtils.toString(inputStream);
    System.out.println("body : " + body);
} catch (IOException e) {
    e.printStackTrace();
}

However, I receive status=403, reason=FORBIDDEN when I try doing a POST using the following :

String url = "http://<servername>/PWA/_api/ProjectServer/Projects";
HttpDigestAuthFilter filter = new HttpDigestAuthFilter("<username>", "<password>");
Client client = ClientBuilder.newClient(new ClientConfig());
client.register(filter);
WebTarget target = client.target(url);
Builder builder = target.request();
Form form = new Form();
form.param("Name", "Test Project");
form.param("Title", "Test Project");
form.param("Description", "My Test Project from Java");
builder.header("X-RequestDigest", "form digest value");
builder.header("X-HTTP-Method", "POST");
builder.accept("application/json;odata=verbose");
Response response = builder.post(Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE));
System.out.println(response.getStatus() + " : " + response.toString());

That same user is successfully able to create new projects using the Project Web App (Project Center) website directly, but I need to be able to do this programmatically from my Java app.

I've tried (and failed) using the WSDLs (i.e. http ://servername/PWA/_vti_bin/psi/project.asmx?wsdl) that come with Project Server, but when I used Axis2 to generate the Java code, the generated java code could not handle the responses sent back from Project Server. The response from the Project Server would include diffgr:diffgram, and apparently, everything I really needed came inside that. Also, the response included an extra element for Project (PROJ_LAST_CHANGE_TOKEN) which was not in the WSDL.

I have also tried the C# code included in the Microsoft Project 2013 SDKs, but most of the files I tried either wouldn't compile, or didn't work as-is. I've read several forums which mention that the Microsoft website help pages and sample code for 2013 may have been copied from Project Server 2010, but although the actual APIs changed between 2010 and 2013, the sample code and MSDN websites have not been updated.

Has anyone successfully been able to create new Projects, and then been able to add new Tasks to an existing Project within Project Server 2013 from Java?

Thank you

1
Hi, from where you got the REST API? is it a JAR?iCode
Hello, I'm trying the code of the first snippet to get all projects from a project server with an https url and I receive a 403 response. Is there a different implementation when accessing project server with https url, have you ever tried something like this?jkonst

1 Answers

2
votes

The JSON should look like this:

{
  'parameters' : {
    'Id':'e19281cf-e8c8-4dfa-879c-75b8b3619426',
    'EnterpriseProjectTypeId':'09fa52b4-059b-4527-926e-99f9be96437a',
    'Name':'Test',
    'Description':'Test',
    'Start':'12/27/2013'
  }
}

The ID is your own generated GUID. The enterprise project type id is from the project type ids of your farm.