I would like to get campaign stats such as a clicked count, opened count etc through Mailgun. This is explained at "Basic Examples" in https://documentation.mailgun.com/api-campaigns.html#basic-examples .
I sent a test email with PHP and codeigniter. I checked the sent email in Mailgun GUI page and saw headers were added like this (which I think correct):
X-Mailgun-Tag: 3511 (note: I also added tag for testing)
X-Mailgun-Campaign-Id: test-campaign-3511
Now, if I type "test-campaign-3511" in the search box in Mailgun GUI, it will not find any email. However, it will retrieve this test email correctly with the search text "3511". So, it works with tag, but not campaign ID.
What I need eventually is getting campaign stats through PHP, so I tried this:
$result = $mgClient->get("$domain/campaigns/test-campaign-3511");
Result is
An uncaught Exception was encountered
Type: Http\\Client\\Exception\\HttpException
Message: Client error:
GET https://api.mailgun.net/v2/(my domain)/campaigns/test-campaign-3511
resulted in a404 Not Found
response: { "message": "Campaign not found" }
Next I tried without campaign ID:
$result = $mgClient->get("$domain/campaigns");
Result:
stdClass Object
(
[http_response_body] => stdClass Object
(
[items] => Array
(
)
[total_count] => 0
)
[http_response_code] => 200
)
It looks like I am failing to create campaign there. Is there anything I am doing wrong or need to set other than X-Mailgun-Campaign-Id?
Turned out that I needed to create campaign first.
$result = $mgClient->post("$domain/campaigns", array(
'name' => 'test campaign',
'id' => 'my_test_campaign'
));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.