restful api query using an 'OR' condition

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 "vaguehpsmurl:13081/.../ucmdbnodes or type=networkcomponents" -u legomac

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

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

curl -XGET -v "vaguehpsmurl:13081/.../ucmdbnodes or type=networkcomponents" -u legomac

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

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

I do achieve a response with the folloing:

curl -XGET -v "">vaguehpsmurl:13081/.../ucmdbnodes -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. 

 

  • 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!

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

  • Hi legomac,

    I checked this successfully using SoapUI with the following query:

    type="computer" or type="networkcomponents"

    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

     

  • Verified Answer

    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 

  • Hi Legomac!

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

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

    Bo

  • 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" "">someSMServer:1337/.../Requests --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!

  • I think I can explain that. SM uses double quotes for text string and single quote for datetime. No quotes for numbers and boolean.
  • 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 :-)