I have used the Mailjet api to store submitted emails in a Mailjet list. This worked properly when there was the Mailjet 0.1 version API (then there wasn't any PHP wrapper but was easy to use with their examples), but when they changed the API to version 3 their PHP wrapper does not return any contact ID when adding a new contact to a contact list. I have raised a similar question earlier how to get Mailjet to work but now this issue arose with the new version 3.
Again here is the corrected code,
*Assume that the shown email is a new contact that's not already created in Mailjet.
$mj = new Mailjet();
$contact_params = array("method" => "POST", "Email" => "abc@gmail.com");
$contact = $mj->contact($contact_params);
$add_params = array(
"method" => "POST",
"ContactID" => $contact,
"ListID" => _MAILJET_LIST,
"IsActive" => "True"
);
$mj->listrecipient($add_params);
Developer @Gormador said to use $contact->Data[0]->ID
as contact id but it still returns NULL.
I get this error when trying to add a created contact to a list (with debug mode set to 2).
array(3) { ["ContactID"]=> NULL ["ListID"]=> string(1) "2"
["IsActive"]=> string(4) "True" } string(105) "{ "ErrorInfo" : "",
"ErrorMessage" : "Invalid data: \"null\" is an invalid integer",
"StatusCode" : 400 }"
Previous question: Mailjet: Adding email to list does not work
Updated: Full code with corrections,
$mj = new Mailjet();
$add_email = "testing" . rand(0, 1000) . "@gmail.com";
$contact_params = array("method" => "POST", "Email" => $add_email);
$mj->contact($contact_params);
$viewContact = array("method" => "VIEW","unique" => $add_email);
$contact = $mj->contact($viewContact);
$add_params = array( "method" => "POST", "ContactID" => $contact->Data[0]->ID, "ListID" => 1, "IsActive" => "True" );
$mj->listrecipient($add_params);