The Velo Action SPI lets you develop your custom action directly in your site dashboard. Once you create a new automation, you can write your own action code using the Run Velo Code feature.
Working directly in the automation allows you to:
To write your action code, use the Velo APIs just like you would in your site's public or backend files.
To use a custom action as part of an automation, start by creating a new automation in your site dashboard.
Go to the Automations page in your dashboard.
Click New Automation, then Start from Scratch.
Select and configure a trigger.
Important: The code file you create for your custom action is associated with the original trigger you selected. If you change the trigger, a new code file will be created and you'll have to write new code. The initial file you create is still saved, and if you restore the trigger it is associated with, you'll be able to access it again in the automation.
Under Choose an Action, select Run Velo code. Then click Start Coding to add your code.
You'll be prompted to create a new code file.
Give the file a name and click Create & Start Coding.
Note: A file is created with the name you give under the Custom Extensions tab in your site's backend code. Though you can add or edit code in this file, we recommend working only in the file that appears in your automation. This allows you to verify you're working with the correct trigger, as well as take advantage of features like testing and payload viewer.
You should now see something like this:
The Write Velo Code modal contains two tabs. The first is the .js file where you write your code. This is a backend file
that contains a single function, invoke()
.
Write any code that you want the action to execute inside invoke()
. Do not delete the return
statement.
The second tab, which appears under Payload view, lets you view the expected structure of the trigger payload. This changes depending on the trigger you select. The displayed payload is read-only.
When you finish writing your code, click Save.
Now that you have set up and coded your custom action, you can activate the automation immediately. However, we recommend testing the action code first.
To test your code, follow the instructions under Run your code to test this action, then click Run Code.
Wix provides sample data that matches the structure of your trigger payload. You can edit any of the fields in the sample payload to test your action.
Once you test your code and are sure your action works, activate your automation.
To edit your action code, edit your automation and select the Run Velo code action, then click on Edit Code. Make the changes you want, save the code, and test.