After subscription on my website form, I need to create the new contact on Mailjet and then add it to a specific list that already exist.
I have this following code which I execute after insert my user to database.
$firstname = "Michael";
$email = [email protected];
$mj = new \Mailjet\Client($MJ_APIKEY_PUBLIC,$MJ_APIKEY_PRIVATE);
// create new contact on Mailjet
$contact_params = [
"Email" => $email
];
$response_add = $mj->post(Resources::$Contact, ['body' => $contact_params]);
// adding the created contact to my list
$list_params = [
'Name' => $firstname,
'Action' => "addnoforce",
'Email' => $email
];
$response_list = $mj->post(Resources::$ContactslistManagecontact, ['id' => 10181436, 'body' => $list_params]);
The contact is correctly created on Mailjet but never add to the list. The $response_list
always give me back NULL and I don't really know why. I'm pretty new with Mailjet API, but I've following the official API and the way I want to do it seems correct. (https://dev.mailjet.com/email/reference/contacts/subscriptions#v3_post_contactslist_list_ID_managecontact)
Thanks for help :)
In case you are yet to find a solution. Try this out, it works for me.
Check the "/contactslist/{list_ID or list_address}/managecontact" section on this documentation; https://dev.mailjet.com/email/reference/contacts/subscriptions#v3_post_listrecipient
Enjoy