Wix Automations: Using Custom Code in an Automation
We recommend only using custom code in an automation if you have prior technical knowledge and experience working with coding.
Enhance your automation using your own code using the Run Velo Code action. With this automation action and the Velo APIs, you can customize your site or business in any way you like, for example, by updating your CMS, formatting data, or connecting to third-party applications. Write your code, test it, and then activate the automation.
Before you begin:
In order to use the Run Velo Code action, you must first enable coding on your site.
A service plugin can't be added when using Git Integration and Wix CLI.
In order for the code to run, you must have a published site. Be sure to have the proper permission to publish.
Creating an automation with the Run Velo Code action
Go to Automations in your site's dashboard.
Click + Create Automation in the top right corner.
Click + Start from Scratch.
Click the title to give your automation a name.
Select a trigger for your automation.
Click + to add a step.
Click Action.
Click Run Velo code on the left.
Click Start Coding.
Give a name to the JS file and click Create & Start Coding.
Write your code in the window that opens.
Notes: Lines 2 - 6 in the default code support the autocompletion system. Make sure you keep them in your code file. Additionally, use the "Invoke" function to implement your action logic.
Click Save for your code to integrate your custom logic in this automation.
(Optional) Before activating your automation, run your code to test it and make sure it gives the results you expect. Before you start your test:
Define the sample data that will run in the test.
Open the site logs to monitor the result.
When ready, click Activate at the top right.
Important:
Running your code to test means it's running live, so it might make changes within your site and/or dashboard.

FAQs
Can I use data from the trigger in my custom action?
Yes, you can use the data from the trigger or other parts of the automation by using it in the code:

Where can I find the specifications for the payload?
You can view the payload specification by clicking the Payload View tab in the pop-up screen when writing Velo code.

Can I edit the Run Velo Code action in any code environment?
Yes, you can edit the code in 3 different environments:
In the action configuration itself of the automation builder (recommended).
In the backend service plugin file in the site code editor.
In the Wix IDE (for Wix Studio only).
Learn more about custom extensions.
Why do I get an error when creating a .js file with Run Velo Code on a GitHub-connected site?
Creating a new .js file is not supported for Git-managed code. The file won't be added to your GitHub repository and you'll most likely see the error 'We could not load Velo code'.

Even though a backend file may appear in your editor, it's best to manage all your code via GitHub. We recommend that:
You create backend files and functions directly in your GitHub repository (or in the Velo editor in a way that it's synced with GitHub), not via automations on your site.
In the Run Velo Code action, you select an existing backend function instead of creating a new file from the automations interface.
What should I be aware of when connecting to a third-party provider using SPIs?
If you connect to a third-party provider using SPIs, you agree to the Wix.com Terms of Use. Wix is not responsible for your use of such a third-party provider, and any liability resulting from such use will be your responsibility.
Where can I find help implementing an SPI?
If you need help implementing SPI, there are professionals who can help you.