MicroStrategy / mstrio-py

Python integration for MicroStrategy
Apache License 2.0
89 stars 57 forks source link

Doubt how to get Dashboard data #190

Open axnsantana opened 1 month ago

axnsantana commented 1 month ago

Hi,

first thanks a lot for the tool, really appreciate.

I am looking at the Dashboard snippets and I do not understand what are the steps to get the same data (time series) I see in the Micro UI. I can retrieve the Dashboard, its properties, cubes, etc...

I was able to extract the data from Reports (launching instances and so on), but had no success with the Dashboard.

Probably I am missing how Micro works.

Would really appreciate if someone could help me with that. Thanks a lot.

axnsantana commented 1 month ago

An additional detail, I am able to get the data using the API directly with this endpoint

hustontrevor commented 1 month ago

Not all of the endpoints have been implemented in mstrio-py. Many times you may need to dig through the .py files to see if an endpoint is used then go back to the API-docs page to look at the schema of the result so you know how to deal with the response. Though, even those schema are not fully documented, so then you've got to step through a debugger.

Like list_dashboards() ultimately calls return connection.post(endpoint='/api/metadataSearches/results', ...

But you can access the REST endpoints from the same Connection class you've already instantiated. That makes it a bit simpler to hop back and forth.

One of mine for example:

self.mstr_conn = Connection(base_url=self.base_url
                            , username=self.username
                            , password=self.password
                            , ssl_verify=False)

    def getSubPrompts(self, project_id,subscriptionId):
        headers = {'X-MSTR-ProjectID':project_id}
        URL = f"/api/subscriptions/{subscriptionId}/prompts"
        rspns = self.mstr_conn.get(endpoint=URL, headers=headers)

        prompts = rspns.json()["prompts"] if rspns.ok else []
        if not rspns.ok:
            print(URL)
            print(f"HTTP {rspns.status_code} - {rspns.reason}, Message {rspns.text}")            
        return prompts
axnsantana commented 1 month ago

Thanks for the answer @hustontrevor. Yes, by the end I extracted the data using the endpoint and the connection from mstrio-py. The JSON schema it returned is a bit complex but I was able to understand and transform it into a pandas dataframe.