I've been attempting to access the MongoDB API using an API key for authentication, but I keep receiving a 401 status code.
Below is the code snippet I've been using:
fetch(‘https://eu-west-2.aws.data.mongodb-api.com/app/application-0-dhdvm/endpoint/mydatabase’, {
method: ‘GET’,
mode: ‘cors’,
cache: ‘no-cache’,
headers: {
‘Content-Type’: ‘application/json’,
‘Authorization’: Bearer ${apiKey}, // Make sure to include your API key in the Authorization header
},
})
I have successfully generated the API key:
(I made sure to export the key value before its creation, so that is not the issue here)
Here is the endpoint URL I've set up:
Any assistance would be greatly appreciated, as I seem to be encountering difficulties in properly querying the database using the provided setup.