atlassian-python-api icon indicating copy to clipboard operation
atlassian-python-api copied to clipboard

Update Insights to Assets

Open shaun-actionanalytics opened this issue 1 year ago • 2 comments

What's the status on a release which updates to the new assets endpoints?

Looking specifically at: https://github.com/atlassian-api/atlassian-python-api/blob/0a5bc5ee72427be0ec16ce5db4f4b091f7a00ddc/atlassian/insight.py#L23

https://github.com/atlassian-api/atlassian-python-api/blob/0a5bc5ee72427be0ec16ce5db4f4b091f7a00ddc/atlassian/insight.py#L258

shaun-actionanalytics avatar Feb 29 '24 17:02 shaun-actionanalytics

@shaun-actionanalytics I'm using the following to give myself a way to use aql, but it's still using this wrapper's Insight class which uses the insight API. This only implements a function to fetch all objects matching the search, since that's all I needed for now.

""""
Assets class extends the atlassian-api-wrapper Insight class to add functions that use the new /object/aql endpoint
instead of the deprecated /iql/object endpoint. If the wrapper receives an update to use these new endpoints, we could
look at making use of their functions instead.
"""

from atlassian import Insight


class Assets(Insight):
    def get_object_aql(
            self,
            aql,
            start=0,
            results_per_page=25,
            include_attributes=True
    ):
        params = {"startAt": start, "maxResults": results_per_page, "includeAttributes": include_attributes}
        url = self.url_joiner(self.api_root, "object/aql")
        data = {"qlQuery": aql}
        return self.post(
            url,
            data=data,
            params=params
        )

    def get_object_aql_all(
            self,
            aql,
            include_attributes=True
    ):
        start = 0
        results_per_page = 25
        values = []
        while True:
            results = self.get_object_aql(
                aql,
                start=start,
                results_per_page=results_per_page,
                include_attributes=include_attributes
            )
            start = start + results_per_page
            values.extend(results.get('values'))
            if results['isLast']:
                results['values'] = values
                return results

But I'm also looking for a class that uses /jsm/assets

aculver avatar Mar 28 '25 20:03 aculver

How about implementing that group ? ;) https://developer.atlassian.com/cloud/assets/rest/api-group-aql/#api-group-aql

I am open for pull requests

gonchik avatar Mar 29 '25 16:03 gonchik