Call Realm Administration API with Application ID results in 404 Not Found

Hi,

I’m trying to use the Realm Administration API and I can call the base endpoints like create an access token and get a list of applications. But when I take any of the application ids (from the _id field) they all return 404 Not Found for all endpoints.

I gave the API key I set up all the permissions available.

What am I doing wrong? :sweat_smile:

Hi @Max_Karlsson,

I’m having the same issue, all calls to the API return 404 page not found.

Did you find a solution to this?

Thanks
Will

Hey @varyamereon,

Unfortunately, I didn’t. Haven’t heard anything from Realm about it either.

I’m honestly pretty close to giving up on Realm altogether and replace it with a competitor.

@Max_Karlsson Can you give an example code snippet of how you are making this admin API call that always returns a 404?

Hi All – In addition to the code snippet that Ian mentioned, it would also be helpful to confirm that you’re following the steps for an Atlas Programmatic API key and that the key has project owner permissions for the project where your applications are. Sounds like this is the case, but sometimes we see confusion between Atlas API keys and Realm’s API key authentication.

Hi @Ian_Ward and @Drew_DiPalma, if someone would have reached out to this ticket 4 months ago when I posted it I might have been able to oblige, but I can’t even remember why I needed to use that endpoint now, so unfortunately I can’t help.

Sorry about that @Max_Karlsson - we don’t really have a SLA governing our community forums but in the future you can always open a support ticket which does have a SLA tracking system in place.

For this specific issue, we don’t see any reason why this wouldn’t work so likely there is just some confusion in the implementation. Would love to clean this up in the docs but we would need to know what is not clear in order to fix it.

Sorry, @Ian_Ward I didn’t mean to come across as entitled. I realise that this is just the community support forum. I just wanted to point out that the time that’s passed since I posted this question is too long for me to remember what I was trying to achieve or how. I don’t even remember which documentation I used, but I know I followed it to a tee :sweat_smile:

Perhaps @varyamereon will be better equipped to answer since he’s worked on it more recently.

@Drew_DiPalma re-reading the instructions I have found out what I was doing wrong. The call to get an access_token was always successful. I was then making calls with Postman and adding the token to the Authorization like so:

This was always returning 404 Page not Found. This morning I copies the curl request and replaced with my access token. It’s added to the headers in a different way and I was able to successfully make requests this way:

So it’s all in the details :wink:

Thanks for your help anyway, @Max_Karlsson I hope you manage to get it sorted.

Will

Hi Drew,

I’m experiencing a similar problem. I authenticate successfully using the following code;

private string _authUrl = "https://realm.mongodb.com/api/admin/v3.0/auth/providers/mongodb-cloud/";
private string _baseUrl = "https://realm.mongodb.com/api/admin/v3.0/";

string body = JsonConvert.SerializeObject(new { username = _publicApiKey, apiKey = _privateApiKey });
StringContent requestContent = new StringContent(body, Encoding.UTF8, "application/json");

using (HttpClient client = new HttpClient { BaseAddress = new Uri($"{_authUrl}") })
{
	client.DefaultRequestHeaders.Clear();
	client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

	HttpResponseMessage response = await client.PostAsync("login", requestContent).ConfigureAwait(true);

	if (response.IsSuccessStatusCode)
	{
		string content = await response.Content.ReadAsStringAsync();
		_authResponse = JsonConvert.DeserializeObject<AuthResponse>(content);
		_authResponse.Expires = DateTime.Now.AddMinutes(25);
	}
}

Then I try getting the app IDs using;

using (HttpClient client = new HttpClient { BaseAddress = new Uri($"{_baseUrl}") })
{
	client.DefaultRequestHeaders.Clear();
	client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
	client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _authResponse.AccessToken);

	HttpResponseMessage response = await client.GetAsync($"groups/{_projectId}/apps").ConfigureAwait(true);
}

This returns a “403 Forbidden” response.

If I attempt to create a user with the following;

	string body = JsonConvert.SerializeObject(new { email = userName, password = $"{pin}" });
	StringContent requestContent = new StringContent(body, Encoding.UTF8, "application/json");

	using (HttpClient client = new HttpClient { BaseAddress = new Uri($"{_baseUrl}") })
	{
		client.DefaultRequestHeaders.Clear();
		client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
		client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _authResponse.AccessToken);

		HttpResponseMessage response = await client.PostAsync($"groups/{_projectId}/apps/{_appId}/users", requestContent).ConfigureAwait(true);
	}

I get a “404 Not Found”.

I have followed the instructions at Authentication API, Find a Project ID,
Application ID and User APIs but have not managed to resolve the issues.

Hi All,

The 404 error can happen if you copied the API path by highlighting the string from the documentation instead of using the copy icon. Doing so can lead to copying across hidden UTF characters which will cause this issue. Please use the copy icon as shown below to avoid this issue.

Regards
Manny

1 Like

I, too, am running into this issue. @Drew_DiPalma , I see that you mentioned following the steps for an Atlas Programmatic API key. The only thing that I found different was the lack of a configured access list. I went ahead and configured that and was still met with a 404, “app not found” message. It’s also worth noting that the docs for the access list mention the following: “An empty API access list grants access to all API endpoints except those that explicitly require an API access list.” When viewing the Admin API docs page, I see no reference to anything about the access list. I therefore assume that there are no endpoints that require said access list.

The API key has organization member and organization read only roles assigned. At the project level, the key is a project owner.

I’m simply trying to hit the /logs endpoint to see what data they actually return. I’m using Postman for these requests. I’ve also tried with curl and was met with the same message.

Would love to know what I’m missing here.

It’s saying I posted too long ago to make edits. So minor updates:

  • The code in Access Logs with the Admin API produces the same result.
  • The realm-cli, using the same key, has no issue with dumping the logs, but the info is just not helpful as there are no details about the individual log event beyond the type and if it was an error or OK.

Hi Justin – Would you mind posting/messaging the API request that you’re making (minus any sensitive information) this could help debug here as the above doesn’t point to any specific issue.

Sure thing. There’s not really anything crazy. It’s really just the standard API endpoint:
curl --request GET \ --header 'Authorization: Bearer <access_token>' \ 'https://realm.mongodb.com/api/admin/v3.0/groups/{groupId}/apps/{appId}/logs'

As others have said, I, too, can get a valid response from:
curl --request GET \ --header 'Authorization: Bearer <access_token>' \ https://realm.mongodb.com/api/admin/v3.0/groups/{groupId}/apps

Same key being used for both.

My issue has been resolved. (Thanks, Drew!) It’s important to note that the {appId} in the API path is NOT the client App ID. The docs specifically say this in this section. In my case, I was passing client_app_id and not the _id that was returned from the call to https://realm.mongodb.com/api/admin/v3.0/groups/{groupId}/apps.

4 Likes