Create Trigger
This tutorial will guide you through the process of creating trigger for a Gelato piece that fetches new icecream flavor.
Trigger Definition
To create trigger run the following command,
Piece Folder Name
: This is the name associated with the folder where the trigger resides. It helps organize and categorize triggers within the piece.Trigger Display Name
: The name users see in the interface, conveying the trigger’s purpose clearly.Trigger Description
: A brief, informative text in the UI, guiding users about the trigger’s function and purpose.Trigger Technique
: Specifies the trigger type - either polling or webhook.
Example:
This will create a new TypeScript file at packages/pieces/community/gelato/src/lib/triggers
named new-flavor-created.ts
.
Inside this file, paste the following code:
The way polling triggers usually work is as follows:
Run
:The run method executes every 5 minutes, fetching data from the endpoint within a specified timestamp range or continuing until it identifies the last item ID. It then returns the new items as an array. In this example, the httpClient.sendRequest method is utilized to retrieve new flavors, which are subsequently stored in the store along with a timestamp.
Expose The Definition
To make the trigger readable by Activepieces, add it to the array of triggers in the piece definition.
Testing
By default, the development setup only builds specific components. Open the file packages/server/api/.env
and include “gelato” in the AP_DEV_PIECES
.
For more details, check out the Piece Development section.
Once you edit the environment variable, restart the backend. The piece will be rebuilt. After this process, you’ll need to refresh the frontend to see the changes.
To test the trigger, use the load sample data from flow builder in Activepieces. It should function as shown in the screenshot.