Script automation for Mailjet

Hi,
I’m stuck with one problem.

I’d like to send Mailjet email with the Airtable Script automation.
I succeed to send a Mailjet SMS with this code :

    let inputConfig = input.config(); // the input variables in Airtable
    let response = await fetch('https://api.mailjet.com/v4/sms-send', {
        method: 'POST',
        body: JSON.stringify(inputConfig),
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer Mykey'
        },
    });

The problem is that, in Mailjet dev API, they said to use this code for sending Mailjet template :

curl -s \
	-X POST \
	--user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE" \
	https://api.mailjet.com/v3.1/send \
	-H 'Content-Type: application/json' \
	-d '{
		"Messages":[
				{
						"From": {
								"Email": "pilot@mailjet.com",
								"Name": "Mailjet Pilot"
						},
						"To": [
								{
										"Email": "passenger1@mailjet.com",
										"Name": "passenger 1"
								}
						],
						"TemplateID": 1,
						"TemplateLanguage": true,
						"Subject": "Your email flight plan!"
				}
		]
	}'

The thing is that I succeeded to do it for the SMS, but in this case, I need to add " --user “$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE” "

The problem is : where should I add this user information ?
In the header like this ‘Authorization’: ‘Bearer Mykey’ ?
Doesn’t work.

I really don’t want to use zapier or integromat, I’ll have to many emails to send.

Thanks by advance for any contributions ! :slight_smile:

Hi @Mathieu_Quiniou - have a look at this post:

Which suggests doing:

Authorization: 'Basic ' + Utilities.base64Encode('username:password')

or in your case:

Authorization: 'Basic ' + Utilities.base64Encode('public_key:private_key')

Thanks for your answer @JonathanBowen

I wrote this code :

let response = await fetch('https://api.mailjet.com/v3.1/send', {
    method: 'POST',
    body: JSON.stringify(payload),
    headers: {
        'Content-Type': 'application/json',
        'Authorization': 'Basic'  + 'Utilities.base64Encode(mypublickey:mysecretkey)'
    },
});

Doesn’t work.

I also tried this line :
'Authorization': 'Basic' + Utilities.base64Encode('mypublickey:mysecretkey')

I also tried this line :
'Authorization': 'Utilities.base64Encode(mypublickey:mysecretkey)'

But the Airtable scripting doesn’t recognize the Utilities function, and the email is not working …

What ca I do then ?

This topic was solved and automatically closed 15 days after the last reply. New replies are no longer allowed.