biigle / reports

:m: BIIGLE module to generate reports for projects and volumes
GNU General Public License v3.0
1 stars 2 forks source link

Return report ID when report generated through API. #73

Closed rskelly closed 2 years ago

rskelly commented 3 years ago

When generating a report through the API it would be preferable to return a report ID that the client software could use to poll the service (at reasonable intervals, of course) for the existence of the finished report, rather than having a human user check their email. Ideally, the client software could send a parameter to turn the notification email off for that request.

If I have the opportunity I will look into it and offer a solution (if one doesn't already exist).

mzur commented 3 years ago

Sounds like a good idea. Returning the report with its ID is easy to implement for the project and volume controllers. An option to disable notifications could be added as new report option which is observed once a report was successfully generated. Are you willing to send a pull request for this?

rskelly commented 3 years ago

I'll look into it. Just getting started with Biigle and a little rusty with PHP!

rskelly commented 2 years ago

I am looking at this issue now, and have successfully returned a result (you were right, it's easy). Can you offer any guidance with regards to what to return? For now, I just return a JSON object containing the ID and nothing else. I could add an error field as well, and set it to the error message if there is one, or let the framework return a 500 response.

Also, should I assume that it's desirable to only enable the suppression of notifications through the API and not through the UI, since the latter would prevent the user from finding out the ID of the report?

mzur commented 2 years ago

You can just return $report and it should be automatically converted to JSON (including the ID). To do this only for requests not coming from the UI (e.g. scripts), you can use isAutomatedRequest (example). There is no need to do manual error handling. This is done automatically.

The report ID is no secret. But it should be sufficient to implement that option and just not use it in the UI. Then it's basically only available for custom scripts accessing the API. Feel free to open a pull request and we can continue discussing the implementation there.