Pages

Saturday, 28 December 2019

Connect to MailJet API with Google Apps Script

The following Google Apps Script can be used to connect to the MailJet API, from where you can then send emails and manage contacts. There is a lot of documentation on how to connect via PHP, Python, Rub, C# etc but nothing suited towards Google Apps Script.

To connect you will need to have a MailJet account and your own API/Secret keys. In this example we will connect with the 'Contact List' aspect of the API. We need to create an encoded string which contains our API keys:
var encoding = Utilities.base64Encode(apiKey + ":" + secretKey);
From here we can set the HTTP headers authentication as part of the request, to authorise our account details:
var options = {
    'headers': {"Authorization": "Basic " + encoding},
  };
Then we can continue with the usual route of using the 'UrlFetchApp' to make the request and return our data.

Connect to MailJet API with Google Apps Script.gs

No comments:

Post a comment