How to get information about a Poll using Rest API?

For a class project, I’m building a mobile app for Nextcloud Polls. I’m using the rest API to get the polls and show them to the user. When it comes to allow the user to interact with a certain poll, I’m annoyed: using /api/v1.0/poll/{pollId} only gives me the configuration of the poll, but not other information, like the permissions (addOption, allAccess, etc.) or the current user (isLoggedIn, isOwner, etc.). The only way I found is to use /api/v1.0/polls which loads every poll and gives those information but it is quite inefficient (because I only need one poll and it might load dozens of them).

My question is : how can I get the permissions and current user for a single poll without loading every poll?

(I saw here there is a way to use /poll/{pollId}/poll, but I don’t understand how to make it work outside of a browser. If someone could show me a curl or a Java HttpURLConnection working example using an URL like https://example.com/index.php/apps/polls/poll/{pollId}/poll, it would also solve my problem.)

Any help would be much appreciated.

If it can help you understand why I don’t understand how to use /poll/{pollId}/poll, I get a 412 error ({“message”:“CSRF check failed”}) whenever I try to access it with curl -X GET https://username:password@example.com/index.php/apps/polls/poll/{pollId}/poll -H “OCS-APIRequest: true”

i just moved your topic to the development-category. Hopefully some dev is watching and could help you in your mission to use Rest-API successfully

1 Like

I fear, you are out of direct luck here.

The REST calls are summarized in the route.php. I have not checked each route but it seems that these are the only ones with CSRF check disabled. This means, only the routes are those with the /api prefix.

The list method of the controller returns all polls, while the get method will return a single poll. The single query just returns the poll. On the other hand, the list method of the service augments the data with additional information.

I would suggest to contact the dev of the poll app (dartcafe) and ask if one could augment the API with either one additional API endpoint to get the meta data or augment also the existing endpoint with the meta data. The fastest way to get there is to provide a PR :wink:.

By the way: the fetching of all polls should not impose too much of load on the server. So, requesting all as a workaround and filtering out the relevant ones, might be doable in the meantime.

2 Likes

Thank you very much for answer. I opened a feature request. I will rely on the list method for now.

1 Like

A new endpoint for the acl was added to the API.

1 Like