Generate Sample Payload for a Custom Event Source

Payload Generation

A custom event listener is used to pass data to a target function whenever its URL is invoked by the end user. Custom event listeners can contain multiple rules, which can be associated with different target functions. All rules of a custom event listener have the same URL endpoint, but each rule will contain a unique rule identifier variable that you can configure while creating it. This allows you to indicate the specific rule to invoke.

Note: Custom event listeners do not exist in a project by default. You must therefore first create a custom event listener in your project from the remote console, to generate a sample payload for it. However, you don't need to create any rules in it for this purpose. You can create a rule in the CLI for testing purposes while generating the sample payload. This will not be reflected in the custom event listener configured in the console.

You can generate a sample payload for a custom event by executing this same command:

copy
$
catalyst event:generate|generate:event [options] <source> <action>

However, Catalyst only accepts the following values for source and action for a custom event source:

Source Action
custom Produce

Mandatory Command Options

You must also use these options mandatorily while generating a sample payload for a custom event:


-e | --event-bus <event_bus_name>

The –event-bus option performs the same action as discussed in the previous section. It enables you to specify the name of the event bus that must be used in the sample payload. The event_bus_details JSON will contain the name that you pass as the bus’s name.


-rid | --rule-id <rule_identifier>

The –rule-id option enables you to specify the rule identifier that must be used in the custom event payload. As mentioned earlier, a rule identifier uniquely identifies a rule in a custom event bus. The data field in the JSON will contain the rule identifier.

You can generate a sample payload for a custom event, and pass the event bus name and rule identifier by executing the following command:

copy
$
catalyst event:generate|generate:event custom Produce --event-bus TrackerRequests --rule-id DomesticTracking

This will generate the following JSON payload. The payload will contain the details of your project, event bus, and rule identifier details you provided, as well as other sample data.

Custom Event Payload Generation


Note: If you are a Visual Studio Code IDE user, you can install the Catalyst Tools extension, and perform CLI operations using your IDE in place of the CLI. Steps to debug your event functions using Visual Studio Code IDE can be found here.

Last Updated 2024-01-09 17:07:13 +0530 +0530