i am trying to query the MongoDB Rest API using Custom HTTP Endpoints and i am getting the ‘404’ Error.
I created the following endpoint for ‘GET’ requests:
fetch('https://eu-west-2.aws.data.mongodb-api.com/app/application-0-dhdvm/endpoint/mydatabase/', {
method: 'GET',
mode: 'no-cors',
cache: 'no-cache',
headers: {
"Content-Type": "application/json",
},
Do i have to use an API key to have access to the API ? What is missing to have access to my database ?
2
Answers
I am getting the 401 status code.
I created the API key:
mongoDB API key
I inserted the APIkey on the Headers:
headers: { 'Content-Type': 'application/json', 'Authorization':
Bearer ${apiKey}, Authorization header },
I am still getting the unauthorized error.
If you’re trying to access a MongoDB REST API, using an API key for authentication is a common practice.
This is a general example of how you might use an API key in your
fetch
request