Ah good catch! It will actually work if you run the script, the editor just doesn’t know about fetch right now, which is why it’s complaining. We’ll get this fixed, thanks.
Hi @Kasra - just tried this again and can’t get fetch to work. This is my script:
// send an email via Sendgrid
let messageContent = "Message to go in email"
const sendgrid_url = 'https://api.sendgrid.com/v3/mail/send';
const headers = {
"Content-Type": "application/json",
"Authorization": "Bearer MY_BEARER_TOKEN"
};
var email = 'jonathan@example.com'
var content = {
"personalizations": [
{
"to": [
{
"email": email
}
],
"subject": "Hello, World! " + email
}
],
"from": {
"email": "jonathan@example.com",
"name": "Jonathan Bowen"
},
"content": [
{
"type": "text/plain",
"value": messageContent
}
]
}
let response = await fetch(sendgrid_url, {
method: "post",
headers: headers,
body: JSON.stringify(content)
});
console.log(email, response.ok);
(Just adding this to show you what it is doing).
This script works correctly on the pre-beta release base, but doesn’t work on the current beta release base. As you say, the fetch command is highlighted in the code editor, but when I run it in the current beta release, I’m also getting this as an error message:
Edit: Note that I have stripped out getting table records for the purposes of testing. I would read email addresses from the base in reality, but I stripped this code out for now just to be able to test it in the pre- and current release bases