Highlighted
legomac Valued Contributor.
Valued Contributor.
1603 views

restful api query using an 'OR' condition

Jump to solution

I am trying to query the restful API by configuration type using an 'OR' condition.  Usually I use python, but for testing queries I am using curl.  Below are my unsuccessful attempts:

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?type=computer%20or%20type=networkcomponents" -u legomac

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?type='computer'%20or%20type='networkcomponents'" -u legomac

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?type=\'computer\'%20or%20type=\'networkcomponents\'" -u legomac

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?query=type=computer%20or%20type=networkcomponents" -u legomac

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?query=type='computer'%20or%20type='networkcomponents'" -u legomac

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?query=type=\'computer\'%20or%20type=\'networkcomponents\'" -u legomac

I do achieve a response with the folloing:

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?type=computer" -u legomac

curl -XGET -v "http://vaguehpsmurl:13081/SM/9/rest/ucmdbnodes?type=networkcomponents" -u legomac

Any information on how to run this query would be helpful. 

 

0 Likes
1 Solution

Accepted Solutions
legomac Valued Contributor.
Valued Contributor.

Re: restful api query using an 'OR' condition

Jump to solution

Thanks, but I am trying to use the REST service.

I did, however, figure out a resolution to the issue.  It is due to the way the app is processing the quotation marks in the request.

Apparently the REST API and SQL server process the query differently when given double quotes or single quotes.....hope this helps someone else out!

If I get a chance, I will come back and post examples 

0 Likes
8 Replies
Micro Focus Expert
Micro Focus Expert

Re: restful api query using an 'OR' condition

Jump to solution

Hello legomac,
Hope you are doing well.

I am not sure which SM version are you using, however I don't think the principle changes a lot between versions.

I found the following in the MicroFocus' Help Server for Service Manager, hope you find it useful.
It explains some of the RESTful Queries you can use on the application:

https://docs.microfocus.com/SM/9.50/Hybrid/Content/webservicesguide/rest_queries.htm

Best regards!

If you find that this or any other post resolves your issue, please be sure to mark it as an accepted solution. If you are satisfied with anyone’s response please remember to give them a LIKE by clicking on the Thumb and show your appreciation.
0 Likes
legomac Valued Contributor.
Valued Contributor.

Re: restful api query using an 'OR' condition

Jump to solution

I have read the documentation and traversed these threads, but am still not able to format the curl command properly.

0 Likes
Super Contributor.. bogart Super Contributor..
Super Contributor..

Re: restful api query using an 'OR' condition

Jump to solution

Hi legomac,

I checked this successfully using SoapUI with the following query:

type%3D%22computer%22%20or%20type%3D%22networkcomponents%22

It's just the url encoded version of

type="computer" or type="networkcomponents"

Here is a fragment of the result:

{
   "@count": 670,
   "@start": 1,
   "@totalcount": 670,
   "Messages": [],
   "ResourceName": "ucmdbNode",
   "ReturnCode": 0,
   "content":    [
      {"ucmdbNode": {"CIIdentifier": "CI1000007"}},
      {"ucmdbNode": {"CIIdentifier": "CI1000008"}},
      {"ucmdbNode": {"CIIdentifier": "CI1000009"}},
      {"ucmdbNode": {"CIIdentifier": "CI1000010"}},
      {"ucmdbNode": {"CIIdentifier": "CI1000011"}},
      {"ucmdbNode": {"CIIdentifier": "CI1000012"}},
      {"ucmdbNode": {"CIIdentifier": "CI1000013"}},
      {"ucmdbNode": {"CIIdentifier": "CI1000014"}},

Hope the answer helps...

Bo

 

0 Likes
legomac Valued Contributor.
Valued Contributor.

Re: restful api query using an 'OR' condition

Jump to solution

Thanks, but I am trying to use the REST service.

I did, however, figure out a resolution to the issue.  It is due to the way the app is processing the quotation marks in the request.

Apparently the REST API and SQL server process the query differently when given double quotes or single quotes.....hope this helps someone else out!

If I get a chance, I will come back and post examples 

0 Likes
Super Contributor.. bogart Super Contributor..
Super Contributor..

Re: restful api query using an 'OR' condition

Jump to solution

Hi Legomac!

Thanks, but I am trying to use the REST service.

I used the REST service - it's possible with SoapUI! 😉

Bo

0 Likes
legomac Valued Contributor.
Valued Contributor.

Re: restful api query using an 'OR' condition

Jump to solution

Oops!  I breezed through your response so fast that I did not notice the 'UI', only the 'SOAP'!

 

Anyway, below are my findings for making requests to SM using curl.  It appears the DB only like double quotes around many parameters, but requires single quotes around the date:

 Works: 

curl  -v -H "Connection:Close" "http://someSMServer:1337/SM/9/rest/Requests?view=expand" --data-urlencode "query=brief.description=\"(scan)\" and SubmitDate>'2018-06-20T04:00:00+00:00' and status=\"open\" or status=\"fulfilled\"" -u username

If the datetime is enclosed with double quotes, the query fails.

If the status or description are in single quotes, the query fails.

This is true while making the request using either curl or python, I have not tested it any other way.

Anyway, thanks for your help!

Micro Focus Expert
Micro Focus Expert

Re: restful api query using an 'OR' condition

Jump to solution
I think I can explain that. SM uses double quotes for text string and single quote for datetime. No quotes for numbers and boolean.
0 Likes
Super Contributor.. bogart Super Contributor..
Super Contributor..

Re: restful api query using an 'OR' condition

Jump to solution

Yes, that's exactly the way SM works! And the quoting things are sometimes a little bit confusing...

But for now everything is fine! The query is querying!

Bo 🙂

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.