Add a service plugin (formerly SPI) extension to your app in your app's dashboard to extend the functionality of a Wix site.
With service plugins, your app can:
If you prefer to host your app on Wix, you can add a service plugin extension with the CLI.
Follow these steps to implement a self-hosted service plugin with the Wix JavaScript SDK:
Add a service plugin extension to your app in your app's dashboard as follows:
Select an app from the Custom Apps page in your Wix Studio workspace.
Go to the Extensions page, and click + Create Extension.
Filter by tag, or search to find the extension you want to add.
Select the relevant extension and click + Create.
In the JSON editor, configure the parameters by referencing the Documentation section on the right side of the page. For each parameter, add the parameter name and value in the JSON editor.
Click Save.
To implement a self-hosted service plugin, you'll need to retrieve these credentials from your app's dashboard:
In your app code, import the Wix client and service plugin modules you need, then call createClient()
with the AppStrategy
auth strategy to create a client for making authenticated calls to Wix APIs:
Make sure you:
modules
when creating the client.Now it's time to add your custom business logic. Do this by calling provideHandlers()
and passing it an object containing handler functions for each service plugin functionality you need:
For example, to implement the Shipping Rates service plugin, define the getShippingRates()
handler function as follows:
When a site action triggers one of these functions, Wix passes the function a payload
object containing the following properties:
request
: Details related to the specific service and action.metadata
: Information about the context of the request, such as the App Instance ID, site currency, language, and identity of the user who triggered the request.To find the handler functions a service plugin supports, and the precise structure of the request
and metadata
objects for each handler function, see the reference documentation.
Define a route to handle POST
requests from Wix. Use the /*
wildcard to enable the endpoint to catch all requests to all sub-paths. In your route handler, call process()
and pass it the request. This function takes care of the following for you:
provideHandlers()
and passes it the request payload.For example, if you are using Express, you can implement the endpoint simply as follows, regardless of which handler functions you defined:
Here's an example of implementing this code for a shipping rates service plugin: