I have a REST operation that retrieves CIs based on type and the result set can be filtered on the REST host side by passing in zero or more additional filters. For example, these queries are all valid:
GET http://cmdb/webservices/ci/Customer
GET http://cmdb/webservices/ci/Customer?city=Madison
GET http://cmdb/webservices/ci/Customer?city=Madison&size=1000
How can I define this rest operation on the vRO side? it seems like it wants a static set of query string variables.
Well, the easiest way is to define your REST operation with URL template /{type}?{query} (assuming http://cmdb/webservices/ci is the base URL of the REST host). So when you start the workflow to invoke the operation, you'll need to type the whole query filter string; eg. city=Madison&size=1000
If you want a more user-friendly UI, for example, to show additional fields in presentation UI for every filter field (city, size, etc.) so the user will need to provide only the values if any (Madison, 1000, etc.), then you should do a bit more work.
Take a look at the workflows 'Invoke a dynamic REST operation' and 'Invoke a REST operation with dynamic params' that are part of HTTP-REST samples. The presentation of the latter defines a large number of input parameters that are hidden by default, and there is some logic to show them based on some logic. You need to add your own logic that will compute the filter fields based on the provided type. After that, you can dynamically build the request as shown in the first workflow.
I haven't tried the above but in theory it should work.
While the workflow-based "create REST workflows" approach may be nice for beginners, I'd recommand you to just do the scriping yourself. The exposed JavaScript API of the REST plugin is pretty good and the request you're trying to do is no more then a two-liner:
var response = configuredRestHost.createRequest("GET", "/webservices/ci/Customer?city=Madison", null).execute();
var xmlFile = XMLManager.fromString(response.contentAsString);
Where configuredRestHost is your configured REST host object from the HTTP-REST plugin in vRO.
As you see, all that happens here is really only plain old String manipulation. Build a workflow and create a attribute "sizeValue" and "cityValue". Then go something like that (quick and dirty example, but you get the idea):
var requestString = "/webservices/ci/Customer?"
if(cityValue)
{
requestString = requestString + "city=" + cityValue
}
if(cityValue && sizeValue)
{
requestString = requestString + "&size=" + sizeValue
}
if you want to re-use the bit's nothing prevents you to make the workflow modular or even build actions for common REST tasks you're performing.
regards
Robert