Connecting to HPSM through REST api

Hi all, 

 

I'm new to the REST api I was wondering where I can find:

 

1) The documentation for using REST api in Java to connect to HPSM ticketing database?

 

2)Where can I find the configuration settings to connect to my HPSM?

 

Any help would be much appreciated.

 

Kind Regards, 

Mark

Top Replies

  • Hey, simply sign in to http://softwaresupport.hp.com and down load the Web Services manual for the version you are on.

     

    Here is a link to 9.34 document:-

     

    https://softwaresupport.hp.com/group/softwaresupport/search-result/-/facetsearch/document/KM01043337

     

    It's best to setup a seperate port for web service connections.

     

    Details are all in the manual.

     

    REST services can be set up via the extaccess records in the application.

     

     

  • I am using HPSM rest api to post incident and retirieving incidents, but when i invoke post(save incident) service through java with HTTP URL Connection,  Initially it is taking nearly 5 mins for creatign incident, and then it is taking 30 secs for saving incident, 10 secs form retrieving incidents.

    My client(java application) is reciding in different machine and hpsm is installed in different machine.

    I am using Normal java code to connect hpsm.

    URL url = new URL("<HPSM URL Located in remote machine>");
    		HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    		conn.setRequestMethod("GET Or POST");
    		conn.setRequestProperty("Accept", "application/json");

     It would be appreciable, if any one provide solution.

    Thanks.

  • @Balaji_HP

    Maybe its a network issue. I am guessign that since you told both applications are on different box. 

    How about a continuous ping to the HPSM server ?

    Also check if any anti-virus is runnign in HPSM server.

    AB

  • Hey thanks for your quick reply after first connection and posting incident info, for second onwards it is taking 30 secs. it has reduced from 5mins to 30 secs, even though it is big change,  30 secs also long duration and for retrieving it is taking nearly 9 secs.

  • hi abhin88,

    I have one question regarding hpsm rest service cookies, i am tring to use hpsm connection effectively for that i need to get cookie

    jsessionid from httpurlconnection response. but i am getting null that rest service is returning nothing in cookies.

    Is there any way to get cookie from hpsm rest service.

  • @KingMark,

    Following code works for me with user/password: falcon/1

    Get an incident by java:

     

    package com.company;
    import java.io.*;
    import java.net.*;
    public class Main {
        public static void main(String[] args) throws IOException {
            URL url = new URL("">localhost:13951/.../IM10002");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("GET");
            conn.setRequestProperty("Accept-Encoding", "gzip,deflate");
            conn.setRequestProperty("Authorization", "Basic ZmFsY29uOjE=");
            //conn.getResponseCode();
            BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }
            conn.disconnect();
        }
    }

    To create a new incident by java:

    package com.company;
    import java.io.*;
    import java.net.*;
    public class Main {
        public static void main(String[] args) throws IOException {
            URL url = new URL("">localhost:13951/.../incidents");
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            conn.setRequestMethod("POST");
            conn.setDoOutput(true);
            conn.setRequestProperty("Content-Type", "application/json");
            conn.setRequestProperty("Accept-Encoding", "gzip,deflate");
            conn.setRequestProperty("Authorization", "Basic ZmFsY29uOjE=");
            String input = "{ \t'Incident': \t{       'AlertStatus' : 'updated',       'Area' :'failure',       'Assignee' : 'Incident.Analyst',       'AssignmentGroup': 'Network',       'Category' : 'incident',       'ClosureCode' : 'Solved by Workaround',       'Company' : 'advantage',       'Contact' : 'FALCON, JENNIFER',       'ContactFirstName' :'FALCON',       'ContactLastName' : 'JENNIFER',       'Description' : [ 'test' ],       'Impact' : '2',       'JournalUpdates':  \t    [ '08/04/08 12:54:14 US/Mountain (falcon):',           'test',           '08/04/08 12:54:14 US/Mountain (falcon):',           'test'         ],       'Location':'advantage/North America',       'OpenTime' : '2007-09-02T07:51:00 00:00',       'OpenedBy':'Jurr.Fleijs',       'ProblemType' : 'incident',       'ResolutionFixType' : 'incident',       'SLAAgreementID' : 168,       'Service' : 'CI1001060',       'SiteCategory' : 'incident',       'Solution' : ['Solution by rest api'],       'Status' : 'Work In Progress',       'Subarea' :'function or feature not working',       'TicketOwner' : 'Jurr.Fleijs',       'Title' : 'test',       'UpdatedBy' : 'problem',       'UpdatedTime' : '2008-08-04T12:54:26 00:00',       'Urgency' : '3',       'UserPriority': '3 - Average',       'explanation' : ['test'],       'folder' :'advantage' \t} }";
            OutputStream os = conn.getOutputStream();
            os.write(input.getBytes());
            os.flush();
            //conn.getResponseCode();
            BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));
            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }
            conn.disconnect();
        }
    }

    Ling-Yan

     

     

  • Hey Ling-Yan,

    Thanks for your help on rest service connection. I did everything with hpsm rest sevice and integrate with my application succesfully. Un fortunately i have only 15 session to connect hpsm but my application has 20 concurrent users. Here i planned to get cookies from urlconnection and store in cache. when end user calls the api i am sending cookie in header of url connection. 

    Note: Here i am using Basic Authentication(different user) for get the different  cookies(Not Authenticator.setDefault)

    In my response header fields i can see only one cookie(i.e Set-Cookie: JSESSIONID=576SSDSDS657  /sm)

    While sending cookie to another url with out authorisation i am getting 401 (UnAuthorised) error.

    Please help me on this to reuse the session. so that i can use 15 session is very effectively. 

  • HI Can any one reply for this post.

  • Hi lingyanmeng,

    Is there any option to persistance sessions with hpsm rest(http) service. if yes please let me know the procedure how achieve it.

    i am using HttpUrlConnection for accesing rest service in java.