AmitA
AmitA

Reputation: 3245

Mailgun: Is there a way to retrieve a stored message a webhook call gave up on?

I have a Mailgun application with an incoming route set up in the following way:

match_recipient('[email protected]')
store(notify='https://www.example.com/endpoint')

At some point, I switched the domain from www.example.com to www.example2.com with a 301 redirect through the DNS provider (read: I cannot access the logs..) without changing the Mailgun routes.

Over the course of a few days I got a bunch of permanent errors in the logs, since the webhook does not seem to follow redirects.

Now, I'd like to try to retrieve these stored messages, but there I don't find a way to get to the original ID.

Here is what is stored in the Mailgun event log:

{
  "severity": "permanent",
  "tags": [],
  "delivery-status": {
    "retry-seconds": 14400,
    "message": "<html><body>You are being <a href=\"https://www.example2.com/endpoint\">redirected</a>.</body></html>",
    "code": 301,
    "description": "<html><body>You are being <a href=\"https://www.example2.com/endpoint\">redirected</a>.</body></html>",
    "session-seconds": 0.7563347816467285
  },
  "envelope": {
    "targets": "https://www.example.com/endpoint",
    "transport": "http",
    "sender": "[email protected]"
  },
  "log-level": "error",
  "id": "dffZ3qigQpyKGNdwhfj26A",
  "campaigns": [],
  "reason": "old",
  "user-variables": {},
  "flags": {
    "is-routed": null,
    "is-authenticated": true,
    "is-callback": true,
    "is-system-test": false,
    "is-test-mode": false
  },
  "timestamp": 1430473028.303534,
  "message": {
    "headers": {
      "to": null,
      "message-id": "[email protected]",
      "from": "[email protected]",
      "subject": null
    },
    "attachments": [],
    "recipients": [
      "https://example.com/endpoint"
    ],
    "size": 47467
  },
  "recipient": "https://example.com/endpoint",
  "event": "failed"
}

(1) In the above the id seems to represent the Event ID, which I believe is irrelevant, and the message ID seems to be 20150430214155.10820.14949.

(2) In a typical webhook success scenario, the message posted to the server contains a callback-URL to retrieve the message that looks like this:

https://api.mailgun.net/v2/domains/www.example.com/messages/WyI4MzNheDUxMmRjIiwgWyI0ZWFiNWM1Mi05Zjg4LTRkMjctYjdhMS04ZTM3Y2E3ZDJmNTkiXSwgIm1haWxndW4iLCAib2xkY29rZSJd

This is a Base64 encoded message of the following (all UIDs are modified):

["833ax512dc", ["4eab5c52-9f88-4d27-b7a1-8e37ca7d2f59"], "mailgun", "oldcoke"]

Is there a way to construct the stored-message retrieval URL using the message ID 20150430214155.10820.14949 ?

Upvotes: 3

Views: 2132

Answers (1)

Daniel
Daniel

Reputation: 571

This is maybe a little too late for AmitA's need, but if anyone else wants to know a way to get that retrieval URL, my approach was to use the Events API:

GET /events?message-id={your message ID}

This returns a response, with a list of results under an 'items' key. These items will have that URL under the 'storage' key, as 'url'.

So, if response is the response from that GET call, the URL for the first response will be found at response['items'][0]['storage']['url'].

I hope that helps someone out there!

Upvotes: 3

Related Questions