Platinum Sponsor
Archives

api

vRealize Automation REST API Filter function gotha

A colleague of mine (@peteroudman )asked me how to grab a parameter through filtering a JSON response generated from the vRA REST API after he had tried several times. The parameter in question was workItem number. The purpose of this was to automate a catalog item request that has an approval request attached to it. To achieve this we need to compare the response from a few different API calls. We ran into an issue doing what we need purely with REST calls but let me explain from the beginning so you learn something:

  1. We want to automate the request of a catalog item from outside of vRA
  2. Using the catalogItemId we make a request call using a predefined payload (JSON entry) using the catalog-service API request function
  3. The response header from the above call informs us of a parameter known as the requestId
  4. Because the catalog item as an approval request waiting for someone to accept or reject this request we need to programmatically handle this.
  5. When there is some action needed by the user a workitem request is generated.
  6. We noticed that when you list all workitems there was a parameter in the JSON response called requestInstanceId which was identical to the requestID. This is the key to how we associate the original request to which workitem needs action.
  7. So the plan is to filter all the workitems expect the one relevant to our catalog request
  8. The API has a filter function when you make a GET request
  9. The problem is that requestInstanceId parameter is not filterable because its an inner-feed in the JSON response and not a JSON element.
    workitem
  10. We tried every possibility to format the filter sting and some examples look like this:
  • $filter=(workItemRequest/itemData/entries(6)/value/value eq ’18f71a3a-34c1-4624-9e20-11f4666a6b4a’)
  • ?$filter=(workItemRequest/itemData(6)/value eq ‘7990b2ce-0497-4a5a-9c40-060350086078’)

The conclusion is that we have to filter the workitem response outside of the API call in code. Not difficult but would have been nice to have that feature in the filter. I realise this is a high-level explanation but if you want to discuss this problem in detail reach out to me. Like to thank @grantorchard for trying his best to fix this for us.

Gold Sponsors
Silver Sponsors