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


  1. Could I be so bold to ask, how would you save this data in a Google Sheet?

    THANK YOU!!!!

    1. Hi

      that was my end goal and unfortunately it was not possible (at least at the time). I was in touch with MailJet support to fix a number of problems with their API but ultimately Apps Script is not 'supported' and so I couldn't get it to work .... sorry.

      Kind regards