Logs

Logs

This simple logging API allows you to fetch the same log entries you would normally see in your Control Panel.

GET /<domain>/log

Fetches the list of log entries.

Parameter Description
limit Maximum number of records to return. (100 by default)
skip Number of records to skip. (0 by default)

Example

An example of how to fetch a single 51st log message skipping the first 50, using the API:

def get_logs
  RestClient.get "https://api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0"\
  "@api.mailgun.net/v2/samples.mailgun.org/log", :params => {
    :skip => 50,
    :limit => 2
  }
end

Response:

{
  "total_count": 837,
  "items": [
    {
      "hap": "delivered",
      "created_at": "Fri, 03 Feb 2012 10:39:50 GMT",
      "message": "Delivered:  me@samples.mailgun.org \u2192 Sasha Klizhentas <alex@mailgun.net> 'Hello'",
      "type": "info",
      "message_id": "20120203103948.20654.16663@samples.mailgun.org"
    },
    {
      "hap": "delivered",
      "created_at": "Fri, 03 Feb 2012 10:39:50 GMT",
      "message": "Delivered:  me@samples.mailgun.org \u2192 ev@mailgun.net 'Hello'",
      "type": "info",
      "message_id": "20120203103948.20654.16663@samples.mailgun.org"
    }
  ]
}

An example of how to fetch a single 51st log message skipping the first 50, using the API:

public static ClientResponse GetLogs() {
       Client client = new Client();
       client.addFilter(new HTTPBasicAuthFilter("api",
                       "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"));
       WebResource webResource =
               client.resource("https://api.mailgun.net/v2/samples.mailgun.org/log");
       MultivaluedMapImpl queryParams = new MultivaluedMapImpl();
       Integer a = 50;
       queryParams.add("skip", a);
       queryParams.add("limit", 1);
       return webResource.queryParams(queryParams).get(ClientResponse.class);
}

Response:

{
  "total_count": 46,
  "items": []
}

An example of how to fetch a single 51st log message skipping the first 50, using the API:

function get_logs() {
  $request =
    new HttpRequest('https://api.mailgun.net/v2/samples.mailgun.org/log',
                    HttpRequest::METH_GET);
  $auth = base64_encode('api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0');

  $request->setHeaders(array('Authorization' => 'Basic '.$auth));
  $request->setQueryData(array('skip' => 1, 'limit' => 2));
  $request->send();
  return $request;
}

Response:

{
  "total_count": 81,
  "items": [
    {
      "message": "Sent:  me@samples.mailgun.org \u2192 sergeyo@profista.com 'Hello' ",
      "type": "info",
      "created_at": "Mon, 14 Nov 2011 18:07:11 GMT"
    },
    {
      "message": "Sent:  me@samples.mailgun.org \u2192 sergeyo@profista.com 'Hello' ",
      "type": "info",
      "created_at": "Mon, 14 Nov 2011 18:07:01 GMT"
    }
  ]
}

An example of how to fetch a single 51st log message skipping the first 50, using the API:

def get_logs():
    r = requests.\
        get(("https://api.mailgun.net/v2/samples.mailgun.org/"
             "log"),
            auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
            params={
                "skip": 1,
                "limit": 2
                }
            )
    return r

Response:

{
  "total_count": 1010,
  "items": [
    {
      "hap": "delivered",
      "created_at": "Tue, 07 Feb 2012 07:11:45 GMT",
      "message": "Delivered:  sbob@samples.mailgun.org \u2192 Sasha Klizhentas <alex@mailgun.net> 'Hello'",
      "type": "info",
      "message_id": "20120207071144.30917.84205@samples.mailgun.org"
    },
    {
      "hap": "delivered",
      "created_at": "Tue, 07 Feb 2012 07:11:43 GMT",
      "message": "Delivered:  me@samples.mailgun.org \u2192 Sasha Klizhentas <alex@mailgun.net> 'Hello'",
      "type": "info",
      "message_id": "20120207071142.26601.64240@samples.mailgun.org"
    }
  ]
}

An example of how to fetch a single 51st log message skipping the first 50, using the API:

public static RestResponse GetLogs() {
       RestClient client = new RestClient();
       client.BaseUrl = "https://api.mailgun.net/v2";
       client.Authenticator =
               new HttpBasicAuthenticator("api",
                                          "key-3ax6xnjp29jd6fds4gc373sgvjxteol0");
       RestRequest request = new RestRequest();
       request.AddParameter("domain",
                            "samples.mailgun.org", ParameterType.UrlSegment);
       request.Resource = "{domain}/log";
       request.AddParameter("skip", 50);
       request.AddParameter("limit", 1);
       return client.Execute(request);
}

Response:

{
  "total_count": 123,
  "items": [
    {
      "message": "Sent:  me@samples.mailgun.org \u2192 sergeyo@profista.com 'Hello' ",
      "type": "info",
      "created_at": "Mon, 14 Nov 2011 18:06:22 GMT"
    }
  ]
}

An example of how to fetch a single 51st log message skipping the first 50, using the API:

curl -s -k --user api:key-3ax6xnjp29jd6fds4gc373sgvjxteol0 -G \
    https://api.mailgun.net/v2/samples.mailgun.org/log \
    -d skip=50 \
    -d limit=1

Response:

{
  "total_count": 1211,
  "items": [
      {
          "hap": "delivered",
          "created_at": "Wed, 15 Feb 2012 03:51:52 GMT",
          "type": "info",
          "message": "Delivered:  me@samples.mailgun.org \u2192 Sasha Klizhentas <alex@mailgun.net> 'Hello'",
          "message_id": "20120215035151.31904.4170@samples.mailgun.org"
      }
  ]
}