mailjet / mailjet-apiv3-php-simple

[API v3] Simple PHP wrapper for the Mailjet API /!\ [DEPRECATED - SEE README] /!\
https://dev.mailjet.com
MIT License
55 stars 45 forks source link

Easily find contact status for a newsletter/campaign (API v1 vs API v3) #104

Closed FHenry closed 9 years ago

FHenry commented 9 years ago

In APIv1 there is a simple way to get contact status for one specific campaign messageCampaigns with mailjet campaign ID in parameters return :

messageContacts with paramters stats_campaign_id return : an object's array with contact email and contact status in the for this campaign.

I can't find any equivalent methods returns value (report_uri and array with contact email and contact status) in new APIv3.

I've already ask to mailjet support, but I didn't get really usefull answer (for now)

Gormador commented 9 years ago

Hi @FHenry,

First of all, sorry for the delay in my response.

Regarding your need, there doesn't seem to be a direct translation between the API v1 and v3 process to get the status of a newsletter for a contact. However, you can still get for which contact an email hasn't reach its destination.

To do so, you need to use the bouncestatistics resource (doc here) and filter with the CampaignID:

curl -s -X GET 
    --user "$MJ_APIKEY_PUBLIC:$MJ_APIKEY_PRIVATE"
    https://api.mailjet.com/v3/REST/bouncestatistics?CampaignID=XXXX

This translates easily in php:

$params = array(
    "CampaignID" => XXXX
);

$campaignBounces = $mj->bouncestatistics($params);

Then, you get all bouncestatistics resources associated to that campaign, which contain a numerical field named StateID. That ID varies from 0 to 8 and is associated to the named status described at the Status parameter here. You naturally also get a ContactID with each bouncestatistics resource.

Once again, sorry for the delay. I hope this helps. Don't hesitate to ask again if not.

Gaëtan

FHenry commented 9 years ago

Hi @Gormador, Sorry to answer so late, When I try this method I've get that result : { "Count" : 0, "Data" : [], "Total" : 0 } The campagin ID I use come from https://api.mailjet.com/v3/REST/campaignstatistics?NewsLetter=XXXX And the Newsleter ID come from IS return by create newsletter method.