Sorry for summoning all WIX Gurus at once, I know you are very busy answering hundreds of questions in here. But guys, I wouldn’t bother you if I didn’t need you.
Here is my situation:
I have your SendGrid sample up and running, but because of SendGrid have problems processing large HTML files with their API Ver.2 (which is the one used by the WIX sample), SendGrid helpdesk suggested me to migrate to their API Ver.3. So I did.
As they promised, the new API actually can handle large and complex HTML files. I have everything running smoothly… Well, not quite yet.
Here is what I have accomplished so far (please see my function below): it uses the SendGrid API Ver.3, and sends my emails successfully. I actually receive the email instantaneously and fully HTML formatted. Problems is, I never receive any “ok” response from the SendGrid servers; they keep me on waiting for a response permanently, so my code gets stuck on the Promise().
SendGrid Helpdesk says that this is impossible, they do send me an answer but somehow I’m not catching it. To get things weirder, when I send a bad request on purpose, I get an error response from SendGrid. So. I’m catching the bad ones but not the good ones? Hum!
If I send a bad request on purpose, I receive a response immediately, but when I send a good request, I receive no response at all, not even a null or empty string.
Fact is, SendGrid is processing my request successfully because I get the email in my inbox, but I never get any response. So I’m guessing the problem must be in the FETCH Function or in my code… Ok, OK, most likely in my code.
Could you please take a look at my function and let me know if you see anything out of place?
Sorry again for summoning you all
Thank you very much,
-Luigi
HERE IS MY CODE:
export function SendGridFetch2 (APIKey, Sender, Recipient, Subject, HTMLBody)
{
const MyURL = “https://api.sendgrid.com/v3/mail/send”;
const MyHeaders = {“Content-Type”:“application/json”, “Authorization”:"Bearer " + APIKey};
const MyBody = {“personalizations”:[{“to”: [{“email”:Recipient, “name”:“XXXX”}]}], “from”:{“email”:Sender, “name”:“YYYYY”}, “subject”:Subject, “content”:[{“type”:“text/plain”,“value”:“Your email client does not support HTML”},{“type”:“text/html”,“value”:HTMLBody}]};
return fetch(MyURL, {“method”:“POST”, “headers”:MyHeaders, “body”:JSON.stringify(MyBody)}).then(Response => Response.json());
}