Posting returns no authentication methods were specified

Hello, I hope this is the right topic.
So I am trying to post something to my data api that would insert a key. Everything is fine and everything works fine when I do it with python and even on my other lua end.
Here are some screenshots of the error.

Also tried using this header format but it returns a syntax error.

'Content-Type: application/json' 
'Access-Control-Request-Headers: *' 
'api-key: <Data API Key>'

And here you can see that it works just fine with python. Screenshot by Lightshot

Hi @Sin_S, welcome to the community.
Can you please post the error that you are getting? I am unable to locate the error in both of your screenshots.

PS: Please post the error and the code by pasting the text directly, it will make the post easily discoverable if someone faces a similar issue in the future.

Thanks & Regards,
Sourabh Bagrecha,
MongoDB Community Team

1 Like

Hello. Thank you for replying. Here is my code

fetch("https://data.mongodb-api.com/app/data-ysfzy/endpoint/data/beta/action/insertOne", {
    mode: "no-cors",
    method: "POST",
    headers: {
        'Content-Type': 'application/json',
        'Access-Control-Request-Headers': '*',
        'api-key': 'KEYHERE'
    },
    data: JSON.stringify({
        "collection": "Keys",
        "database": "modlogs",
        "dataSource": "RGH",
        "document": {"linkkey": "gayy"}
    })
}).then (res =>{
    console.log(res)
})

And here is the error that I get in console

Here is the error that I get in MongoDB https://i.imgur.com/q0x6dQQ.png

And yes the API-Key that I am using is right.

Hello. Thank you for replying. Here is my code

fetch("https://data.mongodb-api.com/app/data-ysfzy/endpoint/data/beta/action/insertOne", {
    mode: "no-cors",
    method: "POST",
    headers: {
        'Content-Type': 'application/json',
        'Access-Control-Request-Headers': '*',
        'api-key': 'KEYHERE'
    },
    data: JSON.stringify({
        "collection": "Keys",
        "database": "modlogs",
        "dataSource": "RGH",
        "document": {"linkkey": "gayy"}
    })
}).then (res =>{
    console.log(res)
})

And here is the error that I get in console

Here is the error that I get in mongodb


and yes the api key is right

1 Like

Hello, was the problem solved?

Regards,

S.