WHM API: emailtrack_search returns 空记录

WHM API: emailtrack_search returns empty records

我正在使用 WHM api 来跟踪邮件发送日志中的电子邮件,但是,JSON 响应使用 emailtrack_search return 没有记录

我正在调用以下URL

1xx.x.xx.xxx:2087/cpsess####/json-api/emailtrack_search?api.version=1

这是 JSON 响应

{"metadata":{"result":1,"version":1,"command":"emailtrack_search","reason":"OK","overflowed":0,"__chunked":1},"data":{"records":[]}}

请注意,记录是空的,但我在电子邮件发送日志中有消息,我尝试添加一个用户作为参数,但它 return 是一样的。

有人知道如何使用此 API 显示电子邮件传送日志吗?

非常感谢任何帮助

此致。

该帖子可能对您有所帮助。您也可以在 cPanel 论坛上提出请求。那里有很多活跃用户:

https://forums.cpanel.net/threads/track-delivery-api.534501/

Daniel,空记录数组也让我抓狂。您的发现帮助我更深入地研究了 cPanel 的不良记录 API。为了帮助其他人寻找类似的答案,我在博客中详细描述了这个过程 post - Email delivery reports using WHM API and PHP

编辑: 这是我的一段代码,returns 来自 WHM 的 JSON API,使用 emailtrack_search:

function fetchRecordsByHour($sender, $startTime, $endTime) {
  //Set up variables
  $user = USER;
  $token = TOKEN;
  $hostname = HOSTNAME;

  //Set up query - https://documentation.cpanel.net/display/DD/WHM+API+1+Functions+-+emailtrack_search
  $query = $hostname.'/json-api/emailtrack_search?api.version=1'.
            '&api.filter.enable=1'. //Enable filter (https://documentation.cpanel.net/display/DD/WHM+API+1+-+Filter+Output)
            '&api.filter.a.field=sender&api.filter.a.arg0='.$sender.'&api.filter.a.type=eq'. //Filter records with $sender
            '&api.filter.b.field=sendunixtime&api.filter.b.arg0='.$startTime.'&api.filter.b.type=gt'. //Filter records greater than $startTime
            '&api.filter.c.field=sendunixtime&api.filter.c.arg0='.$endTime.'&api.filter.c.type=lt'. //Filter records less than $endTime
            '&api.sort.enable=1'. //Enable sorting (https://documentation.cpanel.net/display/DD/WHM+API+1+-+Sort+Output)
            '&api.sort.a.field=sendunixtime&api.sort.a.method=numeric&api.sort.a.reverse=0'. //Sort by sent time, not in reverse (By default, the API sorts in reverse order)
            '&success=1'. //Fetch success emails
            '&defer=1'. //Fetch defered emails
            '&failure=1'. //Fetch failed emails
            '&inprogress=1'. //Fetch in progress emails
            '&deliverytype=all'. //Fetch remote and local emails
            '&max_results_by_type=999'; // Fetch a large number of records per batch (Since WHM limits the total at 250 records, anything above 250 is fine)

  //Initialize CURL
  $curl = curl_init();
  curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($curl, CURLOPT_URL, $query);

  //Set authentication parameters
  $header[0] = "Authorization: whm $user:$token";
  curl_setopt($curl, CURLOPT_HTTPHEADER, $header);

  $result = curl_exec($curl);

  //Check for CURL error
  $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  if ($http_status != 200) {
    echo "Error: ".$http_status." returned";
  }

  curl_close($curl);

  //Return only the records, stripping away all the metadata
  return json_decode($result)->data->records;
}