Clarity PPM1

Expand all | Collapse all

Use Java to access Clarity PPM REST API

Jump to Best Answer
  • 1.  Use Java to access Clarity PPM REST API

    Posted 08-16-2017 02:45 AM

    The following is a simple example to access project data from Clarity using Java. This example demonstrates how to use a Java build-in HTTP client library to implement a simple Clarity REST API client. We will use “java.net.URL” and “java.net.HttpURLConnection” to send a “GET” request to Clarity to access project data using project’s internal ID. The Response received from Clarity REST API in JSON format will be processed to display the key-value pairs.

     

    package com.clarity.rest.api;
    import java.io.*;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.io.IOException;
    import java.util.stream.Collectors;
    import com.niku.union.utility.Base64;
    import org.json.*;

    public class ReadProjectData {
         //Use a Clarity User Account having access to the project with project internal ID = 5020001
         private static String username = "******";
        private static String password = "******";
        //Clarity REST API URL to get single project data
        private static String urlREST = "https://clarity_url/ppm/rest/v1/projects/5020001";
        
        public static void main(String[] args) {
             
              try {
                   // Construct Base 64 Authenticate String
                   String b64 = username + ":" + password;
                   String basicAuth = "Basic " + Base64.encode(b64);
                   System.out.println ("basicAuth=" + basicAuth);
                   // Connection URL
                   URL url = new URL(urlREST);
                   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                   //HTTP Request Header
                   conn.setDoInput(true);
                   conn.setRequestMethod("GET");
                   conn.setRequestProperty("Content-type", "application/json");
                   conn.setRequestProperty("Accept", "application/json");
                   conn.setRequestProperty("cache-control", "no-cache");
                   conn.setRequestProperty("Authorization", basicAuth);
                   //Send HTTP GET Request
                   conn.connect();
                   //Check HTTP Response Code for success
                   if (conn.getResponseCode() != 200) {
                        System.out.println("Failed : HTTP error code : " + conn.getHeaderField(0));
                   } else {
                        //Process HTTP Response from Clarity REST API
                        BufferedReader br = new BufferedReader(new InputStreamReader(
                             (conn.getInputStream())));
                       
                        String fileData = br.readLine();
                        System.out.println ("fileData=" + fileData);
                        br.close();
                       
                        //Process REST API response data in JSON format
                        JSONObject jsonObj = new JSONObject(fileData);
                       
                        //Extract Name Vaue pairs from JSON object
                        for(int i = 0; i< jsonObj.names().length(); i++){
                             System.out.println ("Key = " + jsonObj.names().getString(i) + " | Value = " + jsonObj.get(jsonObj.names().getString(i)));
                        }
                   }
              } catch (MalformedURLException e) {
        
                   e.printStackTrace();
             
              } catch (IOException e) {
                   e.printStackTrace();
                  
              }catch (Exception e){//Catch exception if any
                    System.err.println("Error: " + e.getMessage());
        
              }
                  
         }

    }

     

    The following example provides a sample Java code to create a project in Clarity using REST API. 

     

    package com.clarity.rest.api;
    import java.io.*;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.io.IOException;
    import java.util.stream.Collectors;
    import com.niku.union.utility.Base64;
    import org.json.*;

    public class WriteProject {
         //Use a Clarity User Account having access to Clarity and rights to create project
         private static String username = "xxxxxxxx";
        private static String password = "xxxxxxx";
        //Clarity REST API URL to get single project data
        private static String urlREST = "https://clarity_url/ppm/rest/v1/projects";
        
        public static void main(String[] args) {
             
              try {
                   // Construct Base 64 Authenticate String
                   String b64 = username + ":" + password;
                   String basicAuth = "Basic " + Base64.encode(b64);
                   System.out.println ("basicAuth=" + basicAuth);
                   // Connection URL
                   URL url = new URL(urlREST);
                   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                   //HTTP Request Header
                   conn.setDoOutput(true);
                   conn.setRequestMethod("POST");
                   conn.setRequestProperty("Content-type", "application/json");
                   conn.setRequestProperty("Accept", "application/json");
                   conn.setRequestProperty("cache-control", "no-cache");
                   conn.setRequestProperty("Authorization", basicAuth);
                  
                   //Create Project write request in JSON format
                   JSONObject jsonObj = new JSONObject();
                  
                   jsonObj.put("code", "PROJ0001");
                   jsonObj.put("name", "Sample Test Project 1 - Created using REST API");
                   jsonObj.put("description", "This a Test Project Created using REST API");
                   jsonObj.put("scheduleStart", "2017-08-01T08:00:00");
                   jsonObj.put("scheduleFinish", "2017-08-31T17:00:00");
                  
                   //Send HTTP POST Request
                   OutputStreamWriter osw = new OutputStreamWriter(
                           (conn.getOutputStream()));
                     
                   osw.write(jsonObj.toString());
                  
                   osw.close();
                   //Check HTTP Response Code for success
                   if (conn.getResponseCode() != 200) {
                        System.out.println("Failed : HTTP error code : " + conn.getHeaderField(0));
                   } else {
                       
                        //Process HTTP Response from Clarity REST API
                       BufferedReader br = new BufferedReader(new InputStreamReader(
                            (conn.getInputStream())));
                      
                       String outputData = br.readLine();
                       System.out.println ("Project Write Output=" + outputData);
                       br.close();
                      
                       //Process REST API response data in JSON format
                       JSONObject jsonOut = new JSONObject(outputData);
                      
                       //Extract Name Vaue pairs from JSON object
                       for(int i = 0; i< jsonObj.names().length(); i++){
                            System.out.println ("Key = " + jsonObj.names().getString(i) + " | Value = " + jsonObj.get(jsonObj.names().getString(i)));
                       }
                       
                   }
              } catch (MalformedURLException e) {
        
                   e.printStackTrace();
             
              } catch (IOException e) {
                   e.printStackTrace();
                  
              }catch (Exception e){//Catch exception if any
                    System.err.println("Error: " + e.getMessage());
        
              }
                  
         }

    }

     

    The following Java example will edit an existing project record in Clarity using REST API. 

    package com.clarity.rest.api;
    import java.io.*;
    import java.net.HttpURLConnection;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.io.IOException;
    import java.util.stream.Collectors;
    import com.niku.union.utility.Base64;
    import org.json.*;

    public class UpdateProjectPartial {
         //Use a Clarity User Account having access to Clarity and rights to create project
         private static String username = "******";
        private static String password = "******";
        //Clarity REST API URL to get single project data
        private static String urlREST = "https://clarity_url/ppm/rest/v1/projects/5020005";
        
        public static void main(String[] args) {
             
              try {
                   // Construct Base 64 Authenticate String
                   String b64 = username + ":" + password;
                   String basicAuth = "Basic " + Base64.encode(b64);
                   System.out.println ("basicAuth=" + basicAuth);
                   // Connection URL
                   URL url = new URL(urlREST);
                   HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                   //HTTP Request Header
                   conn.setDoOutput(true);
                   conn.setRequestMethod("PUT");
                   conn.setRequestProperty("Content-type", "application/json");
                   conn.setRequestProperty("Accept", "application/json");
                   conn.setRequestProperty("cache-control", "no-cache");
                   conn.setRequestProperty("x-api-force-patch", "true");
                   conn.setRequestProperty("Authorization", basicAuth);
                  
                   //Create Project write request in JSON format
                   JSONObject jsonObj = new JSONObject();
                  
                  jsonObj.put("code", "PRJ00001");
                   jsonObj.put("name", "Sample Test Project 1 - Created using REST API - Updated");
                   jsonObj.put("description", "This a Test Project Created using REST API Updated");
                   jsonObj.put("scheduleStart", "2017-09-01T08:00:00");
                   jsonObj.put("scheduleFinish", "2018-12-31T17:00:00");
                   jsonObj.put("progress", "1");     //Started
                   jsonObj.put("percentComplete", "0.1");     //10%
                  
                   System.out.println("Request : " + jsonObj.toString());
                  
                   //Send HTTP POST Request
                   OutputStreamWriter osw = new OutputStreamWriter(
                           (conn.getOutputStream()));
                     
                   osw.write(jsonObj.toString());
                  
                   osw.close();
                   //Check HTTP Response Code for success
                   if (conn.getResponseCode() != 200) {
                        System.out.println("Failed : HTTP error code : " + conn.getHeaderField(0));
                   } else {
                       
                        //Process HTTP Response from Clarity REST API
                       BufferedReader br = new BufferedReader(new InputStreamReader(
                            (conn.getInputStream())));
                      
                       String outputData = br.readLine();
                       System.out.println ("Project Write Output=" + outputData);
                       br.close();
                      
                       //Process REST API response data in JSON format
                       JSONObject jsonOut = new JSONObject(outputData);
                      
                       //Extract Name Vaue pairs from JSON object
                       for(int i = 0; i< jsonObj.names().length(); i++){
                            System.out.println ("Key = " + jsonObj.names().getString(i) + " | Value = " + jsonObj.get(jsonObj.names().getString(i)));
                       }
                       
                   }
              } catch (MalformedURLException e) {
        
                   e.printStackTrace();
             
              } catch (IOException e) {
                   e.printStackTrace();
                  
              }catch (Exception e){//Catch exception if any
                    System.err.println("Error: " + e.getMessage());
        
              }
                  
         }

    }


  • 2.  Re: Use Java to access Clarity PPM REST API

    Posted 08-21-2017 07:30 AM

    Isn't REST API no longer being supported?

     

    From 15.1 documentation: https://docops.ca.com/ca-ppm/15-1/en/reference/rest-apis

     

    Important!

    The CA PPM REST APIs can only be used by CA PPM engineering. At this time, the REST APIs are not supported for customer or partner use.

    Our strategy is to focus on developing robust APIs as we design our new user experience. The APIs may change as we make architectural improvements, add capabilities and optimize performance. We will review our strategy every release and make the APIs publicly available as soon as possible.

    While the APIs are not intended for public use, the associated documentation is available for use by both internal and external stakeholders. This documentation will eventually form the foundation for the public REST API documentation.



  • 3.  Re: Use Java to access Clarity PPM REST API

    Posted 08-21-2017 09:15 AM

    API is not supported to be used till now, however product uses the API internally

     

    Regards

    Suman Pramanik 



  • 4.  Re: Use Java to access Clarity PPM REST API

    Posted 08-22-2017 03:19 AM

    Hi Suman,

     

    I could not understand the above statement. we are using CA PPM 14.3.

     

    Can you please clarify If we can use the CA PPM REST API Interface with other applications?

     

    Regards,

    Rajkumar



  • 5.  Re: Use Java to access Clarity PPM REST API

    Posted 08-22-2017 03:29 AM

    Hi Rajkumar,

     

    API's are exposed but not supported to be used except CA Engineering team. You can use at your own risk but we won';t support it as of now and thats the reason we have documented the same

     

    Important!

    The CA PPM REST APIs can only be used by CA PPM engineering. At this time, the REST APIs are not supported for customer or partner use.

    Our strategy is to focus on developing robust APIs as we design our new user experience. The APIs may change as we make architectural improvements, add capabilities and optimize performance. We will review our strategy every release and make the APIs publicly available as soon as possible.

    While the APIs are not intended for public use, the associated documentation is available for use by both internal and external stakeholders. This documentation will eventually form the foundation for the public REST API documentation.

     

    Regards

    Suman Pramanik



  • 6.  Re: Use Java to access Clarity PPM REST API
    Best Answer

    Posted 08-25-2017 02:37 AM

    From 14.3 documentation https://docops.ca.com/ca-ppm-saas/14-3/en/ca-ppm-14-3-release-information/release-notes-saas

    CA PPM SaaS REST APIs

    CA PPM SaaS REST APIs allow partners and customers to build more flexible integrations that should be compatible with future product releases. The REST APIs feature includes:
    •REST APIs for Project and Task Objects: A core set of project and task attributes are accessible using the CA PPM SaaS REST APIs.
    •Web-based and interactive API documentation where you can execute API commands against your CA PPM SaaS instance.
    •New Integration Studio object that provides an area where partners and customers can configure and track any integration with CA PPM SaaS. The Rally integration utilizes the Integration object and provides an example on how to set up and configure an integration using this new object.

     

    I would personally request verification from CA on REST, as I am just copying from documentation which I had to previously undertook recently when we were looking at what was available for PPM SaaS implementations.

     

    You may want to consider looking at SOAP which we are using to pull Clarity data out to other applications.  SOAP also supports Clarity data updates.  It is also used in Clarity GEL scripts. 



  • 7.  Re: Use Java to access Clarity PPM REST API

    Posted 08-25-2017 03:13 AM

    Ronald - You are absolutely correct, we have API's available but we don't support it for customers use yet. 



  • 8.  Re: Use Java to access Clarity PPM REST API

    Posted 03-26-2019 10:45 AM

    Suman,

     

    So REST API for PPM is not supported for customers use yet? What is the latest on this?

     

    Thanks!



  • 9.  Re: Use Java to access Clarity PPM REST API

    Posted 03-26-2019 11:04 AM


  • 10.  Re: Use Java to access Clarity PPM REST API

    Posted 03-29-2019 02:47 PM

    Thank you very much Suman!



  • 11.  RE: Use Java to access Clarity PPM REST API

    Posted 09-18-2019 08:04 AM
    Hi, where in the clarity folder can I find the  package com.clarity.rest.api or the jar file that has the api class.


  • 12.  RE: Use Java to access Clarity PPM REST API

    Posted 09-19-2019 08:41 AM
    All the jars are kept under lib folders

    ------------------------------
    Thanks & Regards
    Suman Pramanik
    Principal Support Engineer | Customer Success & Support, Enterprise Software Division
    Broadcom
    ------------------------------



  • 13.  RE: Use Java to access Clarity PPM REST API

    Posted 09-23-2019 08:52 AM
    To clarify, if you're referring to the java example provided in the original poster's message, then that is just the package name given TO the code in the example, it isn't something you find.

    Connecting to and using the REST services outside of Clarity should not need or use any jar files or packages from within the Clarity installation's lib folders.

    As the examples show, from Java, you can send/receive data by constructing http requests with the appropriate headers and a correctly formed REST resource url (and parameters), with an optional JSON body where needed.


  • 14.  RE: Use Java to access Clarity PPM REST API

    Posted 09-25-2019 07:59 AM
    Thanks Nick, Highly appreciated


  • 15.  RE: Use Java to access Clarity PPM REST API

    Posted 09-26-2019 05:12 AM
    Hi All,
    I am getting an error in the code Failed : HTTP error code : HTTP/1.1 401 when using the url
    http://servername:portnumber/ppm/rest/v1/projects/5039000/?fields=objective,name  -- I have replaced the actual servername with servername and port number just to hide it on this forum.

    I used postman to authenticate the url http://servername:portnumber/ppm/rest/v1 but I get the same error.

    Please note I am using the ca ppm admin user which has the api access rights and all admin rights.

    Thanks



  • 16.  RE: Use Java to access Clarity PPM REST API

    Posted 09-26-2019 05:48 AM
    I have now got this working, many thanks.


  • 17.  RE: Use Java to access Clarity PPM REST API

    Posted 09-25-2019 08:23 AM
    Thanks Much Appreciated