Morpheus Approval API

Hi Team,

Is there any way to fetch only requested approval items from approvals. As I seen the API docs it is fetching the entire list from that list we need to filter the requested one each time its fetching the huge list of items. So, I want to know is there a way to hit and retrieve only requested item using API.

Regards,
Ibrahim K

Hello,

How are you wanting to filter the approvals?

Per the API docs, you can specify an approval ID if you only need information on a single approval.

This request will give you the most information on the approval
https://apidocs.morpheusdata.com/reference/getapprovals

This request will get items under “approvalItems” in the JSON
https://apidocs.morpheusdata.com/reference/getapprovalsitem

@Tyler_Boyd - I want the filter like needs to retrieve only requested approval items not approved one. Let’s take the example I wants to know how many approval items are not yet approved. For this I need to hit the Retrieves all Approvals Api from that response I need to filter it accordingly. But in this case every time we need to play with huge number of data avoiding this if we have the filter in the API itself will be easy.

JSONPath is quite powerful for filtering. For your use-case, something like this may give you what you’re looking for:

import requests
import json
from jsonpath_ng import jsonpath
from jsonpath_ng.ext import parse
import warnings 

warnings.filterwarnings("ignore")

url = "https://{MORPHEUS-APPLIANCE-URL}/api/approvals?max=100&offset=0&sort=name&direction=asc"

headers = {
    "accept": "application/json",
    "authorization": "Bearer {MORPHEUS-API-KEY}"
}

response = requests.get(url, headers=headers, verify=False)
data = response.json()

requestedApprovalsQuery = parse("$.approvals[?(@.status[*] = '1 requested')]")       # only retrieve approvals with a status of 'requested'
requestedApprovals = [match.value for match in requestedApprovalsQuery.find(data)]

print(json.dumps(requestedApprovals, indent=2))

To print the number of items awaiting approval:

print(f"Number of items awaiting approval: {len(requestedApprovals)}")

I arbitrarily set the max to 100 but you can change that based on your requirements

@ibrahim

If you’re interested in having the filter added, consider submitting an idea. Based on discussions with the team, this shouldn’t be a difficult thing to add but submitting an idea is the most effective way to influence future releases. Don’t forget to vote for your own idea!

1 Like