Please contact us if you need access to this feature.

Event bindings and functions allow you to integrate Stedi with external systems and applications.

Event bindings automatically invoke your function asynchronously in response to events. For example, you could invoke a function for each transaction received from a specific trading partner.

Prerequisites

Before creating a binding, complete the following setup:

To test events and event bindings, you can deploy the following simple function that logs the events it receives.

export const handler = async (event, context) => {
  console.dir(event, { depth: null });
};

Create an event binding in the UI

To configure an event binding:

  1. In Functions UI, open your function.
  2. On the Overview tab, click the Add Event Binding button to open the binding editor.
  3. In the binding editor, you can:
    • Subscribe to one of the default Detail Types, like transaction.processed.v2, by selecting it from the list.
    • Create a custom binding. A custom binding allows you to filter a specific subset of events using a custom event pattern. Visit Creating custom event patterns for details.
  4. Click Create.

Your event binding will take a minute or so to create. It’s ready once the status has changed from Under change to Available. Process a process a test file to try it out.

Visit Events for descriptions of every event type and full event structures.

Custom event patterns

Event patterns are simple JSON objects that have the same structure as the events that they match.

You only need to include the fields in your event pattern that you want to match on, and the values must always be an array. This approach allows a single pattern to match many different events.

The following example pattern would match any file.processed.v2 event when artifactType is text/csv.

Example event pattern

{
  "detail-type": ["file.processed.v2"],
  "detail": {
    "artifacts": {
      "usage": ["input"],
      "artifactType": ["text/csv"]
    }
  }
}

Example matching file.processed.v2 event for an incoming CSV

file.processed.v2 event
{
    "event": {
        "version": "0",
        "id": "d601ab7c-d5d3-4c5f-96f9-6c7479c5594e",
        "detail-type": "file.processed.v2",
        "source": "stedi.core",
        "account": "012345678910",
        "time": "2023-09-06T20:25:03Z",
        "region": "us-east-1",
        "resources": [
          "https://core.us.stedi.com/2023-08-01/executions/xxx-5470-a381-69ca-ee9e4cfa72f7"
        ],
        "detail": {
          "fileExecutionId": "xxx-5470-a381-69ca-ee9e4cfa72f7",
          "processedAt": "2023-09-06T20:25:03.194Z",
          "partnershipId": "ACME_BSW", // optional
          "connectionId": "01H1CH2ZES1Z8AW94A3RQSRWRW", // optional
          "source": {
            "name": "filename.extension"
          },
          "artifacts": [
            {
              "artifactType": "application/edi-x12",
              "usage": "input",
              "sizeBytes": 10036,
              "url": "https://core.us.stedi.com/2023-08-01/executions/xxx-5470-a381-69ca-ee9e4cfa72f7/input",
              "model": "execution"
            },
            {
              "artifactType": "application/json",
              "usage": "metadata",
              "sizeBytes": 2248,
              "url": "https://core.us.stedi.com/2023-08-01/executions/xxx-5470-a381-69ca-ee9e4cfa72f7/metadata",
              "model": "execution"
            }
          ]
        }
      }
}

Send data to your downstream service

Instead of writing a custom function, you can use Destination webhooks to automatically send transactions and other events from Stedi to any third-party service. You can add event bindings that define which events should trigger the destination.