mailgun / mailgun-php

Mailgun's Official SDK for PHP
http://www.mailgun.com
MIT License
1.1k stars 314 forks source link

Getting Accepted Events / Applying Accepted Event Filter #840

Closed c1am closed 1 year ago

c1am commented 2 years ago

With PHP, I'm able to get stored events using the params below flawlessly. I try to change the 'event' => 'stored' to 'event' => 'accepted' but it doesn't seem to work and I'm wondering if anyone might know if there's something else in the code I need to change?

$url = "https://api.mailgun.net/v3/" . $this->mgDomain . "/events";
if (!empty($page_url)) {
      $url = $page_url;
} else {
      $url_params = array(
      'event' => 'stored',
      'recipients' => $curr_journaling_email,
      'limit' => $limit,
      'begin' => (date("d M Y H:i:s", strtotime($dt_start)) . " EST"),
      'end' => (date("d M Y H:i:s", strtotime($dt_end)) . " EST"),
      'pretty' => 'yes'
      );
      $url .= "?" . http_build_query($url_params);
}
$headers = array(
      "Authorization: Basic " . base64_encode("api:" . $this->get_mg_key()),
      "Accept: message/rfc2822"
      );

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$result = curl_exec($curl);
$responseArray = json_decode($result, true);

Thank you in advance!

oleksandr-mykhailenko commented 2 years ago

Hello @c1am Do you have logs in your dashboard for the same period ?

Here is my example

I have logs

image

And after request with the code from library

$queryString = array(
    'limit'        =>  100,
    'pretty'       => 'yes',
    'event'        => 'accepted'
);

# Issue the call to the client.
$result = $mgClient->events()->get($domain, $queryString);

I got my results

image

Also want to mention that I do no have a header of Accept

And my url looks next /v3/my-domain/events?limit=100&pretty=yes&event=accepted

oleksandr-mykhailenko commented 2 years ago

@c1am Hello. Do you have any updates ?

oleksandr-mykhailenko commented 1 year ago

Close the issue due to inactivity

c1am commented 1 year ago

Hello @oleksandr-mykhailenko, I've found out the solution was changing 'recipients' for stored events to 'recipient' for accepted events.