Highlighted
New Member.
3847 views

Rest api for Retreive incidents in the range of dates

Jump to solution

Hi, I have integrated rest full api with my application successfully, now i have one requiremnt where i have to get the incidents in the range of dates.  I have search for the query lot, but no luck.

Example: have to get list of all closed incidents in between 1st Feb to 5th Feb .

Can any one help me to acheive the same.

Thanks

Tags (2)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

Try following code, it works for me:

curl -XGET -H "Authorization: Basic ZmFsY29uOjE=" -H "Accept-Encoding: gzip,deflate" "http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'%20and%20OpenTime<'12/12/2016'"

or java code:

package com.company;
import java.io.*;
import java.net.*;
public class Main {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'%20and%20OpenTime<'12/12/2016'&view=expand");
        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();
    }
}

Ling-Yan

 

 

View solution in original post

14 Replies
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: Rest api for Retreive incidents in the range of dates

Jump to solution
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

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

curl -XGET -H "Authorization: Basic ZmFsY29uOjE=" -H "Accept-Encoding: gzip,deflate" "http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'&view=expand"

And following java code works for me as well:

package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.*;
public class Main {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'&view=expand");
        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();
    }
}

And for more syntax, you can reference to the url Tom mentioned.

Let me know if it helps,

Ling-Yan

Highlighted
New Member.

Re: Rest api for Retreive incidents in the range of dates

Jump to solution
Thanks for your quick response, It's  working fine. But When i send the below req, it is getting all the incidents maches with first condition
and second condtion. I am not getting incident in between thosed dates i am all records. is it possible to get incident in between those
two dates.
 
http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'&OpenTime<'11/27/2015' &view=expand

 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

Try following code, it works for me:

curl -XGET -H "Authorization: Basic ZmFsY29uOjE=" -H "Accept-Encoding: gzip,deflate" "http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'%20and%20OpenTime<'12/12/2016'"

or java code:

package com.company;
import java.io.*;
import java.net.*;
public class Main {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'%20and%20OpenTime<'12/12/2016'&view=expand");
        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();
    }
}

Ling-Yan

 

 

View solution in original post

Highlighted
New Member.

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

Hey thanks for your help. It worked. 

And one more question is, Is it possible to get Additional fields(to display in UI) with respect to Category, Area, SubArea through rest service. If it is not possible how can i get addition fields  from HPSM data base. 

Where these additional fiels will stay and what is the mapping behind it. if possible please send me the link to get the information.

 

 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

@Balaji_HP,

You can get all the values by adding the view=expand:

 

curl -XGET -H "Authorization: Basic ZmFsY29uOjE=" -H "Accept-Encoding: gzip,deflate" "http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'%20and%20OpenTime<'12/12/2016'&view=expand"

And the mapping is in the web service configuration

2017-02-23_16-03-17.jpg

 

 

for more information, check the help:

http://docs.software.hpe.com/SM/9.50/Codeless/Content/integrations/web_services/concepts/web_services.htm

Let me know if it helps,

Ling-Yan

 

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

@Balaji_HP,

You can get all the values by adding the view=expand:

 

curl -XGET -H "Authorization: Basic ZmFsY29uOjE=" -H "Accept-Encoding: gzip,deflate" "http://localhost:13951/SM/9/rest/incidents?OpenTime>'11/25/2015'%20and%20OpenTime<'12/12/2016'&view=expand"

And the mapping is in the web service configuration

2017-02-23_16-03-17.jpg

 

 

for more information, check the help:

 http://docs.software.hpe.com/SM/9.50/Codeless/Content/integrations/web_services/concepts/web_services.htm

Let me know if it helps,

Ling-Yan

 

Highlighted
New Member.

Re: Rest api for Retreive incidents in the range of dates

Jump to solution
Hi
 
Thanks for your valuable time spent for my interactions. I need one more api to approve and deny tickets.
What's my requirement is, As of now i am displaying all tickets to approve for manager, now i need  a rest service
to approve/deny the ticket(interaction)  along with comments.
Please let me know if you have any rest service for the above requirement.
 
 
Regards
0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

@Balaji_HP,

I believe you got the idea on the restful API. And you can find more syntex in the help server.

I don't have an API in hand now.

Ling-Yan

0 Likes
Highlighted
New Member.

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

Hey Lingyanmeng,

Sorry for asking again, After having look at google, i got below api for approval.

<server>:<port>/SM/9/rest/changes/{header,number}/action/approve. 

I am listing all pending incidents(having ChangeID) from below rest service 

<server>:<port>/SM/9/rest/changes?current.pending.groups=<EMPID>&ApprovalStatus=pending&view=expand

So now i have to give option to approve for EMPID(Manager), I dont know what is header,number but i have set that as ChangeId and i called following rest service

<server>:<port>/SM/9/rest/changes/<ChangeId>/action/approve?current.pending.groups=<EMPID> with follwing request Body 

{ "Change": {
"approve":{
"ApprovalComments":"Approveal Comments tested"
}
}
}

but i am getting follwoing message as exception

Messages": [
"You may not approve for any of the pending approval groups.",
"The following values are ignored:{\"approve\":{\"ApprovalComments\":\"Approveal Comments tested\"}}"
],
"ReturnCode": 28

 

Please help me  to achieve the approval process.

 

0 Likes
Highlighted
Outstanding Contributor.. Outstanding Contributor..
Outstanding Contributor..

Re: Rest api for Retreive incidents in the range of dates

Jump to solution

The user your rest call has logged in with do not have permisisons to approve. You need to ensure that this user has the proprt permissions.

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.