Create a Realm App with Realm API
On this page
You can use the Realm Admin API to create a new server-side Realm app.
Prerequisites
- A MongoDB Atlas programmatic API key for the MongoDB Cloud account you wish to log in with. You must be a Project Owner to create a Realm app.
- An Atlas cluster. If you do not have one set up, follow this guide: Create a New Cluster.
Procedure
1
Authenticate a MongoDB Atlas User
Use your MongoDB Cloud API key pair to call the authentication endpoint:
curl --request POST \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --data '{"username": "<Public API Key>", "apiKey": "<Private API Key>"}' \ https://realm.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/login
If authentication succeeds, MongoDB Realm returns an access token as part of the JSON response document:
{ "access_token": "<access_token>", "refresh_token": "<refresh_token>", "user_id": "<user_id>", "device_id": "<device_id>" }
Save the access_token
, which you'll use as the Bearer token to authenticate in the upcoming steps.
Tip
See also:
2
Get the Group ID
To delete a Realm app you will need to find the Group ID in Atlas.
Follow these steps and save the Group ID for the last step.
3
Create a new Realm App
You can create a new Realm app through the create endpoint.
Your request should include:
- The
access_token
from step 1 in a Bearer tokenAuthorization
header. - The Group ID from step 2.
- A name for your new app.
If creation succeeds, the MongoDB Realm returns a 201
response and a JSON document.
Tip