This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

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

Parents
  • @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

     

     

Reply
  • @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

     

     

Children
  • 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.