Hello Everybody,
I would like wix-fetch to send email from wix code via a third party API provided by SendGrid.
My codes are as follows:
fetch(“https://api.sendgrid.com/v3/mail/send”,
{method: ‘POST’,
headers: {‘Authorization’: ‘Bearer SG.rZ96miEdQXKohaalqOS65g.BQ_TaC83Fs1TnqFTvFDmiPmaBq9mPJRAPUBvir_Xg’, ‘Content-Type’: ‘application/json’},
body: JSON.stringify(
{
“personalizations”: [
{
“to”: [
{
“email”: “xxx@gmail.com”
}
],
“subject”: “Hello, World!”
}
],
“from”: {
“email”: “from_address@example.com”
},
“content”: [
{
“type”: “text/html”,
“value”: “
Hello, World!
”}
]
})
})
.then(response => response.json())
.catch(error => console.log(‘error:’, error));
However, I keep on get the error message ‘TypeError: Failed To Fetch’.
I have tried to call the API using hurl.it and managed to call the web service successfully using the parameters used in the codes above.
I would really appreciate if anyone can give me pointers where did I go wrong.
Thank you.