Skip to content

Instantly share code, notes, and snippets.

@nadar
Created September 12, 2022 08:23
Show Gist options
  • Save nadar/26560aac0a85fbc987b7b46b66e6aeb3 to your computer and use it in GitHub Desktop.
Save nadar/26560aac0a85fbc987b7b46b66e6aeb3 to your computer and use it in GitHub Desktop.
Mailjet Sections Cleanup
<?php
$username = 'API_KEY';
$password = 'API_KEY_SECRET';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.mailjet.com/v3/REST/template?EditMode=3&OwnerType=apikey&limit=200');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
$res = curl_exec($ch);
curl_close($ch);
$json = json_decode($res, true);
foreach ($json['Data'] as $k => $v) {
echo PHP_EOL . PHP_EOL;
var_dump($v['Name'], $v['OwnerType']);
$del = curl_init();
curl_setopt($del, CURLOPT_URL, 'https://api.mailjet.com/v3/REST/template/' . $v['ID']);
curl_setopt($del, CURLOPT_RETURNTRANSFER, true);
curl_setopt($del, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($del, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($del, CURLOPT_CUSTOMREQUEST, 'DELETE');
$delResponse = curl_exec($del);
curl_close($del);
var_dump($delResponse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment