How to get a simple return from Insight API call?

Wenping Li April 30, 2021

Currently when I use API call to get Insight objects, it returns lots of information besides the objects and attributes. I have to look up exactly what I need from the returns in order to do the rest of the work. The information returned from an API call is really overwhelming. Anyone has a good idea how to make the return data as simple as just return the value of the attribute?

Many thanks.  

3 answers

0 votes
Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 4, 2021

I don't think the Insight REST API has an equivalent to the "fields" filter that the Jira Issue API offers to only include the attributes you can about.

https://insight-javadoc.riada.io/insight-javadoc-8.6/insight-rest/#

You must either call the /object/{id} to get all the objects details, call /object/{id}/attributes to get just a list of attributes, or once you have a specific attribute id (unique to the object) then you can call /objectattribute/{id}

Be generally, with most modern languages you should be able to ingest the json into a structured object and then just fetch the necessary information.

For example, in groovy:

def parsedJson = New JsonParser().parseText(jsonStringFromObjectApiResponse)
//get an attribute value:
def attribute = parsedJson.attributes.find{it.objectTypeAttribute.name='ABC Attribute'}
def attributeValue = attribute.ObjectAttributeValues[0].value //this assumes the attribute holds a single string value
0 votes
Wenping Li May 4, 2021

Hi Raiv, thanks for the response. We use REST API call to get a JSON, then parse to get data that we need. The difficulty here is the data returned from the REST API call contains too many information, and it takes lots of effort to develop the parse process, especially there are many objects we will need to develop the parse process in java/phythen. We expected that the REST API call should just return the information for the attributes that are defined in the object. 

We will take a look the ScriptRunner page you provided. Thanks for that. We do use PSOTMAN to get API return too. 

 

Wenping

0 votes
Ravi Sagar _Sparxsys_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 30, 2021

Hi @Wenping Li 

How are you using the API? From Jira automation rules or a ScriptRunner or any other tool. For retrieving the information by making a REST call you will get a JSON that you need to parse to get the information you are looking for. 

If you are using ScriptRunner then take a look at this page for some information and sample scripts to make a REST call.

For testing REST endpoints I use Talend API test extension or POSTMAN.

I hope it helps.

Ravi

Suggest an answer

Log in or Sign up to answer