Creating Admin Users Programatically


Forgive me if this something I just missed in the docs - is there a way to create a user with admin privileges programatically with username/password authentication? I noticed there’s a way to do it with admin tokens, but we are using Realm cloud on my project, and so far as I know getting an admin token is somewhat non-trivial in that case. Any suggestions help - it’s been a long day so I’m willing to take a ‘rtfm’ on the chin in the morning too :slight_smile:


There’s an undocumented REST endpoint you can use. After a user is created by logging in with username/password the regular way, you can promote them to an admin by issuing the following request:

PUT https://my-server-url/auth/users

// Headers
Authorization: your-admin-refresh-token

// Body:

To obtain the admin refresh token, you need to login as an admin user by issuing the following http request:

POST https://my-server-url/auth

// Body


Thanks! This works great with our on-premise Realm Object Server, but I can’t quite get it to work with our Realm Cloud instance. Thinking that might just be a network security thing at this point, though, and not the REST endpoints?


There should be no difference in terms of endpoints on cloud. What’s the error response you’re getting?


503 - The requested service is temporarily unavailable (https protocol), or an empty response from the server (http protocol)