Because the template is load before the plugin, i finaly decide to add the API directly from https://github.com/mailjet/mailjet-apiv3-php-no-composer
I check the api:
https://dev.mailjet.com/guides/?php#contactslist_managemanycontacts
And build my function to send a contact to a list:
// Get the value from the plugin mailjet-for-wordpress
$apisecret = get_option('mailjet_password');
$apikey = get_option('mailjet_username');
require 'mailjet-apiv3-php-no-composer/vendor/autoload.php';
use \Mailjet\Resources;
function sendRegisterNewsletterToMailjet($params) {
$mj = new \Mailjet\Client($apikey, $apisecret);
$body = [
'Action' => "addforce",
'Contacts' => [
[
'Email' => $params['Email'],
'Properties' => [
'prénom' => $params['prénom'],
'nom' => $params['nom'],
'profession' => $params['profession'],
'structure' => $params['structure'],
]
],
]
];
$response = $mj->post(Resources::$ContactslistManagemanycontacts, ['id' => $params['ListID'], 'body' => $body]);
$response->success() && var_dump($response->getData());
wp_send_json_success($response);
}
The problem is i get this response:
{
"success":true,
"data":
{
"request":{
"type":"application/json"
}
}
}
Instead of:
{
"Count": 1,
"Data": [
{
"JobID": 35800
}
],
"Total": 1
}
Any idea?