![]() ![]() The API keys in the scripts above have been modifed, so won’t work with SendGrid. Remember to keep your API key secret so that others cannot send emails through your account □. Have a look at the API docs to see how you can further customise your email - ‘from’ and ‘to’ names (to go with email addresses), HTML content (not just plain text), attachments, dynamic templates, cc and bcc emails are just some of the elements that can be set in your API call. This is a very basic example of the kind of email notification you can send through SendGrid. Run your script again, choosing one of the records in your table. Note that the ‘to’ email address is set to the email variable the subject is personalised to include name the content value is set to the message. Let response = await remoteFetchAsync(SG_URL, options) now set some of the values in the data object with the record values Let message = record.getCellValue('Message') get the name, email and message values from the record Let record = await input.recordAsync('Pick a record', table) and get the user to choose a record from the table ![]() Change the to email value in the data object to be a real email address and add a fetch call to the bottom of the script: Let’s now make a simple API call to check that our code is working and that SendGrid is set up correctly. ![]() Note that the API key variable is used in the Authorization header and data is used in the body attribute of the options object. options contains the fetch method (in this case a POST request), the headers required and the body of the request. I’ve also created an options variable which gets passed to the fetch command (see below) when the API call is made. I’ve declared a data variable to hold the basic SendGrid message. In the above script snippet, I’ve declared variables for the API key and the API endpoint/URL we’re going to use. Let SG_API = 'SG.RhhEEPSgRyOZv5Siscxk_A.s-wZuJBTUoAJvUQbbe9OUFj8cZ5' Let’s start by pulling out some of the cURL command elements into variables. We can convert this into JavaScript that will work with the scripting app. Clear the boilerplate code and copy in your API key and the copied cURL command. Now let’s add the scripting app to our base and start to develop the script that will send an email when we select a specific record. Ignore step 3 and copy the code in step 4. Take a moment to do that and note the API key generated. Step 2 tells you to create an API key if you don’t already have one. We’re not going to use cURL directly, so you can ignore step 1 of the instructions. Click on the cURL option to see the recommended steps and generated code. More information on cURL here if you are interested. What do we do here?ĬURL is a command line tool for making data transfer requests and it is easy to translate from a cURL request to a JavaScript request, so let’s start there. This is a common hurdle to get over when you are presented with new API docs. We’re using vanilla Javascript in the Scripting app and none of the language options presented will be useful to us here (most assume the use of a SendGrid library or package to make the integration easier in your chosen language). You’ll now see a set of language options to choose from. ![]() You should see two options for the setup method - Web API and SMTP Relay. Once your account is ready to send, click on ‘Email API’, then ‘Integration Guide’. I won’t cover the set up of your account, but it is pretty straightforward and SendGrid leads you through the process. There’s few hurdles you have to jump before you are ready to send, such as adding your address details and verifying a sender email address. If you don’t already have a SendGrid account, set one up now. Message - the message we want to send to the recipient.Email - the email we’re going to send to.Name - for the name of our email recipient.But for a little more control and configurability (and to continue our API series), in this post we’re going to use the Airtable scripting block to communicate directly with SendGrid. Sending an email using SendGrid (APIs Part 3) Īirtable has a built-in SendGrid app and this is great for sending emails to your users/customers/whatever. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |