Executing service command via Realm Admin API

According to the Realm Admin API docs, it’s possible to run a command associated with a service:

https://docs.mongodb.com/realm/admin/api/v3/#post-/groups/{groupid}/apps/{appid}/services/{serviceid}/commands/{commandname}

My project has a single mongodb-atlas service that I’d like to interact with via the Realm API, but I’m not sure what the acceptable {commandName}s are. I’ve tried using some of these operations (https://docs.mongodb.com/manual/reference/command/) as a reference, but of the ones I’ve tried, the only one that worked was ‘listCollections’ (which I had to provide in the URL as “list_collections”) – all the other commands return a 404 Not Found with this body:

{
    "error": "command not found on MongoDB service",
    "error_code": "ServiceCommandNotFound"
} 

My immediate goal is to retrieve custom user data (https://docs.mongodb.com/realm/sdk/ios/advanced-guides/custom-user-data/) for any and all users of my choosing. This is seemingly not possible using the Realm web SDK as it will only retrieve the custom user data associated with the Realm user you are currently logged in with. I’m hoping the Realm Admin API will provide an avenue for this.

Thanks in advance for any assistance.

Hey Josh - while custom user data will only get returned for the currently logged in user, since all user data is stored in a collection linked to your app, you can define a “public” role with read access to any user data fields (e.g. profile pictures, email addresses) that you would like to make available to anyone logged in, I don’t think using the Admin API would be necessary.

As for your original question, it would be helpful to see the exact URL you used with the ids.

@Sumedha_Mehta1 Thank you for your quick reply. I created a role on the collection storing the user data as you suggested and was able to achieve my objective. I’ll pursue learning more about the Realm API’s ability to execute service commands if and when I need it in the future.

Much appreciated!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.