I working with ReactJS trying to create a contact form using AWS Lambda and SES. I was following this guide for the AWS setup. When I send my json file using postman I have no issues status 200 and the email sends, great! then I try to implement it in my React file and I have issues. despite having the same API endpoint.
function post(url, body, callback) {
var req = new XMLHttpRequest();
req.open("POST", url, true);
req.setRequestHeader("Content-Type", "application/json");
req.addEventListener("load", function () {
if (req.status < 400) {
callback(null, JSON.parse(req.responseText));
} else {
callback(new Error("Request failed: " + req.statusText));
}
});
req.send(JSON.stringify(body));
}
const handleSubmit = (e) => {
e.preventDefault();
console.log(this.state.form);
post(url, this.state.form, function (err, res) {
if (err) {
return alert(err);
}
alert("success");
});
};
the response I get from AWS:
{
message: "Missing Authentication Token"
}
I've tried these steps AWS lessons on missing token
I have checked the url 1000 times and unless I'm missing something it is correct. Invoke URL: https://EXAMPLE.execute-api.us-east-1.amazonaws.com/prod/email/send
also tried everything from here
Not sure what I have wrong and why postman works but my code doesn't any help would be greatly appreciated.