Closed Ra0R closed 1 month ago
Hi @Ra0R, answering prompts is planned to be a part of Reports module, which is currently scheduled to be delivered with 2023 December release. For now we'll keep this issue open so in case of any updates we can let you know.
@Ra0R, @urszulajaczewska Were you able to add prompts workflow before calling to_dataframe() method in the report? Is that how we leverage mstrio-py for prompted reports?
Like this?
conn = Connection(base_url=BASE_URL, username="USERNAME", password="", project_name=PROJECT_NAME) conn.connect() report= Report(connection=conn, id="REPORT_ID", parallel=False)
// Begin Answer prompt workflow
// End Answer Prompt Workflow
report.to_dataframe()
@cjvegi
report= Report(connection=conn, id="REPORT_ID", parallel=False)
// Begin Answer prompt workflow
// End Answer Prompt Workflow
report.to_dataframe()
This wont work because to_dataframe()
method needs report instance and if instance id is not provided to Report init method, the to_dataframe()
will create it internally.
So you'll have to create report instance first:
from mstrio.api.reports import report_instance, get_prompted_instance
from mstrio.project_objects.report import Report
report_id = '<report id>'
instance_id = report_instance(conn, report_id=report_id).json()['instanceId']
Then list prompts that have to be answered:
prompts = get_prompted_instance(conn, report_id=report_id, instance_id=instance_id).json()
print(prompts)
Depending on a type of prompt, you might need to list available elements and available objects:
prompt_id = '90CF2BA14297EEDAC1412CB9C7C7B9C3'
elements = conn.get(
url=conn.base_url + f'/api/reports/{report_id}/instances/{instance_id}/prompts/{prompt_id}/elements',
)
objects = conn.get(
url=conn.base_url + f'/api/reports/{report_id}/instances/{instance_id}/prompts/{prompt_id}/objects',
)
And then create a dictionary containing prompts answers:
prompt_answers = {
"prompts": [
{
"id": '<prompt 1 id>',
"type": "VALUE",
"useDefault": True
},
{
"id": '<prompt 2 id>',
"type": "VALUE",
"useDefault": True
},
]
}
And answer the prompts:
res = conn.put(
url=conn.base_url + f'/api/reports/{report_id}/instances/{instance_id}/prompts/answers',
json=prompt_answers,
)
If every thins went ok, you just pass the instance id to init:
report = Report(conn, id=report_id, instance_id=instance_id)
print(report.to_dataframe())
More information about those endpoint you can find here.
@Ra0R Report module has been moved to be released in Q3 of 2024, possibly earlier. We're sorry for the inconvenience and thank you for your patience.
Report module exists but still has no ability to answer prompts. You have to use REST as detailed by @mstrpr
Answering prompts in Report
module has been released. No further action seem to be required.
Currently when creating a report that has required prompts it is not possible to query data through the library directly:
The last line throws an error, since there is no data in the report (since the report would require to answer a prompt).
I think it should be possible to access the report instance and answer prompts on it or directly set the report data (and manually answer the prompts via REST-API).