Link Search Menu Expand Document

Webhook Integration for AS2

1 Introduction

The MFTGateway allows integration based on webhooks, to notify you of incoming messages or other similar events. Webhooks works well with the REST APIs, or even SFTP or S3 based integration, and avoids the need for polling. This requires the assignment of one or more external Webhook endpoints, exposed over an HTTP or HTTPS URL. Wehbooks allow you to trigger custom actions or alerts based on events.

Webhook notifications use best-effort delivery without any guarantees. If your webhook endpoint was unavailable, or encountered a network error or timeout etc, the notification may become lost, and will not be replayed. As with any distributed system, the use of a polling mechanism to rectify and reconcile any such lost events would be preferable.

1.1 Implementing a webhook

A webhook is a simple HTTP endpoint that can handle POST requests, sent by the MFT Gateway. We recommend a SLAppForge Sigma based Lambda function for the best experience in implementing a quick but powerful webhook for Amazon AWS or Google GCP cloud environments.

2 Webhook Message formats

An incoming webhook message includes an eventType attribute, which will help differentiate between the possible types of messages. See below sections on sample message contents.

Webhook eventWebhook eventType
Send a message from MFT GatewayMESSAGE.SEND.SUCCESS
Receive message to MFT GatewayMESSAGE.RECEIVED.SUCCESS
Message send failureMESSAGE.SEND.FAILED

2.1 Received Message

Triggered when a new message has been received. Request contains a JSON payload representing the received entity (AS2 message) such as the following.

{
  "to": "sample+1@email.com",
  "messageAS2ID": "<1609934788.3185.1616041941493@as2gateway.com>",
  "messageSubject": "Test message",
  "partnerAS2ID": "mypartnerid",
  "partnerName": "Partner Name",
  "stationAS2ID": "mystationid",
  "stationName": "Station Name",
  "receivedAt": 1616041942383,
  "attachments": [
    "AS2/files/mystationid/mypartnerid/inbox/1616042383-195/sample.json",
    "AS2/files/mystationid/mypartnerid/inbox/1616042383-195/testfile.txt"
  ],
  "bucketName": "mftg-bucketname.test.mftgateway.com",
  "tenantName": "abc.test.mftgateway.com",
  "tenantId": 6650967499476,
  "tenantEmail": "tenant@email.com",
  "eventType": "MESSAGE.RECEIVED.SUCCESS"
}
partnerAS2IDAS2 identifier of the sender (remote trading partner)
stationAS2IDAS2 identifier of the receiver (your trading station)
messageAS2IDAS2 identifier of the received message
messageSubjectsubject line of the received message
attachmentsS3 / SFTP path of the received attachment / s
bucketNameName of the S3 bucket where all the attachments will be saved.

2.2 Sent Message

Triggered when a submitted message has been successfully delivered. Request contains a JSON payload representing the sent entity (AS2 message) such as the following.

{
  "to": "sample+1@email.com",
  "messageAS2ID": "<467855488300248@mftgateway.com>",
  "messageSubject": "Test message",
  "partnerAS2ID": "mypartnerid",
  "partnerName": "Partner Name",
  "stationAS2ID": "mystationid",
  "stationName": "Station Name",
  "sentAt": 1624622353886,
  "attachments": [
    "AS2/files/mystationid/mypartnerid/outbox/1616042383-195/sample.json",
    "AS2/files/mystationid/mypartnerid/outbox/1616042383-195/testfile.txt"
  ],
  "bucketName": "mftg-bucketname.test.mftgateway.com",
  "tenantName": "abc.test.mftgateway.com",
  "tenantId": 6650961234576,
  "tenantEmail": "tenant@email.com",
  "eventType": "MESSAGE.SEND.SUCCESS"
}

See Section 2.1 for an explanation of the key attributes.

2.3 Send Failure

Triggered when a submitted message has failed delivery and has exhausted the automatic retries. Request contains a JSON payload representing the failed entity (AS2 message) such as the following.

{
  "to": "sample+1@email.com",
  "messageAS2ID": "<16160421683347496@mftgateway.com>",
  "messageSubject": "Test Fail Message",
  "partnerAS2ID": "mypartnerid",
  "partnerName": "Partner Name",
  "stationAS2ID": "mystationid",
  "stationName": "Station Name",
  "failureReason": "SSL Handshake Exception",
  "failures": 1,
  "lastAttemptTime": 1616042169406,
  "attachments": [
    "AS2/files/mystationid/mypartnerid/outbox/1616042163434-851/Test.txt"
  ],
  "subject": "Test Fail Message",
  "bucketName": "mftg-bucketname.test.mftgateway.com",
  "tenantName": "abc.test.mftgateway.com",
  "tenantId": 6650967499476,
  "tenantEmail": "tenat@email.com",
  "eventType": "MESSAGE.SEND.FAILED"
}

In addition to the details in the received message payload under Section 2.1, send failure JSON payload would also include:

failureReasonReason for the message send failure
failuresHow many times the message has failed
lastAttemptTimeWhen is the last send attempt

3 Webhook Configuration

3.1 Enabling / Disabling Webhooks

Webhook Integration

You can visit ‘Webhooks’ from Integrations menu icon on the left navigation menu, and will be presented with the above page. Here, one or more webhook endpoints can be specified. Each webhook endpoint can be configured against one Station, or for all Stations. You cannot provide two webhook endpoints for the same Station. To disable any webhook, simple remove it from the list by clicking the delete icon.

By configuring a webhook endpoint against only one Station, only events specific to that station will be filtered and sent to the endpoint. To catch all events for any Station, use the ‘All Stations’ webhook type.

MFT Gateway’s webhook invocations currently do not follow redirects (HTTP 301, 302, 307 etc.).

If your HTTPS webhook endpoint has a TLS certificate that is not implicitly trusted by MFT Gateway, it may need to be explicitly imported into the system. In such cases, please contact MFT Gateway team with a copy of the respective certificate.